Skip to contentSkip to conversation

ALSA: core: remove initialise static variables to 0

PATCH Superseded Meng Tang 2 participants 4 messages Feb 28, 2022 Sound

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Meng Tang

author
#0 lore raw

PATCH v2 1/2 ALSA: core: remove initialise static variables to 0

Initializing the static variable to 0 causes the following error when exec checkpatch:

ERROR: do not initialise statics to 0
FILE: sound/sound_core.c:142:
static int preclaim_oss = 0;

In addition, considering the following way of writing
139: #ifdef config_sound_oss_core_preclaim
140: Static int preclaim_oss = 1;
141: #ELSE
142: Static int preclaim_oss = 0;
143: #ENDIF
We can optimize it by IS_ENABLED(CONFIG_SOUND_OSS_CORE_PRECLAIM), so modified it to
static int preclaim_oss = IS_ENABLED(CONFIG_SOUND_OSS_CORE_PRECLAIM);

---
 sound/sound_core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
sound/sound_core.c +1 -5
index 90d118cd9164..aa4a57e488e5 100644
@@ -136,11 +136,7 @@ struct sound_unit
  * All these clutters are scheduled to be removed along with
  * sound-slot/service-* module aliases.
  */
-#ifdef CONFIG_SOUND_OSS_CORE_PRECLAIM
-static int preclaim_oss = 1;
-#else
-static int preclaim_oss = 0;
-#endif
+static int preclaim_oss = IS_ENABLED(CONFIG_SOUND_OSS_CORE_PRECLAIM);
 
 module_param(preclaim_oss, int, 0444);
 
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 2/2 ALSA: core: Remove redundant 'err' variable

Return the result from file->f_op->open() directly instead of taking this in another redundant variable.

---
 sound/sound_core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
sound/sound_core.c +2 -3
index aa4a57e488e5..3ac679ea31c7 100644
@@ -582,13 +582,12 @@ static int soundcore_open(struct inode *inode, struct file *file)
 		 * We rely upon the fact that we can't be unloaded while the
 		 * subdriver is there.
 		 */
-		int err = 0;
 		replace_fops(file, new_fops);
 
 		if (file->f_op->open)
-			err = file->f_op->open(inode,file);
+			return file->f_op->open(inode, file);
 
-		return err;
+		return 0;
 	}
 	return -ENODEV;
 }
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH v2 2/2] ALSA: core: Remove redundant 'err' variable

Quoted 2 lines · Meng Tang

Return the result from file->f_op->open() directly instead of taking this in another redundant variable.

[]

sound/sound_core.c

Quoted 1 line
sound/sound_core.c +0 -0

[]

Quoted 6 lines
sound/sound_core.c +0 -1
@@ -582,13 +582,12 @@ static int soundcore_open(struct inode *inode, struct file *file)
 		 * We rely upon the fact that we can't be unloaded while the
 		 * subdriver is there.
 		 */
-		int err = 0;
 		replace_fops(file, new_fops);

sound/sound_core.c static int soundcore_open(struct inode *inode, struct file *file) · line 593

Quoted 10 lines
sound/sound_core.c +2 -2
 
 		if (file->f_op->open)
-			err = file->f_op->open(inode,file);
+			return file->f_op->open(inode, file);
 
-		return err;
+		return 0;
 	}
 	return -ENODEV;
 }

Perhaps clearer would be to make the typical return the last statement, return early and reduce the indentation too.

i.e.:

---
 sound/sound_core.c | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
sound/sound_core.c +11 -13
index 90d118cd91641..9f2cd6d91a034 100644
@@ -581,22 +581,20 @@ static int soundcore_open(struct inode *inode, struct file *file)
 			new_fops = fops_get(s->unit_fops);
 	}
 	spin_unlock(&sound_loader_lock);
-	if (new_fops) {
-		/*
-		 * We rely upon the fact that we can't be unloaded while the
-		 * subdriver is there.
-		 */
-		int err = 0;
-		replace_fops(file, new_fops);
+	if (!new_fops)
+		return -ENODEV;
 
-		if (file->f_op->open)
-			err = file->f_op->open(inode,file);
+	/*
+	 * We rely upon the fact that we can't be unloaded while the
+	 * subdriver is there.
+	 */
+	replace_fops(file, new_fops);
 
-		return err;
-	}
-	return -ENODEV;
-}
+	if (!file->f_op->open)
+		return -ENODEV;
 
+	return file->f_op->open(inode,file);
+}
 MODULE_ALIAS_CHARDEV_MAJOR(SOUND_MAJOR);
 
 static void cleanup_oss_soundcore(void)
author
#3 lore raw

Re: [PATCH v2 2/2] ALSA: core: Remove redundant 'err' variable

Quoted 41 lines · Joe Perches

Perhaps clearer would be to make the typical return the last statement, return early and reduce the indentation too.

i.e.:

---
  sound/sound_core.c | 24 +++++++++++-------------
  1 file changed, 11 insertions(+), 13 deletions(-)
sound/sound_core.c +7 -11
index 90d118cd91641..9f2cd6d91a034 100644
@@ -581,22 +581,20 @@ static int soundcore_open(struct inode *inode, struct file *file)
  			new_fops = fops_get(s->unit_fops);
  	}
  	spin_unlock(&sound_loader_lock);
-	if (new_fops) {
-		/*
-		 * We rely upon the fact that we can't be unloaded while the
-		 * subdriver is there.
-		 */
-		int err = 0;
-		replace_fops(file, new_fops);
+	if (!new_fops)
+		return -ENODEV;
 
-		if (file->f_op->open)
-			err = file->f_op->open(inode,file);
+	/*
+	 * We rely upon the fact that we can't be unloaded while the
+	 * subdriver is there.
+	 */
+	replace_fops(file, new_fops);
 
-		return err;
-	}

sound/sound_core.c static int soundcore_open(struct inode *inode, struct file *file) · line 600

Quoted 10 lines
sound/sound_core.c +4 -2
-	return -ENODEV;
-}
+	if (!file->f_op->open)
+		return -ENODEV;
 
+	return file->f_op->open(inode,file);
+}
  MODULE_ALIAS_CHARDEV_MAJOR(SOUND_MAJOR);
 
  static void cleanup_oss_soundcore(void)

Thanks, I re-submit it according to your suggestions, and add you to the Signed-off-by list.