Skip to contentSkip to conversation

platform/x86: thinkpad_acpi: Remove unreachable code in beep_read()

PATCH In review Thorsten Blum 3 participants 5 messages Sep 7 – Oct 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: thinkpad_acpi: Remove unreachable code in beep_read()

The procfs entry /proc/acpi/ibm/beep is only created if beep_init() succeeds, which requires beep_handle to be non-NULL. Remove the unreachable code branch from beep_read().

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -6
index 1082c36ae723..069c9f1c359f 100644
@@ -5936,12 +5936,8 @@ static int __init beep_init(struct ibm_init_struct *iibm)
 
 static int beep_read(struct seq_file *m)
 {
-	if (!beep_handle)
-		seq_puts(m, "status:\t\tnot supported\n");
-	else {
-		seq_puts(m, "status:\t\tsupported\n");
-		seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
-	}
+	seq_puts(m, "status:\t\tsupported\n");
+	seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
 
 	return 0;
 }
maintainer
#1 lore raw

Hi Thorsten,

Quoted 29 lines · Thorsten Blum

The procfs entry /proc/acpi/ibm/beep is only created if beep_init() succeeds, which requires beep_handle to be non-NULL. Remove the unreachable code branch from beep_read().

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -6
index 1082c36ae723..069c9f1c359f 100644
@@ -5936,12 +5936,8 @@ static int __init beep_init(struct 
 ibm_init_struct *iibm)
 
 static int beep_read(struct seq_file *m)
 {
-	if (!beep_handle)
-		seq_puts(m, "status:\t\tnot supported\n");
-	else {
-		seq_puts(m, "status:\t\tsupported\n");
-		seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
-	}
+	seq_puts(m, "status:\t\tsupported\n");
+	seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
 
 	return 0;
Quoted 1 line

}

Change looks good to me.
I guess the beep_write could be similarly updated?

Mark

#2 lore raw
Quoted 31 lines · Mark Pearson

Hi Thorsten,

Quoted 28 lines · Thorsten Blum

The procfs entry /proc/acpi/ibm/beep is only created if beep_init() succeeds, which requires beep_handle to be non-NULL. Remove the unreachable code branch from beep_read().

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -6
index 1082c36ae723..069c9f1c359f 100644
@@ -5936,12 +5936,8 @@ static int __init beep_init(struct 
 ibm_init_struct *iibm)
 
 static int beep_read(struct seq_file *m)
 {
-	if (!beep_handle)
-		seq_puts(m, "status:\t\tnot supported\n");
-	else {
-		seq_puts(m, "status:\t\tsupported\n");
-		seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
-	}
+	seq_puts(m, "status:\t\tsupported\n");
+	seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
 
Quoted 5 lines
Quoted 2 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +0 -0
 	return 0;

}

Change looks good to me.
I guess the beep_write could be similarly updated?

No, beep_write() can be called via the beep= module parameter even if beep_init() failed, so that check is still needed.

Thanks,
Thorsten

maintainer Reviewed-by
#3 lore raw
Quoted 32 lines · Thorsten Blum
Quoted 31 lines · Mark Pearson

Hi Thorsten,

Quoted 28 lines · Thorsten Blum

The procfs entry /proc/acpi/ibm/beep is only created if beep_init() succeeds, which requires beep_handle to be non-NULL. Remove the unreachable code branch from beep_read().

---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/platform/x86/lenovo/thinkpad_acpi.c +2 -6
index 1082c36ae723..069c9f1c359f 100644
@@ -5936,12 +5936,8 @@ static int __init beep_init(struct 
 ibm_init_struct *iibm)
 
 static int beep_read(struct seq_file *m)
 {
-	if (!beep_handle)
-		seq_puts(m, "status:\t\tnot supported\n");
-	else {
-		seq_puts(m, "status:\t\tsupported\n");
-		seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
-	}
+	seq_puts(m, "status:\t\tsupported\n");
+	seq_puts(m, "commands:\t<cmd> (<cmd> is 0-17)\n");
 
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
drivers/platform/x86/lenovo/thinkpad_acpi.c +0 -0
 	return 0;

}

Change looks good to me.
I guess the beep_write could be similarly updated?

No, beep_write() can be called via the beep= module parameter even if beep_init() failed, so that check is still needed.

Oh - good point, I had missed that.
With that noted:

Thanks
Mark

maintainer
#4 lore raw
In reply to Thorsten Blum
Quoted 3 lines · Thorsten Blum

The procfs entry /proc/acpi/ibm/beep is only created if beep_init() succeeds, which requires beep_handle to be non-NULL. Remove the unreachable code branch from beep_read().

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.

The list of commits applied:
[1/1] platform/x86: thinkpad_acpi: Remove unreachable code in beep_read()

      commit: c48091a8ac16b0fd1e7ffed29f11c4e6ea1acbb4

--
i.