Skip to contentSkip to conversation

use match_string() helper

PATCH Applied Yisheng Xie 13 participants 72 messages May 31, 2018 – Jul 4, 2018

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

v2 cover use match_string() helper

Andy introduce helper function match_string() which can be used to return the index of array for a matching string. so we can use it in many places instead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes too much big patchset.

v2:
- Remove the Patches which Andy already sent out, or maintainer already picked up.
- Add Reviewed-by or Acked-by tags for some patchs.
- Add some new patches[19-21].

Yisheng Xie (21):
usb: phy: use match_string() helper
mfd: omap-usb-host: use match_string() helper
Staging: gdm724x: use match_string() helper
cxgb4: use match_string() helper
hp100: use match_string() helper
iwlwifi: mvm: use match_string() helper
bus: fsl-mc: use match_string() helper
clk: bcm2835: use match_string() helper
clk: use match_string() helper
cpufreq: intel_pstate: use match_string() helper drm/nouveau: use match_string() helper
drm: i2c: ch7006: use match_string() helper
ima: use match_string() helper sched/debug: use match_string() helper
ALSA: oxygen: use match_string() helper
ASoC: max98088: use match_string() helper
ASoC: max98095: use match_string() helper
ASoC: dapm: use match_string() helper
bcache: use match_string() helper powerpc/xmon: use match_string() helper
sparc64: use match_string() helper

 arch/powerpc/xmon/xmon.c                         | 23 +++++++++---------
 arch/sparc/kernel/setup_64.c                     |  7 +++---
 drivers/bus/fsl-mc/fsl-mc-allocator.c            | 24 ++++--------------
 drivers/clk/bcm/clk-bcm2835.c                    | 13 +++++-----
 drivers/clk/clk.c                                |  8 ++----
 drivers/cpufreq/intel_pstate.c                   | 15 +++++-------
 drivers/gpu/drm/i2c/ch7006_drv.c                 | 13 ++++------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c        | 13 ++++------
 drivers/md/bcache/util.c                         |  9 ++-----
 drivers/mfd/omap-usb-host.c                      | 24 ++----------------
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++--------
 drivers/net/ethernet/hp/hp100.c                  |  9 +------
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++-------
 drivers/staging/gdm724x/gdm_tty.c                | 18 ++++----------
 drivers/usb/phy/of.c                             | 10 ++++----
 kernel/sched/debug.c                             | 31 ++++++++++++------------
 security/integrity/ima/ima_main.c                | 11 +++------
 sound/pci/oxygen/oxygen_mixer.c                  | 14 +++++------
 sound/soc/codecs/max98088.c                      | 13 ++++------
 sound/soc/codecs/max98095.c                      | 13 ++++------
 sound/soc/soc-dapm.c                             | 18 ++++++--------
 21 files changed, 109 insertions(+), 204 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v2 1/21 usb: phy: use match_string() helper

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
v2:
- donot rename err to ret - per Andy

 drivers/usb/phy/of.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/phy/of.c +5 -5
index 1ab134f..9d74081 100644
@@ -28,16 +28,16 @@
 enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
 {
 	const char *phy_type;
-	int err, i;
+	int err;
 
 	err = of_property_read_string(np, "phy_type", &phy_type);
 	if (err < 0)
 		return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-	for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
-		if (!strcmp(phy_type, usbphy_modes[i]))
-			return i;
+	err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+	if (err < 0)
+		return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-	return USBPHY_INTERFACE_MODE_UNKNOWN;
+	return err;
 }
 EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);
#2 lore raw

Re: [PATCH v2 01/21] usb: phy: use match_string() helper

Hello!

Quoted 10 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Felipe Balbi <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

---
v2:
- donot rename err to ret - per Andy

Hm...

Quoted 14 lines
 drivers/usb/phy/of.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/usb/phy/of.c +1 -1
index 1ab134f..9d74081 100644
@@ -28,16 +28,16 @@
 enum usb_phy_interface of_usb_get_phy_mode(struct device_node *np)
 {
 	const char *phy_type;
-	int err, i;
+	int err;

drivers/usb/phy/of.c line 38

Quoted 10 lines
drivers/usb/phy/of.c +2 -3
 
 	err = of_property_read_string(np, "phy_type", &phy_type);
 	if (err < 0)
 		return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-	for (i = 0; i < ARRAY_SIZE(usbphy_modes); i++)
-		if (!strcmp(phy_type, usbphy_modes[i]))
-			return i;
+	err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+	if (err < 0)

This is one of the few cases when 'err' is not the best name for such a
variable. I'd prefer to see something like 'match' or even 'rc' or 'ret'... :-)

drivers/usb/phy/of.c line 43

Quoted 7 lines
drivers/usb/phy/of.c +2 -1
+		return USBPHY_INTERFACE_MODE_UNKNOWN;
 
-	return USBPHY_INTERFACE_MODE_UNKNOWN;
+	return err;
 }
 EXPORT_SYMBOL_GPL(of_usb_get_phy_mode);

MBR, Sergei
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Re: [PATCH v2 01/21] usb: phy: use match_string() helper

Quoted 11 lines · Sergei Shtylyov
Quoted 1 line

- donot rename err to ret - per Andy

   Hm...

drivers/usb/phy/of.c line 38

Quoted 4 lines
drivers/usb/phy/of.c +2 -1
-     int err, i;
 
+     err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+     if (err < 0)

This is one of the few cases when 'err' is not the best name for such a
variable. I'd prefer to see something like 'match' or even 'rc' or 'ret'... :-)

Then leaving i would make it?
I'm okay with either which just not renames err, b/c it's used with something else in this function.

#4 lore raw

Re: [PATCH v2 01/21] usb: phy: use match_string() helper

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines
Quoted 1 line

- donot rename err to ret - per Andy

   Hm...
Quoted 1 line

- int err, i;

Quoted 7 lines
Quoted 5 lines

drivers/usb/phy/of.c line 38

Quoted 2 lines
drivers/usb/phy/of.c +2 -0
+     err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+     if (err < 0)

This is one of the few cases when 'err' is not the best name for such a
variable. I'd prefer to see something like 'match' or even 'rc' or 'ret'... :-)

Then leaving i would make it?

Yes. :-)

Quoted 2 lines

I'm okay with either which just not renames err, b/c it's used with something else in this function.

Looking at it again, 'err' seems equally bad for the result of
of_property_read_string()... unless the check there is changed to just *if* (err) -- this function never returns positive values, 0 means success, others mean error.

MBR, Sergei
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

Re: [PATCH v2 01/21] usb: phy: use match_string() helper

Quoted 4 lines · Sergei Shtylyov
Quoted 1 line · Andy Shevchenko
Quoted 1 line
Quoted 1 line

- int err, i;

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

drivers/usb/phy/of.c line 38

Quoted 2 lines
drivers/usb/phy/of.c +2 -0
+     err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+     if (err < 0)

This is one of the few cases when 'err' is not the best name for such a
variable. I'd prefer to see something like 'match' or even 'rc' or 'ret'... :-)

Then leaving i would make it?

Yes. :-)

So, I leave it to Greg to decide either it's okay in this version, or needs update with i left untouched.

Quoted 6 lines
Quoted 2 lines

I'm okay with either which just not renames err, b/c it's used with something else in this function.

Looking at it again, 'err' seems equally bad for the result of
of_property_read_string()... unless the check there is changed to just *if* (err) -- this function never returns positive values, 0 means success, others mean error.

While you seems right, this is matter of another change which you are welcome to propose.

#6 lore raw

Re: [PATCH v2 01/21] usb: phy: use match_string() helper

Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Sergei Shtylyov
Quoted 5 lines · Andy Shevchenko
Quoted 5 lines
Quoted 4 lines
drivers/usb/phy/of.c +2 -1
-     int err, i;
 
+     err = match_string(usbphy_modes, ARRAY_SIZE(usbphy_modes), phy_type);
+     if (err < 0)
Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

This is one of the few cases when 'err' is not the best name for such a
variable. I'd prefer to see something like 'match' or even 'rc' or 'ret'... :-)

Then leaving i would make it?

Yes. :-)

So, I leave it to Greg to decide either it's okay in this version, or needs update with i left untouched.

Hi Greg,

IIRC, you seems want to keep the err unchanged, right?

Please let me know if another version is need.

Thanks
Yisheng

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

I'm okay with either which just not renames err, b/c it's used with something else in this function.

Looking at it again, 'err' seems equally bad for the result of
of_property_read_string()... unless the check there is changed to just *if* (err) -- this function never returns positive values, 0 means success, others mean error.

While you seems right, this is matter of another change which you are welcome to propose.

---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw

PATCH v2 2/21 mfd: omap-usb-host: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- add Acked-by and Reviewed-by tag.

 drivers/mfd/omap-usb-host.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/mfd/omap-usb-host.c +2 -22
index 7aab376..e11ab12 100644
@@ -153,27 +153,6 @@ static inline u32 usbhs_read(void __iomem *base, u32 reg)
 	[OMAP_OHCI_PORT_MODE_TLL_2PIN_DPDM]	= "ohci-tll-2pin-dpdm",
 };
 
-/**
- * omap_usbhs_get_dt_port_mode - Get the 'enum usbhs_omap_port_mode'
- * from the port mode string.
- * @mode: The port mode string, usually obtained from device tree.
- *
- * The function returns the 'enum usbhs_omap_port_mode' that matches the
- * provided port mode string as per the port_modes table.
- * If no match is found it returns -ENODEV
- */
-static int omap_usbhs_get_dt_port_mode(const char *mode)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(port_modes); i++) {
-		if (!strcmp(mode, port_modes[i]))
-			return i;
-	}
-
-	return -ENODEV;
-}
-
 static struct platform_device *omap_usbhs_alloc_child(const char *name,
 			struct resource	*res, int num_resources, void *pdata,
 			size_t pdata_size, struct device *dev)
