diff mbox series

[v1,2/3] i2c: i801: Use match_string() helper to simplify the code

Message ID 20190613164529.63482-2-andriy.shevchenko@linux.intel.com
State Superseded
Headers show
Series [v1,1/3] i2c: i801: Fix kernel crash in is_dell_system_with_lis3lv02d() | expand

Commit Message

Andy Shevchenko June 13, 2019, 4:45 p.m. UTC
match_string() returns the array index of a matching string.
Use it instead of the open-coded implementation.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/i2c/busses/i2c-i801.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Jean Delvare June 17, 2019, 2:16 p.m. UTC | #1
Hi Andy,

On Thu, 13 Jun 2019 19:45:28 +0300, Andy Shevchenko wrote:
> match_string() returns the array index of a matching string.
> Use it instead of the open-coded implementation.

Nice, I didn't know about this utility function.

Don't we need to include <linux/string.h> though? Or is it another
undocumented exception?
Andy Shevchenko June 17, 2019, 4:08 p.m. UTC | #2
On Mon, Jun 17, 2019 at 04:16:44PM +0200, Jean Delvare wrote:
> On Thu, 13 Jun 2019 19:45:28 +0300, Andy Shevchenko wrote:
> > match_string() returns the array index of a matching string.
> > Use it instead of the open-coded implementation.
> 
> Nice, I didn't know about this utility function.
> 
> Don't we need to include <linux/string.h> though? Or is it another
> undocumented exception?

Here it is a nice catch! I will update.
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 694eb636b40b..03100f5fc0e9 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1164,14 +1164,12 @@  static acpi_status check_acpi_smo88xx_device(acpi_handle obj_handle,
 	if (!hid)
 		return AE_OK;
 
-	for (i = 0; i < ARRAY_SIZE(acpi_smo8800_ids); ++i) {
-		if (strcmp(hid, acpi_smo8800_ids[i]) == 0) {
-			*((bool *)return_value) = true;
-			return AE_CTRL_TERMINATE;
-		}
-	}
+	i = match_string(acpi_smo8800_ids, ARRAY_SIZE(acpi_smo8800_ids), hid);
+	if (i < 0)
+		return AE_OK;
 
-	return AE_OK;
+	*((bool *)return_value) = true;
+	return AE_CTRL_TERMINATE;
 }
 
 static bool is_dell_system_with_lis3lv02d(void)