s390/raw3270: improve raw3270_init() readability
authorRicardo B. Marliere <ricardo@marliere.net>
Tue, 5 Mar 2024 11:25:23 +0000 (08:25 -0300)
committerHeiko Carstens <hca@linux.ibm.com>
Wed, 13 Mar 2024 08:23:49 +0000 (09:23 +0100)
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>
drivers/s390/char/raw3270.c

index 7a5bda26edbd6c7914f0052c679690d14860dbfb..899e86e5a68916cffa556a357ad78a7d0aaba071 100644 (file)
@@ -1316,17 +1316,19 @@ static int raw3270_init(void)
                return 0;
        raw3270_registered = 1;
        rc = ccw_driver_register(&raw3270_ccw_driver);
-       if (rc == 0) {
-               /* Create attributes for early (= console) device. */
-               mutex_lock(&raw3270_mutex);
-               class3270 = class_create("3270");
-               list_for_each_entry(rp, &raw3270_devices, list) {
-                       get_device(&rp->cdev->dev);
-                       raw3270_create_attributes(rp);
-               }
-               mutex_unlock(&raw3270_mutex);
+       if (rc)
+               return rc;
+       class3270 = class_create("3270");
+       if (IS_ERR(class3270))
+               return PTR_ERR(class3270);
+       /* Create attributes for early (= console) device. */
+       mutex_lock(&raw3270_mutex);
+       list_for_each_entry(rp, &raw3270_devices, list) {
+               get_device(&rp->cdev->dev);
+               raw3270_create_attributes(rp);
        }
-       return rc;
+       mutex_unlock(&raw3270_mutex);
+       return 0;
 }
 
 static void raw3270_exit(void)