@@ -529,7 +508,8 @@ static int usbhs_omap_get_dt_pdata(struct device *dev,
 		if (ret < 0)
 			continue;
 
-		ret = omap_usbhs_get_dt_port_mode(mode);
+		/* get 'enum usbhs_omap_port_mode' from port mode string */
+		ret = match_string(port_modes, ARRAY_SIZE(port_modes), mode);
 		if (ret < 0) {
 			dev_warn(dev, "Invalid port%d-mode \"%s\" in device tree\n",
 					i, mode);
Signature · 1 line
1.7.12.4
#8 lore raw

Re: [PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

Quoted 9 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 6 lines

---
v2:
- add Acked-by and Reviewed-by tag.

 drivers/mfd/omap-usb-host.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

I already applied this with the tags

Signature · 4 lines
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
#9 lore raw

Re: [PATCH v2 02/21] mfd: omap-usb-host: use match_string() helper

Hi Lee,

Quoted 15 lines · Lee Jones
Quoted 13 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- add Acked-by and Reviewed-by tag.

Quoted 4 lines
Quoted 2 lines
 drivers/mfd/omap-usb-host.c | 24 ++----------------------
 1 file changed, 2 insertions(+), 22 deletions(-)

I already applied this with the tags

Thanks
Yisheng

Quoted 1 line
#10 lore raw

PATCH v2 3/21 Staging: gdm724x: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Greg Kroah-Hartman <[email protected]>
Cc Quytelda Kahja <[email protected]>

---
v2:
- const DRIVER_STRING instead - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +5 -13
index 3cdebb8..397ecaa 100644
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
 	struct gdm *gdm = NULL;
 	int ret;
-	int i;
-	int j;
-
-	j = GDM_TTY_MINOR;
-	for (i = 0; i < TTY_MAX_COUNT; i++) {
-		if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-			j = tty->index;
-			break;
-		}
-	}
 
-	if (j == GDM_TTY_MINOR)
+	ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+			   tty->driver->driver_name);
+	if (ret < 0 || tty->index == GDM_TTY_MINOR)
 		return -ENODEV;
 
 	mutex_lock(&gdm_table_lock);
-	gdm = gdm_table[i][j];
+	gdm = gdm_table[ret][tty->index];
 	if (!gdm) {
 		mutex_unlock(&gdm_table_lock);
 		return -ENODEV;
Signature · 1 line
1.7.12.4
#11 lore raw

Re: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper

Quoted 37 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Greg Kroah-Hartman <[email protected]>
Cc Quytelda Kahja <[email protected]>

---
v2:
- const DRIVER_STRING instead - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +1 -7
index 3cdebb8..397ecaa 100644
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
 	struct gdm *gdm = NULL;
 	int ret;
-	int i;
-	int j;
-
-	j = GDM_TTY_MINOR;
-	for (i = 0; i < TTY_MAX_COUNT; i++) {
-		if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {

drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty) · line 72

Quoted 10 lines
drivers/staging/gdm724x/gdm_tty.c +3 -5
-			j = tty->index;
-			break;
-		}
-	}
 
-	if (j == GDM_TTY_MINOR)
+	ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+			   tty->driver->driver_name);
+	if (ret < 0 || tty->index == GDM_TTY_MINOR)
 		return -ENODEV;

Very odd rewrite here. Why call this function if you think the initial parameters are not correct? Are you sure about your test for tty->index?

This should be cleaned up more please.

thanks,

greg k-h

#12 lore raw

Re: [PATCH v2 03/21] Staging: gdm724x: use match_string() helper

Hi Greg,

Quoted 43 lines · Greg Kroah-Hartman
Quoted 42 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Greg Kroah-Hartman <[email protected]>
Cc Quytelda Kahja <[email protected]>

---
v2:
- const DRIVER_STRING instead - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +1 -11
index 3cdebb8..397ecaa 100644
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
 	struct gdm *gdm = NULL;
 	int ret;
-	int i;
-	int j;
-
-	j = GDM_TTY_MINOR;
-	for (i = 0; i < TTY_MAX_COUNT; i++) {
-		if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-			j = tty->index;
-			break;
-		}
-	}
 
Quoted 9 lines

drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty) · line 72

Quoted 5 lines
drivers/staging/gdm724x/gdm_tty.c +3 -1
-	if (j == GDM_TTY_MINOR)
+	ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+			   tty->driver->driver_name);
+	if (ret < 0 || tty->index == GDM_TTY_MINOR)
 		return -ENODEV;

Very odd rewrite here. Why call this function if you think the initial parameters are not correct? Are you sure about your test for tty->index?

Hmm, actually, I thought it no need to test tty->index here, but I not so sure about that so I kept it, I will remove this check next version.

Quoted 2 lines

This should be cleaned up more please.

Sure!

Thanks
Yisheng

Quoted 7 lines

thanks,

greg k-h

.

#13 lore raw

PATCH v3 3/21 Staging: gdm724x: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Greg Kroah-Hartman <[email protected]>
Cc Quytelda Kahja <[email protected]>

---
v3:
- no need to check input tty's index - per Greg
v2:
- const DRIVER_STRING instead - per Andy

 drivers/staging/gdm724x/gdm_tty.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +5 -13
index 3cdebb8..29ac6b5 100644
@@ -43,7 +43,7 @@
 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
 static DEFINE_MUTEX(gdm_table_lock);
 
-static char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
+static const char *DRIVER_STRING[TTY_MAX_COUNT] = {"GCTATC", "GCTDM"};
 static char *DEVICE_STRING[TTY_MAX_COUNT] = {"GCT-ATC", "GCT-DM"};
 
 static void gdm_port_destruct(struct tty_port *port)
@@ -65,22 +65,14 @@ static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
 {
 	struct gdm *gdm = NULL;
 	int ret;
-	int i;
-	int j;
-
-	j = GDM_TTY_MINOR;
-	for (i = 0; i < TTY_MAX_COUNT; i++) {
-		if (!strcmp(tty->driver->driver_name, DRIVER_STRING[i])) {
-			j = tty->index;
-			break;
-		}
-	}
 
-	if (j == GDM_TTY_MINOR)
+	ret = match_string(DRIVER_STRING, TTY_MAX_COUNT,
+			   tty->driver->driver_name);
+	if (ret < 0)
 		return -ENODEV;
 
 	mutex_lock(&gdm_table_lock);
-	gdm = gdm_table[i][j];
+	gdm = gdm_table[ret][tty->index];
 	if (!gdm) {
 		mutex_unlock(&gdm_table_lock);
 		return -ENODEV;
Signature · 1 line
1.7.12.4
#14 lore raw

PATCH v2 4/21 cxgb4: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- no change from v1.

 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +4 -10
index 9da6f57..bd61610 100644
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
 	if (rc)
 		return rc;
 
-	for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
-		if (!strcmp(cudbg_region[i], region_name)) {
-			found = 1;
-			idx = i;
-			break;
-		}
-	}
-	if (!found)
-		return -EINVAL;
+	rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+	if (rc < 0)
+		return rc;
 
-	found = 0;
+	idx = rc;
 	for (i = 0; i < meminfo->mem_c; i++) {
 		if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
 			continue; /* Skip holes */
Signature · 1 line
1.7.12.4
Reviewed-by on v2 4/21
#15 lore raw

Re: [PATCH v2 04/21] cxgb4: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 39 lines

---
v2:
- no change from v1.

 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +4 -11
index 9da6f57..bd61610 100644
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
        if (rc)
                return rc;
 
-       for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
-               if (!strcmp(cudbg_region[i], region_name)) {
-                       found = 1;
-                       idx = i;
-                       break;
-               }
-       }
-       if (!found)
-               return -EINVAL;
+       rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+       if (rc < 0)
+               return rc;
 
-       found = 0;
+       idx = rc;
        for (i = 0; i < meminfo->mem_c; i++) {
                if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
                        continue; /* Skip holes */
--

1.7.12.4

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

PATCH v2 5/21 hp100: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- add Reviewed-by tag.

 drivers/net/ethernet/hp/hp100.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/hp/hp100.c +1 -8
index c8c7ad2..84501b3 100644
@@ -335,7 +335,6 @@ static const char *hp100_read_id(int ioaddr)
 static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
 {
 	const char *sig;
-	int i;
 
 	if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100"))
 		goto err;
@@ -351,13 +350,7 @@ static __init int hp100_isa_probe1(struct net_device *dev, int ioaddr)
 	if (sig == NULL)
 		goto err;
 
-	for (i = 0; i < ARRAY_SIZE(hp100_isa_tbl); i++) {
-		if (!strcmp(hp100_isa_tbl[i], sig))
-			break;
-
-	}
-
-	if (i < ARRAY_SIZE(hp100_isa_tbl))
+	if (match_string(hp100_isa_tbl, ARRAY_SIZE(hp100_isa_tbl), sig) >= 0)
 		return hp100_probe1(dev, ioaddr, HP100_BUS_ISA, NULL);
  err:
 	return -ENODEV;
Signature · 1 line
1.7.12.4
#17 lore raw

PATCH v2 6/21 iwlwifi: mvm: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Kalle Valo <[email protected]>
Cc Intel Linux Wireless <[email protected]>
Cc Johannes Berg <[email protected]>
Cc Emmanuel Grumbach <[email protected]>

---
v2:
- let ret get return value of match_string - per Andy

 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +4 -9
index 0e6401c..d7ac511 100644
@@ -671,16 +671,11 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
 	};
 	int ret, bt_force_ant_mode;
 
-	for (bt_force_ant_mode = 0;
-	     bt_force_ant_mode < ARRAY_SIZE(modes_str);
-	     bt_force_ant_mode++) {
-		if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-			break;
-	}
-
-	if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
-		return -EINVAL;
+	ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
+	if (ret < 0)
+		return ret;
 
+	bt_force_ant_mode = ret;
 	ret = 0;
 	mutex_lock(&mvm->mutex);
 	if (mvm->bt_force_ant_mode == bt_force_ant_mode)
Signature · 1 line
1.7.12.4
Reviewed-by on v2 6/21
#18 lore raw

Re: [PATCH v2 06/21] iwlwifi: mvm: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 42 lines
Cc Kalle Valo <[email protected]>
Cc Intel Linux Wireless <[email protected]>
Cc Johannes Berg <[email protected]>
Cc Emmanuel Grumbach <[email protected]>

---
v2:
- let ret get return value of match_string - per Andy

 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +4 -10
index 0e6401c..d7ac511 100644
@@ -671,16 +671,11 @@ static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
        };
        int ret, bt_force_ant_mode;
 
-       for (bt_force_ant_mode = 0;
-            bt_force_ant_mode < ARRAY_SIZE(modes_str);
-            bt_force_ant_mode++) {
-               if (!strcmp(buf, modes_str[bt_force_ant_mode]))
-                       break;
-       }
-
-       if (bt_force_ant_mode >= ARRAY_SIZE(modes_str))
-               return -EINVAL;
+       ret = match_string(modes_str, ARRAY_SIZE(modes_str), buf);
+       if (ret < 0)
+               return ret;
 
+       bt_force_ant_mode = ret;
        ret = 0;
        mutex_lock(&mvm->mutex);
        if (mvm->bt_force_ant_mode == bt_force_ant_mode)
--

1.7.12.4

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

PATCH v2 7/21 bus: fsl-mc: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- add Reviewed-by tag.

 drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)
