Skip to content

Commit c8fba0c

Browse files
rbmarlierehcahca
authored andcommitted
s390/raw3270: improve raw3270_init() readability
Instead of checking if rc is 0, check whether it is non-zero and return early if so. The call to class_create() can fail, so add a check to it and move it out of the mutex region. Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: "Ricardo B. Marliere" <ricardo@marliere.net> Link: https://lore.kernel.org/r/20240305-class_cleanup-s390-v1-5-c4ff1ec49ffd@marliere.net Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent 5207765 commit c8fba0c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/s390/char/raw3270.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,17 +1316,19 @@ static int raw3270_init(void)
13161316
return 0;
13171317
raw3270_registered = 1;
13181318
rc = ccw_driver_register(&raw3270_ccw_driver);
1319-
if (rc == 0) {
1320-
/* Create attributes for early (= console) device. */
1321-
mutex_lock(&raw3270_mutex);
1322-
class3270 = class_create("3270");
1323-
list_for_each_entry(rp, &raw3270_devices, list) {
1324-
get_device(&rp->cdev->dev);
1325-
raw3270_create_attributes(rp);
1326-
}
1327-
mutex_unlock(&raw3270_mutex);
1319+
if (rc)
1320+
return rc;
1321+
class3270 = class_create("3270");
1322+
if (IS_ERR(class3270))
1323+
return PTR_ERR(class3270);
1324+
/* Create attributes for early (= console) device. */
1325+
mutex_lock(&raw3270_mutex);
1326+
list_for_each_entry(rp, &raw3270_devices, list) {
1327+
get_device(&rp->cdev->dev);
1328+
raw3270_create_attributes(rp);
13281329
}
1329-
return rc;
1330+
mutex_unlock(&raw3270_mutex);
1331+
return 0;
13301332
}
13311333

13321334
static void raw3270_exit(void)

0 commit comments

Comments
 (0)