Skip to contentSkip to conversation

asus-laptop: remove redundant initializers

PATCH In review Giedrius Statkevičius 3 participants 8 messages Apr 16, 2016 – Apr 25, 2016

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

PATCH v2 1/2 asus-laptop: remove redundant initializers

Initializing rv to AE_OK is pointless because later function results are assigned to them and only then the variable is used

---
 drivers/platform/x86/asus-laptop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +3 -3
index f2b5d0a..d86d42e 100644
@@ -771,7 +771,7 @@ static int asus_read_brightness(struct backlight_device *bd)
 {
 	struct asus_laptop *asus = bl_get_data(bd);
 	unsigned long long value;
-	acpi_status rv = AE_OK;
+	acpi_status rv;
 
 	rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
 				   NULL, &value);
@@ -865,7 +865,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
 	int len = 0;
 	unsigned long long temp;
 	char buf[16];		/* enough for all info */
-	acpi_status rv = AE_OK;
+	acpi_status rv;
 
 	/*
 	 * We use the easy way, we don't care of off and count,
@@ -1265,7 +1265,7 @@ static DEVICE_ATTR_RO(ls_value);
 static int asus_gps_status(struct asus_laptop *asus)
 {
 	unsigned long long status;
-	acpi_status rv = AE_OK;
+	acpi_status rv;
 
 	rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
 				   NULL, &status);
Signature · 1 line
2.8.0
#1 lore raw

PATCH v2 2/2 asus-laptop: correct error handling in sysfs_acpi_set

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

---
 drivers/platform/x86/asus-laptop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +2 -3
index d86d42e..9a69734 100644
@@ -946,11 +946,10 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
 			      const char *method)
 {
 	int rv, value;
-	int out = 0;
 
 	rv = parse_arg(buf, count, &value);
-	if (rv > 0)
-		out = value ? 1 : 0;
+	if (rv <= 0)
+		return rv;
 
 	if (write_acpi_int(asus->handle, method, value))
 		return -ENODEV;
Signature · 1 line
2.8.0
#2 lore raw

Re: [PATCH v2 2/2] asus-laptop: correct error handling in sysfs_acpi_set

Quoted 2 lines · Giedrius Statkevičius

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

The initial problem if I recall was value being uninitialized. Is that correct?

Quoted 28 lines
---
 drivers/platform/x86/asus-laptop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +2 -3
index d86d42e..9a69734 100644
@@ -946,11 +946,10 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
 			      const char *method)
 {
 	int rv, value;
-	int out = 0;
 
 	rv = parse_arg(buf, count, &value);
-	if (rv > 0)
-		out = value ? 1 : 0;
+	if (rv <= 0)
+		return rv;
 
 	if (write_acpi_int(asus->handle, method, value))
 		return -ENODEV;
Signature · 1 line
2.8.0
Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#3 lore raw

Re: [PATCH v2 2/2] asus-laptop: correct error handling in sysfs_acpi_set

Quoted 5 lines · Darren Hart
Quoted 2 lines · Giedrius Statkevičius

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

The initial problem if I recall was value being uninitialized. Is that correct?

No, 'out' was just removed as it was unused. Then you caught the issue with error handling in this function so I've updated this patch to fix that as well.

#4 lore raw

Re: [PATCH v2 2/2] asus-laptop: correct error handling in sysfs_acpi_set

In reply to Giedrius Statkevičius
Quoted 13 lines · Giedrius Statkevičius

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

---
 drivers/platform/x86/asus-laptop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +0 -0
index d86d42e..9a69734 100644

drivers/platform/x86/asus-laptop.c static ssize_t sysfs_acpi_set(struct asus_laptop *asus, · line 950

Quoted 6 lines
drivers/platform/x86/asus-laptop.c +0 -1
@@ -946,11 +946,10 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
                              const char *method)
 {
        int rv, value;
-       int out = 0;
 
        rv = parse_arg(buf, count, &value);

Just noticed (might be a separate patch for this) that parse_arg pretty much duplicated kstrotint().

Quoted 10 lines
drivers/platform/x86/asus-laptop.c +2 -3
-       if (rv > 0)
-               out = value ? 1 : 0;
+       if (rv <= 0)
+               return rv;
 
        if (write_acpi_int(asus->handle, method, value))
                return -ENODEV;
--

2.8.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH v2 2/2] asus-laptop: correct error handling in sysfs_acpi_set

Quoted 20 lines · Andy Shevchenko
Quoted 18 lines · Giedrius Statkevičius

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

---
 drivers/platform/x86/asus-laptop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +0 -1
index d86d42e..9a69734 100644
@@ -946,11 +946,10 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
                              const char *method)
 {
        int rv, value;
-       int out = 0;
 
Quoted 4 lines

drivers/platform/x86/asus-laptop.c static ssize_t sysfs_acpi_set(struct asus_laptop *asus, · line 950

Quoted 1 line
drivers/platform/x86/asus-laptop.c +0 -0
        rv = parse_arg(buf, count, &value);

Just noticed (might be a separate patch for this) that parse_arg pretty much duplicated kstrotint().

Ah, thanks Andy.

I'd like to take this one as is, but a cleanup for that would be welcome indeed.

Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
#6 lore raw

Re: [PATCH v2 2/2] asus-laptop: correct error handling in sysfs_acpi_set

In reply to Giedrius Statkevičius
Quoted 4 lines · Giedrius Statkevičius

Properly return rv back to the caller in the case of an error in parse_arg. In the process remove a unused variable 'out'.

1 and 2 queued for 4.7.

Quoted 26 lines
---
 drivers/platform/x86/asus-laptop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +2 -3
index d86d42e..9a69734 100644
@@ -946,11 +946,10 @@ static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
 			      const char *method)
 {
 	int rv, value;
-	int out = 0;
 
 	rv = parse_arg(buf, count, &value);
-	if (rv > 0)
-		out = value ? 1 : 0;
+	if (rv <= 0)
+		return rv;
 
 	if (write_acpi_int(asus->handle, method, value))
 		return -ENODEV;
Signature · 1 line
2.8.0
Signature · 2 lines
Darren Hart
Intel Open Source Technology Center
Acked-by on v2 1/2
#7 lore raw
In reply to Giedrius Statkevičius
Quoted 4 lines · Giedrius Statkevičius

Initializing rv to AE_OK is pointless because later function results are assigned to them and only then the variable is used

Fine to me:

Quoted 38 lines
---
 drivers/platform/x86/asus-laptop.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-laptop.c +3 -4
index f2b5d0a..d86d42e 100644
@@ -771,7 +771,7 @@ static int asus_read_brightness(struct backlight_device *bd)
 {
        struct asus_laptop *asus = bl_get_data(bd);
        unsigned long long value;
-       acpi_status rv = AE_OK;
+       acpi_status rv;
 
        rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
                                   NULL, &value);
@@ -865,7 +865,7 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr,
        int len = 0;
        unsigned long long temp;
        char buf[16];           /* enough for all info */
-       acpi_status rv = AE_OK;
+       acpi_status rv;
 
        /*
         * We use the easy way, we don't care of off and count,
@@ -1265,7 +1265,7 @@ static DEVICE_ATTR_RO(ls_value);
 static int asus_gps_status(struct asus_laptop *asus)
 {
        unsigned long long status;
-       acpi_status rv = AE_OK;
+       acpi_status rv;
 
        rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
                                   NULL, &status);
--

2.8.0

Signature · 2 lines
With Best Regards,
Andy Shevchenko