drivers/bus/fsl-mc/fsl-mc-allocator.c +5 -19
index fb1442b..63c4735 100644
@@ -156,22 +156,6 @@ static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
 	[FSL_MC_POOL_IRQ] = "irq",
 };
 
-static int __must_check object_type_to_pool_type(const char *object_type,
-						 enum fsl_mc_pool_type
-								*pool_type)
-{
-	unsigned int i;
-
-	for (i = 0; i < ARRAY_SIZE(fsl_mc_pool_type_strings); i++) {
-		if (strcmp(object_type, fsl_mc_pool_type_strings[i]) == 0) {
-			*pool_type = i;
-			return 0;
-		}
-	}
-
-	return -EINVAL;
-}
-
 int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
 					  enum fsl_mc_pool_type pool_type,
 					  struct fsl_mc_resource **new_resource)
@@ -581,9 +565,11 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device *mc_dev)
 		return -EINVAL;
 
 	mc_bus = to_fsl_mc_bus(mc_bus_dev);
-	error = object_type_to_pool_type(mc_dev->obj_desc.type, &pool_type);
-	if (error < 0)
-		return error;
+	pool_type = match_string(fsl_mc_pool_type_strings,
+				 ARRAY_SIZE(fsl_mc_pool_type_strings),
+				 mc_dev->obj_desc.type);
+	if (pool_type < 0)
+		return pool_type;
 
 	error = fsl_mc_resource_pool_add_device(mc_bus, pool_type, mc_dev);
 	if (error < 0)
Signature · 1 line
1.7.12.4
#20 lore raw

PATCH v2 8/21 clk: bcm2835: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Michael Turquette <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Stefan Wahren <[email protected]>
Cc linux-clk at vger.kernel.org
Cc linux-rpi-kernel at lists.infradead.org
Cc linux-arm-kernel at lists.infradead.org

---
v2:
- donot change the type of i - per Andy

 drivers/clk/bcm/clk-bcm2835.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/clk/bcm/clk-bcm2835.c +6 -7
index fa0d5c8..5e18433 100644
@@ -1395,7 +1395,7 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
 	struct bcm2835_clock *clock;
 	struct clk_init_data init;
 	const char *parents[1 << CM_SRC_BITS];
-	size_t i, j;
+	size_t i;
 	int ret;
 
 	/*
@@ -1405,12 +1405,11 @@ static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman,
 	for (i = 0; i < data->num_mux_parents; i++) {
 		parents[i] = data->parents[i];
 
-		for (j = 0; j < ARRAY_SIZE(cprman_parent_names); j++) {
-			if (strcmp(parents[i], cprman_parent_names[j]) == 0) {
-				parents[i] = cprman->real_parent_names[j];
-				break;
-			}
-		}
+		ret = match_string(cprman_parent_names,
+				   ARRAY_SIZE(cprman_parent_names),
+				   parents[i]);
+		if (ret >= 0)
+			parents[i] = cprman->real_parent_names[ret];
 	}
 
 	memset(&init, 0, sizeof(init));
Signature · 1 line
1.7.12.4
maintainer Applied
#21 lore raw

Re: [PATCH v2 08/21] clk: bcm2835: use match_string() helper

Quoting Yisheng Xie (2018-05-31 04:11:13)

Quoted 12 lines

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Michael Turquette <[email protected]>
Cc Stephen Boyd <[email protected]>
Cc Eric Anholt <[email protected]>
Cc Stefan Wahren <[email protected]>
Cc linux-clk at vger.kernel.org
Cc linux-rpi-kernel at lists.infradead.org
Cc linux-arm-kernel at lists.infradead.org
Quoted 1 line

---

Applied to clk-next

#22 lore raw

PATCH v2 9/21 clk: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Michael Turquette <[email protected]>
Cc Stephen Boyd <[email protected]>

---
v2:
- leave second parameter on the first line - per Andy

 drivers/clk/clk.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/clk/clk.c +2 -6
index 7af555f..d01bdda 100644
@@ -2171,7 +2171,6 @@ void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent)
 bool clk_has_parent(struct clk *clk, struct clk *parent)
 {
 	struct clk_core *core, *parent_core;
-	unsigned int i;
 
 	/* NULL clocks should be nops, so return success if either is NULL. */
 	if (!clk || !parent)
@@ -2184,11 +2183,8 @@ bool clk_has_parent(struct clk *clk, struct clk *parent)
 	if (core->parent == parent_core)
 		return true;
 
-	for (i = 0; i < core->num_parents; i++)
-		if (strcmp(core->parent_names[i], parent_core->name) == 0)
-			return true;
-
-	return false;
+	return match_string(core->parent_names, core->num_parents,
+			    parent_core->name) >= 0;
 }
 EXPORT_SYMBOL_GPL(clk_has_parent);
 
Signature · 1 line
1.7.12.4
#24 lore raw

PATCH v2 10/21 cpufreq: intel_pstate: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Srinivas Pandruvada <[email protected]>
Cc Len Brown <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Viresh Kumar <[email protected]>

---
v2:
- add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/cpufreq/intel_pstate.c +6 -9
index 17e566af..d701e26 100644
@@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference(
 {
 	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
 	char str_preference[21];
-	int ret, i = 0;
+	int ret;
 
 	ret = sscanf(buf, "%20s", str_preference);
 	if (ret != 1)
 		return -EINVAL;
 
-	while (energy_perf_strings[i] != NULL) {
-		if (!strcmp(str_preference, energy_perf_strings[i])) {
-			intel_pstate_set_energy_pref_index(cpu_data, i);
-			return count;
-		}
-		++i;
-	}
+	ret = match_string(energy_perf_strings, -1, str_preference);
+	if (ret < 0)
+		return ret;
 
-	return -EINVAL;
+	intel_pstate_set_energy_pref_index(cpu_data, ret);
+	return count;
 }
 
 static ssize_t show_energy_performance_preference(
Signature · 1 line
1.7.12.4
#25 lore raw

Re: [PATCH v2 10/21] cpufreq: intel_pstate: use match_string() helper

Quoted 40 lines · CEST Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Srinivas Pandruvada <[email protected]>
Cc Len Brown <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Viresh Kumar <[email protected]>

---
v2:
- add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/cpufreq/intel_pstate.c +1 -8
index 17e566af..d701e26 100644
@@ -645,21 +645,18 @@ static ssize_t store_energy_performance_preference(
 {
 	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
 	char str_preference[21];
-	int ret, i = 0;
+	int ret;
 
 	ret = sscanf(buf, "%20s", str_preference);
 	if (ret != 1)
 		return -EINVAL;
 
-	while (energy_perf_strings[i] != NULL) {
-		if (!strcmp(str_preference, energy_perf_strings[i])) {
-			intel_pstate_set_energy_pref_index(cpu_data, i);
-			return count;
-		}
-		++i;
-	}

drivers/cpufreq/intel_pstate.c static ssize_t store_energy_performance_preference( · line 662

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +5 -1
+	ret = match_string(energy_perf_strings, -1, str_preference);
+	if (ret < 0)
+		return ret;
 
-	return -EINVAL;
+	intel_pstate_set_energy_pref_index(cpu_data, ret);
+	return count;
 }
 
 static ssize_t show_energy_performance_preference(

Srinivas, any concerns?

maintainer Acked-by
#26 lore raw

Re: [PATCH v2 10/21] cpufreq: intel_pstate: use match_string() helper

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · CEST Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 54 lines
Quoted 42 lines
Cc Srinivas Pandruvada <[email protected]>
Cc Len Brown <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Viresh Kumar <[email protected]>

---
v2:
- add Reviewed-by tag.

 drivers/cpufreq/intel_pstate.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

performance

drivers/cpufreq/intel_pstate.c +0 -0
index 17e566af..d701e26 100644
@@ -645,21 +645,18 @@ static ssize_t

store_energy_performance_preference(
{

drivers/cpufreq/intel_pstate.c +1 -3
 	struct cpudata *cpu_data = all_cpu_data[policy->cpu];
 	char str_preference[21];
-	int ret, i = 0;
+	int ret;
 
 	ret = sscanf(buf, "%20s", str_preference);
 	if (ret != 1)
 		return -EINVAL;
 
-	while (energy_perf_strings[i] != NULL) {
-		if (!strcmp(str_preference,

energy_perf_strings[i])) {

drivers/cpufreq/intel_pstate.c +0 -1
-			intel_pstate_set_energy_pref_index(cpu_dat

a, i);

drivers/cpufreq/intel_pstate.c +1 -4
-			return count;
-		}
-		++i;
-	}
+	ret = match_string(energy_perf_strings, -1,

str_preference);

drivers/cpufreq/intel_pstate.c static ssize_t store_energy_performance_preference( · line 662

Quoted 9 lines
drivers/cpufreq/intel_pstate.c +4 -1
+	if (ret < 0)
+		return ret;
 
-	return -EINVAL;
+	intel_pstate_set_energy_pref_index(cpu_data, ret);
+	return count;
 }
 
 static ssize_t show_energy_performance_preference(

Srinivas, any concerns?

#28 lore raw

PATCH v2 11/21 drm/nouveau: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- handle err case before normal case - per Andy

 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +5 -8
index 6d99f11..67ba2ac 100644
@@ -644,16 +644,13 @@ static int nv17_tv_create_resources(struct drm_encoder *encoder,
 	int i;
 
 	if (nouveau_tv_norm) {
-		for (i = 0; i < num_tv_norms; i++) {
-			if (!strcmp(nv17_tv_norm_names[i], nouveau_tv_norm)) {
-				tv_enc->tv_norm = i;
-				break;
-			}
-		}
-
-		if (i == num_tv_norms)
+		i = match_string(nv17_tv_norm_names,
+				 num_tv_norms, nouveau_tv_norm);
+		if (i < 0)
 			NV_WARN(drm, "Invalid TV norm setting \"%s\"\n",
 				nouveau_tv_norm);
+		else
+			tv_enc->tv_norm = i;
 	}
 
 	drm_mode_create_tv_properties(dev, num_tv_norms, nv17_tv_norm_names);
Signature · 6 lines
1.7.12.4

_______________________________________________
Nouveau mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/nouveau
Reviewed-by on v2 11/21
#29 lore raw

Re: [PATCH v2 11/21] drm/nouveau: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 41 lines

---
v2:
- handle err case before normal case - per Andy

 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +5 -9
index 6d99f11..67ba2ac 100644
@@ -644,16 +644,13 @@ static int nv17_tv_create_resources(struct drm_encoder *encoder,
        int i;
 
        if (nouveau_tv_norm) {
-               for (i = 0; i < num_tv_norms; i++) {
-                       if (!strcmp(nv17_tv_norm_names[i], nouveau_tv_norm)) {
-                               tv_enc->tv_norm = i;
-                               break;
-                       }
-               }
-
-               if (i == num_tv_norms)
+               i = match_string(nv17_tv_norm_names,
+                                num_tv_norms, nouveau_tv_norm);
+               if (i < 0)
                        NV_WARN(drm, "Invalid TV norm setting \"%s\"\n",
                                nouveau_tv_norm);
+               else
+                       tv_enc->tv_norm = i;
        }
 
        drm_mode_create_tv_properties(dev, num_tv_norms, nv17_tv_norm_names);
--

1.7.12.4

Signature · 6 lines
With Best Regards,
Andy Shevchenko
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#30 lore raw

PATCH v2 12/21 drm: i2c: ch7006: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc David Airlie <[email protected]>
Cc Yisheng Xie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Arvind Yadav <[email protected]>

---
v2:
- handle err case before normal case.

 drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +5 -8
index 544a8a2..9eefdfe 100644
@@ -464,16 +464,13 @@ static int ch7006_encoder_init(struct i2c_client *client,
 	priv->chip_version = ch7006_read(client, CH7006_VERSION_ID);
 
 	if (ch7006_tv_norm) {
-		for (i = 0; i < NUM_TV_NORMS; i++) {
-			if (!strcmp(ch7006_tv_norm_names[i], ch7006_tv_norm)) {
-				priv->norm = i;
-				break;
-			}
-		}
-
-		if (i == NUM_TV_NORMS)
+		i = match_string(ch7006_tv_norm_names,
+				 NUM_TV_NORMS, ch7006_tv_norm);
+		if (i < 0)
 			ch7006_err(client, "Invalid TV norm setting \"%s\".\n",
 				   ch7006_tv_norm);
+		else
+			priv->norm = i;
 	}
 
 	if (ch7006_scale >= 0 && ch7006_scale <= 2)
Signature · 1 line
1.7.12.4
Reviewed-by on v2 12/21
#31 lore raw

Re: [PATCH v2 12/21] drm: i2c: ch7006: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 42 lines
Cc David Airlie <[email protected]>
Cc Yisheng Xie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Arvind Yadav <[email protected]>

---
v2:
- handle err case before normal case.

 drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +5 -9
index 544a8a2..9eefdfe 100644
@@ -464,16 +464,13 @@ static int ch7006_encoder_init(struct i2c_client *client,
        priv->chip_version = ch7006_read(client, CH7006_VERSION_ID);
 
        if (ch7006_tv_norm) {
-               for (i = 0; i < NUM_TV_NORMS; i++) {
-                       if (!strcmp(ch7006_tv_norm_names[i], ch7006_tv_norm)) {
-                               priv->norm = i;
-                               break;
-                       }
-               }
-
-               if (i == NUM_TV_NORMS)
+               i = match_string(ch7006_tv_norm_names,
+                                NUM_TV_NORMS, ch7006_tv_norm);
+               if (i < 0)
                        ch7006_err(client, "Invalid TV norm setting \"%s\".\n",
                                   ch7006_tv_norm);
+               else
+                       priv->norm = i;
        }
 
        if (ch7006_scale >= 0 && ch7006_scale <= 2)
--

1.7.12.4

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

PATCH v2 13/21 ima: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Mimi Zohar <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc James Morris <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc linux-integrity at vger.kernel.org
Cc linux-security-module at vger.kernel.org

---
v2:
- add Reviewed-by tag.

 security/integrity/ima/ima_main.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
security/integrity/ima/ima_main.c +4 -7
index 74d0bd7..f807093 100644
@@ -61,14 +61,11 @@ static int __init hash_setup(char *str)
 		goto out;
 	}
 
-	for (i = 0; i < HASH_ALGO__LAST; i++) {
-		if (strcmp(str, hash_algo_name[i]) == 0) {
-			ima_hash_algo = i;
-			break;
-		}
-	}
-	if (i == HASH_ALGO__LAST)
+	i = match_string(hash_algo_name, HASH_ALGO__LAST, str);
+	if (i < 0)
 		return 1;
+
+	ima_hash_algo = i;
 out:
 	hash_setup_done = 1;
 	return 1;
Signature · 6 lines
1.7.12.4

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info@ http://vger.kernel.org/majordomo-info.html
#33 lore raw

Re: [PATCH v2 13/21] ima: use match_string() helper

Quoted 12 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Mimi Zohar <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc James Morris <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc linux-integrity at vger.kernel.org
Cc linux-security-module at vger.kernel.org

In the future, the patch's author Signed-off-by is always first.

Thanks, this patch is now queued in the next-integrity branch.

Mimi

Quoted 20 lines

---
v2:
- add Reviewed-by tag.

 security/integrity/ima/ima_main.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
security/integrity/ima/ima_main.c +0 -5
index 74d0bd7..f807093 100644
@@ -61,14 +61,11 @@ static int __init hash_setup(char *str)
 		goto out;
 	}
 
-	for (i = 0; i < HASH_ALGO__LAST; i++) {
-		if (strcmp(str, hash_algo_name[i]) == 0) {
-			ima_hash_algo = i;
-			break;
-		}

security/integrity/ima/ima_main.c static int __init hash_setup(char *str) · line 71

Quoted 10 lines
security/integrity/ima/ima_main.c +4 -2
-	}
-	if (i == HASH_ALGO__LAST)
+	i = match_string(hash_algo_name, HASH_ALGO__LAST, str);
+	if (i < 0)
 		return 1;
+
+	ima_hash_algo = i;
 out:
 	hash_setup_done = 1;
 	return 1;

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#34 lore raw

Re: [PATCH v2 13/21] ima: use match_string() helper

Quoted 14 lines · Mimi Zohar
Quoted 12 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Mimi Zohar <[email protected]>
Cc Dmitry Kasatkin <[email protected]>
Cc James Morris <[email protected]>
Cc "Serge E. Hallyn" <[email protected]>
Cc linux-integrity at vger.kernel.org
Cc linux-security-module at vger.kernel.org
Quoted 3 lines

In the future, the patch's author Signed-off-by is always first.

Thanks, this patch is now queued in the next-integrity branch.

Hmm... It's interesting since git commit -s checks for author's SoB as a _last_ in the bunch.

Is it configurable?

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#35 lore raw

PATCH v2 14/21 sched/debug: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
v2:
- rename i to ret to show the change in returned value meaning - per Andy

 kernel/sched/debug.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
kernel/sched/debug.c +15 -16
index 15b10e2..5591147 100644
@@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp)
 		cmp += 3;
 	}
 
-	for (i = 0; i < __SCHED_FEAT_NR; i++) {
-		if (strcmp(cmp, sched_feat_names[i]) == 0) {
-			if (neg) {
-				sysctl_sched_features &= ~(1UL << i);
-				sched_feat_disable(i);
-			} else {
-				sysctl_sched_features |= (1UL << i);
-				sched_feat_enable(i);
-			}
-			break;
-		}
+	i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
+	if (i < 0)
+		return i;
+
+	if (neg) {
+		sysctl_sched_features &= ~(1UL << i);
+		sched_feat_disable(i);
+	} else {
+		sysctl_sched_features |= (1UL << i);
+		sched_feat_enable(i);
 	}
 
-	return i;
+	return 0;
 }
 
 static ssize_t
@@ -133,7 +132,7 @@ static int sched_feat_set(char *cmp)
 {
 	char buf[64];
 	char *cmp;
-	int i;
+	int ret;
 	struct inode *inode;
 
 	if (cnt > 63)
@@ -148,10 +147,10 @@ static int sched_feat_set(char *cmp)
 	/* Ensure the static_key remains in a consistent state */
 	inode = file_inode(filp);
 	inode_lock(inode);
-	i = sched_feat_set(cmp);
+	ret = sched_feat_set(cmp);
 	inode_unlock(inode);
-	if (i == __SCHED_FEAT_NR)
-		return -EINVAL;
+	if (ret < 0)
+		return ret;
 
 	*ppos += cnt;
 
Signature · 1 line
1.7.12.4
Reviewed-by on v2 14/21
#36 lore raw

Re: [PATCH v2 14/21] sched/debug: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

FWIW,

Quoted 72 lines
Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>

---
v2:
- rename i to ret to show the change in returned value meaning - per Andy

 kernel/sched/debug.c | 31 +++++++++++++++----------------
 1 file changed, 15 insertions(+), 16 deletions(-)
kernel/sched/debug.c +15 -17
index 15b10e2..5591147 100644
@@ -111,20 +111,19 @@ static int sched_feat_set(char *cmp)
                cmp += 3;
        }
 
-       for (i = 0; i < __SCHED_FEAT_NR; i++) {
-               if (strcmp(cmp, sched_feat_names[i]) == 0) {
-                       if (neg) {
-                               sysctl_sched_features &= ~(1UL << i);
-                               sched_feat_disable(i);
-                       } else {
-                               sysctl_sched_features |= (1UL << i);
-                               sched_feat_enable(i);
-                       }
-                       break;
-               }
+       i = match_string(sched_feat_names, __SCHED_FEAT_NR, cmp);
+       if (i < 0)
+               return i;
+
+       if (neg) {
+               sysctl_sched_features &= ~(1UL << i);
+               sched_feat_disable(i);
+       } else {
+               sysctl_sched_features |= (1UL << i);
+               sched_feat_enable(i);
        }
 
-       return i;
+       return 0;
 }
 
 static ssize_t
@@ -133,7 +132,7 @@ static int sched_feat_set(char *cmp)
 {
        char buf[64];
        char *cmp;
-       int i;
+       int ret;
        struct inode *inode;
 
        if (cnt > 63)
@@ -148,10 +147,10 @@ static int sched_feat_set(char *cmp)
        /* Ensure the static_key remains in a consistent state */
        inode = file_inode(filp);
        inode_lock(inode);
-       i = sched_feat_set(cmp);
+       ret = sched_feat_set(cmp);
        inode_unlock(inode);
-       if (i == __SCHED_FEAT_NR)
-               return -EINVAL;
+       if (ret < 0)
+               return ret;
 
        *ppos += cnt;
 
--

1.7.12.4

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

PATCH v2 15/21 ALSA: oxygen: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Clemens Ladisch <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>

---
v2:
- do not change the type of i - per Andy

 sound/pci/oxygen/oxygen_mixer.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
sound/pci/oxygen/oxygen_mixer.c +7 -7
index 4ca1266..81af21a 100644
@@ -1052,10 +1052,10 @@ static int add_controls(struct oxygen *chip,
 		[CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
 		[CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
 	};
-	unsigned int i, j;
+	unsigned int i;
 	struct snd_kcontrol_new template;
 	struct snd_kcontrol *ctl;
-	int err;
+	int j, err;
 
 	for (i = 0; i < count; ++i) {
 		template = controls[i];
@@ -1086,11 +1086,11 @@ static int add_controls(struct oxygen *chip,
 		err = snd_ctl_add(chip->card, ctl);
 		if (err < 0)
 			return err;
-		for (j = 0; j < CONTROL_COUNT; ++j)
-			if (!strcmp(ctl->id.name, known_ctl_names[j])) {
-				chip->controls[j] = ctl;
-				ctl->private_free = oxygen_any_ctl_free;
-			}
+		j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+		if (j >= 0) {
+			chip->controls[j] = ctl;
+			ctl->private_free = oxygen_any_ctl_free;
+		}
 	}
 	return 0;
 }
Signature · 1 line
1.7.12.4
#39 lore raw

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Quoted 7 lines
Quoted 5 lines
Cc Clemens Ladisch <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>

Applied, thanks.

Is it too late for nitpick?

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

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 14 lines · Andy Shevchenko
Quoted 12 lines · Takashi Iwai
Quoted 9 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Clemens Ladisch <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
Quoted 3 lines
Quoted 1 line

Applied, thanks.

Is it too late for nitpick?

Depends :)

Takashi

#41 lore raw

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 10 lines · Takashi Iwai
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Takashi Iwai

Applied, thanks.

Is it too late for nitpick?

Depends :)

See my previous mail then.

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

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

In reply to Yisheng Xie
Quoted 2 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Sorry, didn't notice before one thing:

sound/pci/oxygen/oxygen_mixer.c static int add_controls(struct oxygen *chip, · line 1093

Quoted 5 lines
sound/pci/oxygen/oxygen_mixer.c +5 -0
+               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+               if (j >= 0) {
+                       chip->controls[j] = ctl;
+                       ctl->private_free = oxygen_any_ctl_free;
+               }

It looks to me you may get rid of j completely by utilizing existing err.

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

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Sorry, didn't notice before one thing:

Quoted 7 lines

sound/pci/oxygen/oxygen_mixer.c static int add_controls(struct oxygen *chip, · line 1093

Quoted 5 lines
sound/pci/oxygen/oxygen_mixer.c +5 -0
+               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+               if (j >= 0) {
+                       chip->controls[j] = ctl;
+                       ctl->private_free = oxygen_any_ctl_free;
+               }

It looks to me you may get rid of j completely by utilizing existing err.

Well, err isn't ideal as it's referred as the actual index. That is, the line below looks weird to me:

	chip->controls[err] = ctl;

Of course, j isn't the best name, either, but at least, keeping the same variable makes the code conversion logic clearer.

thanks,

Takashi

#44 lore raw

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 10 lines · Takashi Iwai
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Yisheng Xie
sound/pci/oxygen/oxygen_mixer.c +5 -0
+               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+               if (j >= 0) {
+                       chip->controls[j] = ctl;
+                       ctl->private_free = oxygen_any_ctl_free;
+               }
Quoted 8 lines
Quoted 1 line

It looks to me you may get rid of j completely by utilizing existing err.

Well, err isn't ideal as it's referred as the actual index. That is, the line below looks weird to me:

        chip->controls[err] = ctl;

Of course, j isn't the best name, either, but at least, keeping the same variable makes the code conversion logic clearer.

Works for me either way.
Thanks!

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

Re: [PATCH v2 15/21] ALSA: oxygen: use match_string() helper

Quoted 18 lines · Andy Shevchenko
Quoted 16 lines · Takashi Iwai
Quoted 9 lines · Andy Shevchenko

sound/pci/oxygen/oxygen_mixer.c static int add_controls(struct oxygen *chip, · line 1093

Quoted 5 lines · Yisheng Xie
sound/pci/oxygen/oxygen_mixer.c +5 -0
+               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+               if (j >= 0) {
+                       chip->controls[j] = ctl;
+                       ctl->private_free = oxygen_any_ctl_free;
+               }

It looks to me you may get rid of j completely by utilizing existing err.

Well, err isn't ideal as it's referred as the actual index. That is, the line below looks weird to me:

        chip->controls[err] = ctl;
Quoted 5 lines
Quoted 2 lines

Of course, j isn't the best name, either, but at least, keeping the same variable makes the code conversion logic clearer.

Works for me either way.
Thanks!

OK, let's take as is.

thanks,

Takashi

#46 lore raw

PATCH v2 16/21 ASoC: max98088: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>

---
v2:
- split ret=xxx and move assignment to the line before 'if'
- fix error return value - both per Andy

 sound/soc/codecs/max98088.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
sound/soc/codecs/max98088.c +5 -8
index 865f64c..fb515aa 100644
@@ -1382,15 +1382,12 @@ static int max98088_set_bias_level(struct snd_soc_component *component,
 
 static int max98088_get_channel(struct snd_soc_component *component, const char *name)
 {
-	int i;
+	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
-		if (strcmp(name, eq_mode_name[i]) == 0)
-			return i;
-
-	/* Shouldn't happen */
-	dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
-	return -EINVAL;
+	ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
+	if (ret < 0)
+		dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
+	return ret;
 }
 
 static void max98088_setup_eq1(struct snd_soc_component *component)
Signature · 1 line
1.7.12.4
maintainer
#47 lore raw

Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

Quoted 2 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

I don't have either the cover letter or the rest of the series here so I've no context - what is the story here with regard to dependencies and things?

#48 lore raw

Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

Hi Mark,

Quoted 7 lines · Mark Brown
Quoted 2 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

I don't have either the cover letter or the rest of the series here so I've no context - what is the story here with regard to dependencies and things?

Sorry about that I should have sent cover letter to you, but for too many maintainer to sent, I ignore this to avoid make too much noisy.

Anyway, Here is the cover letter of v1 and I have add v2's cover letter to you:
https://lkml.org/lkml/2018/5/21/303

Each patch in this patchset is a separate one, for what this patchset want to do is use match_string() helper for echo subsystem.

Thanks
Yisheng

Quoted 1 line
maintainer
#49 lore raw

Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

Quoted 5 lines · Yisheng Xie

Anyway, Here is the cover letter of v1 and I have add v2's cover letter to you:
https://lkml.org/lkml/2018/5/21/303

Each patch in this patchset is a separate one, for what this patchset want to do is use match_string() helper for echo subsystem.

For something like this it's generally easier to not send everything as one big series - it avoids any confusion about dependencies and there's no actual relationship between the patches. Instead just sending each subsystem as a series or perhaps even just a bunch of separate patches should make things smoother.

#50 lore raw

Re: [PATCH v2 16/21] ASoC: max98088: use match_string() helper

Hi Mark,

Quoted 5 lines · Mark Brown
Quoted 2 lines · Yisheng Xie

Anyway, Here is the cover letter of v1 and I have add v2's cover letter to you:
https://lkml.org/lkml/2018/5/21/303

Quoted 8 lines
Quoted 2 lines

Each patch in this patchset is a separate one, for what this patchset want to do is use match_string() helper for echo subsystem.

For something like this it's generally easier to not send everything as one big series - it avoids any confusion about dependencies and there's no actual relationship between the patches. Instead just sending each subsystem as a series or perhaps even just a bunch of separate patches should make things smoother.

Thanks, will take this suggestion maybe next time.

Thanks
Yisheng

Quoted 1 line
maintainer
#51 lore raw

Applied "ASoC: max98088: use match_string() helper" to the asoc tree

In reply to Yisheng Xie

The patch

ASoC: max98088: use match_string() helper

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 3470631510fa383feac5969b436499ca9bad03b8 Mon Sep 17 00:00:00 2001

From: Xie Yisheng <[email protected]>
Date: Thu, 31 May 2018 19:11:21 +0800
Subject: [PATCH] ASoC: max98088: use match_string() helper

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
---
 sound/soc/codecs/max98088.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
sound/soc/codecs/max98088.c +5 -8
index 865f64c40b79..fb515aaa54fc 100644
@@ -1382,15 +1382,12 @@ static const char *eq_mode_name[] = {"EQ1 Mode", "EQ2 Mode"};
 
 static int max98088_get_channel(struct snd_soc_component *component, const char *name)
 {
-	int i;
+	int ret;
 
-	for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
-		if (strcmp(name, eq_mode_name[i]) == 0)
-			return i;
-
-	/* Shouldn't happen */
-	dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
-	return -EINVAL;
+	ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
+	if (ret < 0)
+		dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
+	return ret;
 }
 
 static void max98088_setup_eq1(struct snd_soc_component *component)
Signature · 1 line
2.17.0
#52 lore raw

PATCH v2 17/21 ASoC: max98095: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>

---
v2:
- split ret=xxxx and move assignment to the line before 'if' - per Andy

 sound/soc/codecs/max98095.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
sound/soc/codecs/max98095.c +5 -8
index 6bf2d0b..3b3a10d 100644
@@ -1634,15 +1634,12 @@ static void max98095_handle_eq_pdata(struct snd_soc_component *component)
 static int max98095_get_bq_channel(struct snd_soc_component *component,
 				   const char *name)
 {
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
-		if (strcmp(name, bq_mode_name[i]) == 0)
-			return i;
+	int ret;
 
-	/* Shouldn't happen */
-	dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
-	return -EINVAL;
+	ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
+	if (ret < 0)
+		dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
+	return ret;
 }
 
 static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
Signature · 1 line
1.7.12.4
maintainer
#53 lore raw

Applied "ASoC: max98095: use match_string() helper" to the asoc tree

The patch

ASoC: max98095: use match_string() helper

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 1567062f17284637519d004ecc5d7ea0d6c754c3 Mon Sep 17 00:00:00 2001

From: Xie Yisheng <[email protected]>
Date: Thu, 31 May 2018 19:11:22 +0800
Subject: [PATCH] ASoC: max98095: use match_string() helper

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Liam Girdwood <[email protected]>
Cc Mark Brown <[email protected]>
Cc Jaroslav Kysela <[email protected]>
Cc Takashi Iwai <[email protected]>
---
 sound/soc/codecs/max98095.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
sound/soc/codecs/max98095.c +5 -8
index 6bf2d0ba864f..3b3a10da7f40 100644
@@ -1634,15 +1634,12 @@ static const char *bq_mode_name[] = {"Biquad1 Mode", "Biquad2 Mode"};
 static int max98095_get_bq_channel(struct snd_soc_component *component,
 				   const char *name)
 {
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(bq_mode_name); i++)
-		if (strcmp(name, bq_mode_name[i]) == 0)
-			return i;
+	int ret;
 
-	/* Shouldn't happen */
-	dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
-	return -EINVAL;
+	ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
+	if (ret < 0)
+		dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
+	return ret;
 }
 
 static int max98095_put_bq_enum(struct snd_kcontrol *kcontrol,
Signature · 1 line
2.17.0
#54 lore raw

PATCH v2 18/21 ASoC: dapm: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
v2:
- add Reviewed-by tag.

 sound/soc/soc-dapm.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
sound/soc/soc-dapm.c +7 -11
index 2d97091..1e9a363 100644
@@ -724,18 +724,14 @@ static int dapm_connect_mux(struct snd_soc_dapm_context *dapm,
 		item = 0;
 	}
 
-	for (i = 0; i < e->items; i++) {
-		if (!(strcmp(control_name, e->texts[i]))) {
-			path->name = e->texts[i];
-			if (i == item)
-				path->connect = 1;
-			else
-				path->connect = 0;
-			return 0;
-		}
-	}
+	i = match_string(e->texts, e->items, control_name);
+	if (i < 0)
+		return -ENODEV;
+
+	path->name = e->texts[i];
+	path->connect = (i == item);
+	return 0;
 
-	return -ENODEV;
 }
 
 /* set up initial codec paths */
Signature · 1 line
1.7.12.4
#55 lore raw

PATCH v2 19/21 bcache: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

---
 drivers/md/bcache/util.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/md/bcache/util.c +2 -7
index 74febd5..cd1f4fd 100644
@@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[
 
 ssize_t bch_read_string_list(const char *buf, const char * const list[])
 {
-	size_t i;
+	ssize_t i;
 	char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 
 	s = strim(d);
 
-	for (i = 0; list[i]; i++)
-		if (!strcmp(list[i], s))
-			break;
+	i = match_string(list, -1, s);
 
 	kfree(d);
 
-	if (!list[i])
-		return -EINVAL;
-
 	return i;
 }
 
Signature · 1 line
1.7.12.4
#56 lore raw

Re: [PATCH v2 19/21] bcache: use match_string() helper

Quoted 6 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Hi Yishenng,

Andy Shevchenko <[email protected]> submitted a patch to replace the whole bch_read_string_list() with __sysfs_match_string(). And this patch is applied in Jens' block tree, will go into mainline kernel in v4.18.

If you search bcache mailing list, you may find a patch named with "bcache: Replace bch_read_string_list() by __sysfs_match_string()".

That means this patch will conflict with existing changes.

Thanks.

Coly Li

Quoted 34 lines
---
 drivers/md/bcache/util.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/md/bcache/util.c +2 -7
index 74febd5..cd1f4fd 100644
@@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[
 
 ssize_t bch_read_string_list(const char *buf, const char * const list[])
 {
-	size_t i;
+	ssize_t i;
 	char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 
 	s = strim(d);
 
-	for (i = 0; list[i]; i++)
-		if (!strcmp(list[i], s))
-			break;
+	i = match_string(list, -1, s);
 
 	kfree(d);
 
-	if (!list[i])
-		return -EINVAL;
-
 	return i;
 }
 
#57 lore raw

Re: [PATCH v2 19/21] bcache: use match_string() helper

Hi Coly,

Quoted 15 lines · Coly Li
Quoted 6 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Hi Yishenng,

Andy Shevchenko <[email protected]> submitted a patch to replace the whole bch_read_string_list() with __sysfs_match_string(). And this patch is applied in Jens' block tree, will go into mainline kernel in v4.18.

Quoted 4 lines

If you search bcache mailing list, you may find a patch named with "bcache: Replace bch_read_string_list() by __sysfs_match_string()".

That means this patch will conflict with existing changes.

Get it, and thanks for this information.

Sorry Andy, for doing this once more.

Thanks
Yisheng

Quoted 42 lines

Thanks.

Coly Li

Quoted 34 lines
---
 drivers/md/bcache/util.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/md/bcache/util.c +2 -7
index 74febd5..cd1f4fd 100644
@@ -136,22 +136,17 @@ ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[
 
 ssize_t bch_read_string_list(const char *buf, const char * const list[])
 {
-	size_t i;
+	ssize_t i;
 	char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
 	if (!d)
 		return -ENOMEM;
 
 	s = strim(d);
 
-	for (i = 0; list[i]; i++)
-		if (!strcmp(list[i], s))
-			break;
+	i = match_string(list, -1, s);
 
 	kfree(d);
 
-	if (!list[i])
-		return -EINVAL;
-
 	return i;
 }
 
#58 lore raw

Re: [PATCH v2 19/21] bcache: use match_string() helper

Quoted 18 lines · Yisheng Xie

Hi Coly,

Quoted 15 lines · Coly Li
Quoted 6 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Hi Yishenng,

Andy Shevchenko <[email protected]> submitted a patch to replace the whole bch_read_string_list() with __sysfs_match_string(). And this patch is applied in Jens' block tree, will go into mainline kernel in v4.18.

Quoted 9 lines
Quoted 4 lines

If you search bcache mailing list, you may find a patch named with "bcache: Replace bch_read_string_list() by __sysfs_match_string()".

That means this patch will conflict with existing changes.

Get it, and thanks for this information.

Sorry Andy, for doing this once more.

Hi Yisheng,

Thank you for the effort, hope to see more bcache patches from you :-)

Coly Li

#59 lore raw

PATCH v2 20/21 powerpc/xmon: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/xmon/xmon.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
arch/powerpc/xmon/xmon.c +11 -12
index a0842f1..872ac8c 100644
@@ -3161,7 +3161,7 @@ static void proccall(void)
 }
 
 #define N_PTREGS	44
-static char *regnames[N_PTREGS] = {
+static const char *regnames[N_PTREGS] = {
 	"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
 	"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
 	"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
@@ -3196,18 +3196,17 @@ static void proccall(void)
 			regname[i] = c;
 		}
 		regname[i] = 0;
-		for (i = 0; i < N_PTREGS; ++i) {
-			if (strcmp(regnames[i], regname) == 0) {
-				if (xmon_regs == NULL) {
-					printf("regs not available\n");
-					return 0;
-				}
-				*vp = ((unsigned long *)xmon_regs)[i];
-				return 1;
-			}
+		i = match_string(regnames, N_PTREGS, regname);
+		if (i < 0) {
+			printf("invalid register name '%%%s'\n", regname);
+			return 0;
 		}
-		printf("invalid register name '%%%s'\n", regname);
-		return 0;
+		if (xmon_regs == NULL) {
+			printf("regs not available\n");
+			return 0;
+		}
+		*vp = ((unsigned long *)xmon_regs)[i];
+		return 1;
 	}
 
 	/* skip leading "0x" if any */
Signature · 1 line
1.7.12.4
#60 lore raw

Re: [v2,20/21] powerpc/xmon: use match_string() helper

Quoted 8 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/0abbf2bfdc9dec32e9832aa8d4522a

cheers

#61 lore raw

PATCH v2 21/21 sparc64: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>
---
 arch/sparc/kernel/setup_64.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
arch/sparc/kernel/setup_64.c +3 -4
index 7944b3c..7af8c7e 100644
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
 				break;
 			}
 		}
-		for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-			if (!strcmp(prop, crypto_hwcaps[i]))
-				caps |= HWCAP_SPARC_CRYPTO;
-		}
+		i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+		if (i >= 0)
+			caps |= HWCAP_SPARC_CRYPTO;
 
 		plen = strlen(prop) + 1;
 		prop += plen;
Signature · 1 line
1.7.12.4
#62 lore raw

Re: [PATCH v2 21/21] sparc64: use match_string() helper

Review static unsigned long __init mdesc_cpu_hwcap_list(void) · line 514

Quoted 7 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

(quoted diff) +0 -0
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
                                break;
                        }
                }

It seems previous loop also can be replaced.

Quoted 13 lines
arch/sparc/kernel/setup_64.c +3 -5
-               for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-                       if (!strcmp(prop, crypto_hwcaps[i]))
-                               caps |= HWCAP_SPARC_CRYPTO;
-               }
+               i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+               if (i >= 0)
+                       caps |= HWCAP_SPARC_CRYPTO;
 
                plen = strlen(prop) + 1;
                prop += plen;
--

1.7.12.4

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

Re: [PATCH v2 21/21] sparc64: use match_string() helper

Hi Andy,

Quoted 10 lines · Andy Shevchenko

Review static unsigned long __init mdesc_cpu_hwcap_list(void) · line 514

Quoted 7 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

(quoted diff) +0 -0
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
                                break;
                        }
                }

It seems previous loop also can be replaced.

No, because the there is an NULL in the middle of the array hwcaps:

 static const char *hwcaps[] = {
          "flush", "stbar", "swap", "muldiv", "v9",
          "ultra3", "blkinit", "n2",

          /* These strings are as they appear in the machine description
           * 'hwcap-list' property for cpu nodes.
           */
          "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
          "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
          "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
          "adp",

};

Thanks
Yisheng

Quoted 17 lines
Quoted 14 lines
arch/sparc/kernel/setup_64.c +3 -5
-               for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-                       if (!strcmp(prop, crypto_hwcaps[i]))
-                               caps |= HWCAP_SPARC_CRYPTO;
-               }
+               i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+               if (i >= 0)
+                       caps |= HWCAP_SPARC_CRYPTO;
 
                plen = strlen(prop) + 1;
                prop += plen;
--

1.7.12.4

#64 lore raw

Re: [PATCH v2 21/21] sparc64: use match_string() helper

Quoted 26 lines · Yisheng Xie

Hi Andy,

Quoted 10 lines · Andy Shevchenko

Review static unsigned long __init mdesc_cpu_hwcap_list(void) · line 514

Quoted 7 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

(quoted diff) +0 -0
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
                                break;
                        }
                }

It seems previous loop also can be replaced.

No, because the there is an NULL in the middle of the array hwcaps:

 static const char *hwcaps[] = {
          "flush", "stbar", "swap", "muldiv", "v9",
          "ultra3", "blkinit", "n2",

          /* These strings are as they appear in the machine description
           * 'hwcap-list' property for cpu nodes.
           */
          "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
          "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
          "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
          "adp",
Quoted 1 line

};

Actually you can.
What you need is to add string literal instead of NULL and make an additional condition after match_string() in all users (not to many), something like

i = match_string();
if (i < 0)
...
if (BIT(i) = HWCAP_SPARC_CRYPTO) // or ! ...

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

Re: [PATCH v2 21/21] sparc64: use match_string() helper

Hi Andy,

Quoted 34 lines · Andy Shevchenko
Quoted 26 lines · Yisheng Xie

Hi Andy,

Quoted 10 lines · Andy Shevchenko

Review static unsigned long __init mdesc_cpu_hwcap_list(void) · line 514

Quoted 7 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

(quoted diff) +0 -0
@@ -512,10 +512,9 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
                                break;
                        }
                }

It seems previous loop also can be replaced.

No, because the there is an NULL in the middle of the array hwcaps:

 static const char *hwcaps[] = {
          "flush", "stbar", "swap", "muldiv", "v9",
          "ultra3", "blkinit", "n2",

          /* These strings are as they appear in the machine description
           * 'hwcap-list' property for cpu nodes.
           */
          "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
          "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
          "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
          "adp",
Quoted 1 line

};

Actually you can.
What you need is to add string literal instead of NULL and make an additional condition after match_string() in all users (not to many), something like

Quoted 4 lines

i = match_string();
if (i < 0)
...
if (BIT(i) = HWCAP_SPARC_CRYPTO) // or !

OK, I get your point.

Thanks
Yisheng

Quoted 2 lines

...

#66 lore raw

PATCH v3 21/21 sparc64: use match_string() helper

In reply to Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>

---
v3:
- add string literal instead of NULL for array hwcaps to make it can use match_string() too. - per Andy
v2
- new add for use match_string() helper patchset.

 arch/sparc/kernel/setup_64.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
arch/sparc/kernel/setup_64.c +9 -14
index 7944b3c..4f0ec0c 100644
@@ -401,7 +401,7 @@ void __init start_early_boot(void)
 	 */
 	"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
 	"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-	"ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
+	"ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
 	"adp",
 };
 
@@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
 	seq_puts(m, "cpucaps\t\t: ");
 	for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
 		unsigned long bit = 1UL << i;
-		if (hwcaps[i] && (caps & bit)) {
+		if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {
 			seq_printf(m, "%s%s",
 				   printed ? "," : "", hwcaps[i]);
 			printed++;
@@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)
 
 	for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
 		unsigned long bit = 1UL << i;
-		if (hwcaps[i] && (caps & bit))
+		if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
 			report_one_hwcap(&printed, hwcaps[i]);
 	}
 	if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
 	while (len) {
 		int i, plen;
 
-		for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-			unsigned long bit = 1UL << i;
+		i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+		if (i >= 0)
+			caps |= (1UL << i);
 
-			if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-				caps |= bit;
-				break;
-			}
-		}
-		for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-			if (!strcmp(prop, crypto_hwcaps[i]))
-				caps |= HWCAP_SPARC_CRYPTO;
-		}
+		i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+		if (i >= 0)
+			caps |= HWCAP_SPARC_CRYPTO;
 
 		plen = strlen(prop) + 1;
 		prop += plen;
Signature · 1 line
1.7.12.4
#67 lore raw

Re: [PATCH v3 21/21] sparc64: use match_string() helper

Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Thanks for an update.
My comments below.

I think you need to mentioned the string literal change in the commit message.

Quoted 20 lines
Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>

---
v3:
- add string literal instead of NULL for array hwcaps to make it can use match_string() too. - per Andy
v2
- new add for use match_string() helper patchset.

 arch/sparc/kernel/setup_64.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
arch/sparc/kernel/setup_64.c +0 -0
index 7944b3c..4f0ec0c 100644

arch/sparc/kernel/setup_64.c void __init start_early_boot(void) · line 405

Quoted 6 lines
arch/sparc/kernel/setup_64.c +1 -1
@@ -401,7 +401,7 @@ void __init start_early_boot(void)
         */
        "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
        "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-       "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
+       "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
        "adp",

Why not to spell "crypto" explicitly and remove comment?

arch/sparc/kernel/setup_64.c void cpucap_info(struct seq_file *m) · line 421

Quoted 8 lines
arch/sparc/kernel/setup_64.c +1 -1
 };
 
@@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
        seq_puts(m, "cpucaps\t\t: ");
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit)) {
+               if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {

I would rather swap the order of subsonditions to check if caps has a bit first, and then exclude CRYPTO.

arch/sparc/kernel/setup_64.c static void __init report_hwcaps(unsigned long caps) · line 476

Quoted 10 lines
arch/sparc/kernel/setup_64.c +1 -1
                        seq_printf(m, "%s%s",
                                   printed ? "," : "", hwcaps[i]);
                        printed++;
@@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)
 
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit))
+               if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
                        report_one_hwcap(&printed, hwcaps[i]);

Ditto.

arch/sparc/kernel/setup_64.c static unsigned long __init mdesc_cpu_hwcap_list(void) · line 509

Quoted 11 lines
arch/sparc/kernel/setup_64.c +3 -2
        }
        if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
        while (len) {
                int i, plen;
 
-               for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-                       unsigned long bit = 1UL << i;
+               i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+               if (i >= 0)
+                       caps |= (1UL << i);

Parens are redundant (and actually didn't present in the original code above).

Quoted 21 lines
arch/sparc/kernel/setup_64.c +3 -10
-                       if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-                               caps |= bit;
-                               break;
-                       }
-               }
-               for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-                       if (!strcmp(prop, crypto_hwcaps[i]))
-                               caps |= HWCAP_SPARC_CRYPTO;
-               }
+               i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+               if (i >= 0)
+                       caps |= HWCAP_SPARC_CRYPTO;
 
                plen = strlen(prop) + 1;
                prop += plen;
--

1.7.12.4

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

Re: [PATCH v3 21/21] sparc64: use match_string() helper

Hi Andy,

Sorry for late response. I will take your suggestion in next version.

Thanks
Yisheng

Quoted 102 lines · Andy Shevchenko
Quoted 3 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

Thanks for an update.
My comments below.

I think you need to mentioned the string literal change in the commit message.

Quoted 20 lines
Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>

---
v3:
- add string literal instead of NULL for array hwcaps to make it can use match_string() too. - per Andy
v2
- new add for use match_string() helper patchset.

 arch/sparc/kernel/setup_64.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)
arch/sparc/kernel/setup_64.c +0 -0
index 7944b3c..4f0ec0c 100644

arch/sparc/kernel/setup_64.c void __init start_early_boot(void) · line 405

Quoted 6 lines
arch/sparc/kernel/setup_64.c +1 -1
@@ -401,7 +401,7 @@ void __init start_early_boot(void)
         */
        "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
        "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-       "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
+       "ima", "cspare", "pause", "cbcond", "resv" /*reserved for crypto */,
        "adp",

Why not to spell "crypto" explicitly and remove comment?

arch/sparc/kernel/setup_64.c void cpucap_info(struct seq_file *m) · line 421

Quoted 8 lines
arch/sparc/kernel/setup_64.c +1 -1
 };
 
@@ -418,7 +418,7 @@ void cpucap_info(struct seq_file *m)
        seq_puts(m, "cpucaps\t\t: ");
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit)) {
+               if (bit != HWCAP_SPARC_CRYPTO && (caps & bit)) {

I would rather swap the order of subsonditions to check if caps has a bit first, and then exclude CRYPTO.

arch/sparc/kernel/setup_64.c static void __init report_hwcaps(unsigned long caps) · line 476

Quoted 10 lines
arch/sparc/kernel/setup_64.c +1 -1
                        seq_printf(m, "%s%s",
                                   printed ? "," : "", hwcaps[i]);
                        printed++;
@@ -472,7 +472,7 @@ static void __init report_hwcaps(unsigned long caps)
 
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit))
+               if (bit != HWCAP_SPARC_CRYPTO && (caps & bit))
                        report_one_hwcap(&printed, hwcaps[i]);

Ditto.

arch/sparc/kernel/setup_64.c static unsigned long __init mdesc_cpu_hwcap_list(void) · line 509

Quoted 11 lines
arch/sparc/kernel/setup_64.c +3 -2
        }
        if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +504,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
        while (len) {
                int i, plen;
 
-               for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-                       unsigned long bit = 1UL << i;
+               i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+               if (i >= 0)
+                       caps |= (1UL << i);

Parens are redundant (and actually didn't present in the original code above).

Quoted 21 lines
arch/sparc/kernel/setup_64.c +3 -10
-                       if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-                               caps |= bit;
-                               break;
-                       }
-               }
-               for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-                       if (!strcmp(prop, crypto_hwcaps[i]))
-                               caps |= HWCAP_SPARC_CRYPTO;
-               }
+               i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+               if (i >= 0)
+                       caps |= HWCAP_SPARC_CRYPTO;
 
                plen = strlen(prop) + 1;
                prop += plen;
--

1.7.12.4

#69 lore raw

PATCH v4 21/21 sparc64: use match_string() helper

In reply to Andy Shevchenko

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

As Andy's suggestion, this patch add string literal instead of NULL for crypto in array of hwcaps and make an additional condition after match_string() in all users of it.

Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>
---
 arch/sparc/kernel/setup_64.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
arch/sparc/kernel/setup_64.c +9 -15
index 7944b3c..6fa0c78 100644
@@ -401,8 +401,7 @@ void __init start_early_boot(void)
 	 */
 	"mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
 	"ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-	"ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
-	"adp",
+	"ima", "cspare", "pause", "cbcond", "crypto", "adp",
 };
 
 static const char *crypto_hwcaps[] = {
@@ -418,7 +417,7 @@ void cpucap_info(struct seq_file *m)
 	seq_puts(m, "cpucaps\t\t: ");
 	for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
 		unsigned long bit = 1UL << i;
-		if (hwcaps[i] && (caps & bit)) {
+		if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO) {
 			seq_printf(m, "%s%s",
 				   printed ? "," : "", hwcaps[i]);
 			printed++;
@@ -472,7 +471,7 @@ static void __init report_hwcaps(unsigned long caps)
 
 	for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
 		unsigned long bit = 1UL << i;
-		if (hwcaps[i] && (caps & bit))
+		if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO)
 			report_one_hwcap(&printed, hwcaps[i]);
 	}
 	if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +503,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
 	while (len) {
 		int i, plen;
 
-		for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-			unsigned long bit = 1UL << i;
+		i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+		if (i >= 0)
+			caps |= 1UL << i;
 
-			if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-				caps |= bit;
-				break;
-			}
-		}
-		for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-			if (!strcmp(prop, crypto_hwcaps[i]))
-				caps |= HWCAP_SPARC_CRYPTO;
-		}
+		i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+		if (i >= 0)
+			caps |= HWCAP_SPARC_CRYPTO;
 
 		plen = strlen(prop) + 1;
 		prop += plen;
Signature · 1 line
1.7.12.4
Reviewed-by on v4 21/21
#70 lore raw

Re: [PATCH v4 21/21] sparc64: use match_string() helper

Quoted 7 lines · Yisheng Xie

match_string() returns the index of an array for a matching string, which can be used instead of open coded variant.

As Andy's suggestion, this patch add string literal instead of NULL for crypto in array of hwcaps and make an additional condition after match_string() in all users of it.

FWIW,

Quoted 70 lines
Cc "David S. Miller" <[email protected]>
Cc Anthony Yznaga <[email protected]>
Cc Pavel Tatashin <[email protected]>
---
 arch/sparc/kernel/setup_64.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
arch/sparc/kernel/setup_64.c +9 -16
index 7944b3c..6fa0c78 100644
@@ -401,8 +401,7 @@ void __init start_early_boot(void)
         */
        "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2",
        "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau",
-       "ima", "cspare", "pause", "cbcond", NULL /*reserved for crypto */,
-       "adp",
+       "ima", "cspare", "pause", "cbcond", "crypto", "adp",
 };
 
 static const char *crypto_hwcaps[] = {
@@ -418,7 +417,7 @@ void cpucap_info(struct seq_file *m)
        seq_puts(m, "cpucaps\t\t: ");
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit)) {
+               if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO) {
                        seq_printf(m, "%s%s",
                                   printed ? "," : "", hwcaps[i]);
                        printed++;
@@ -472,7 +471,7 @@ static void __init report_hwcaps(unsigned long caps)
 
        for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
                unsigned long bit = 1UL << i;
-               if (hwcaps[i] && (caps & bit))
+               if ((caps & bit) && bit != HWCAP_SPARC_CRYPTO)
                        report_one_hwcap(&printed, hwcaps[i]);
        }
        if (caps & HWCAP_SPARC_CRYPTO)
@@ -504,18 +503,13 @@ static unsigned long __init mdesc_cpu_hwcap_list(void)
        while (len) {
                int i, plen;
 
-               for (i = 0; i < ARRAY_SIZE(hwcaps); i++) {
-                       unsigned long bit = 1UL << i;
+               i = match_string(hwcaps, ARRAY_SIZE(hwcaps), prop);
+               if (i >= 0)
+                       caps |= 1UL << i;
 
-                       if (hwcaps[i] && !strcmp(prop, hwcaps[i])) {
-                               caps |= bit;
-                               break;
-                       }
-               }
-               for (i = 0; i < ARRAY_SIZE(crypto_hwcaps); i++) {
-                       if (!strcmp(prop, crypto_hwcaps[i]))
-                               caps |= HWCAP_SPARC_CRYPTO;
-               }
+               i = match_string(crypto_hwcaps, ARRAY_SIZE(crypto_hwcaps), prop);
+               if (i >= 0)
+                       caps |= HWCAP_SPARC_CRYPTO;
 
                plen = strlen(prop) + 1;
                prop += plen;
--

1.7.12.4

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#71 lore raw
In reply to Yisheng Xie

+ Mark

Quoted 59 lines · Yisheng Xie

Andy introduce helper function match_string() which can be used to return the index of array for a matching string. so we can use it in many places instead of open coded variant.

I just try to make this API be used more commonly, sorry if this makes too much big patchset.

v2:
- Remove the Patches which Andy already sent out, or maintainer already picked up.
- Add Reviewed-by or Acked-by tags for some patchs.
- Add some new patches[19-21].

Yisheng Xie (21):
usb: phy: use match_string() helper
mfd: omap-usb-host: use match_string() helper
Staging: gdm724x: use match_string() helper
cxgb4: use match_string() helper
hp100: use match_string() helper
iwlwifi: mvm: use match_string() helper
bus: fsl-mc: use match_string() helper
clk: bcm2835: use match_string() helper
clk: use match_string() helper
cpufreq: intel_pstate: use match_string() helper drm/nouveau: use match_string() helper
drm: i2c: ch7006: use match_string() helper
ima: use match_string() helper sched/debug: use match_string() helper
ALSA: oxygen: use match_string() helper
ASoC: max98088: use match_string() helper
ASoC: max98095: use match_string() helper
ASoC: dapm: use match_string() helper
bcache: use match_string() helper powerpc/xmon: use match_string() helper
sparc64: use match_string() helper

 arch/powerpc/xmon/xmon.c                         | 23 +++++++++---------
 arch/sparc/kernel/setup_64.c                     |  7 +++---
 drivers/bus/fsl-mc/fsl-mc-allocator.c            | 24 ++++--------------
 drivers/clk/bcm/clk-bcm2835.c                    | 13 +++++-----
 drivers/clk/clk.c                                |  8 ++----
 drivers/cpufreq/intel_pstate.c                   | 15 +++++-------
 drivers/gpu/drm/i2c/ch7006_drv.c                 | 13 ++++------
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c        | 13 ++++------
 drivers/md/bcache/util.c                         |  9 ++-----
 drivers/mfd/omap-usb-host.c                      | 24 ++----------------
 drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c   | 14 +++--------
 drivers/net/ethernet/hp/hp100.c                  |  9 +------
 drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 13 +++-------
 drivers/staging/gdm724x/gdm_tty.c                | 18 ++++----------
 drivers/usb/phy/of.c                             | 10 ++++----
 kernel/sched/debug.c                             | 31 ++++++++++++------------
 security/integrity/ima/ima_main.c                | 11 +++------
 sound/pci/oxygen/oxygen_mixer.c                  | 14 +++++------
 sound/soc/codecs/max98088.c                      | 13 ++++------
 sound/soc/codecs/max98095.c                      | 13 ++++------
 sound/soc/soc-dapm.c                             | 18 ++++++--------
 21 files changed, 109 insertions(+), 204 deletions(-)