use match_string() helper
Subsystems (44)
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 intead of open coded variant.
I just try to make this API be used more commonly, sorry if this makes too much big patchset.
Yisheng Xie (33):
usb: phy: use match_string() helper
mfd: omap-usb-host: use match_string() helper
Staging: gdm724x: use match_string() helper
gpiolib-of: use match_string() helper
cxgb4: use match_string() helper
hp100: use match_string() helper
iwlwifi: mvm: use match_string() helper
vfio: use match_string() helper
phy: tegra: use match_string() helper
pata_hpt37x: use match_string() helper
bus: fsl-mc: use match_string() helper
clk: bcm2835: use match_string() helper
clk: rockchip: use match_string() helper
clk: use match_string() helper
cpufreq: intel_pstate: use match_string() helper
mmc: sdhci-xenon: use match_string() helper
pinctrl: armada-37xx: use match_string() helper
power: supply: use match_string() helper
thermal: db8500: use match_string() helper
video: fbdev: pxafb: use match_string() helper drm/nouveau: use match_string() helper drm/i915: use match_string() helper
drm: i2c: ch7006: use match_string() helper
drm: use match_string() helper
ima: use match_string() helper
apparmor: use match_string() helper sched/debug: use match_string() helper
ALSA: dice use match_string() helper
ALSA: oxfw: 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
drivers/ata/pata_hpt37x.c | 13 +++++------- drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +++++------------------ drivers/clk/bcm/clk-bcm2835.c | 14 ++++++------- drivers/clk/clk.c | 8 ++------ drivers/clk/rockchip/clk.c | 16 +++++---------- drivers/cpufreq/intel_pstate.c | 15 ++++++-------- drivers/gpio/gpiolib-of.c | 7 +------ drivers/gpu/drm/drm_panel_orientation_quirks.c | 7 ++----- drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++------- drivers/gpu/drm/i915/intel_pipe_crc.c | 22 ++++++++++----------- drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++------- drivers/mfd/omap-usb-host.c | 24 ++--------------------- drivers/mmc/host/sdhci-xenon-phy.c | 11 +++-------- drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++--------- drivers/net/ethernet/hp/hp100.c | 9 +-------- drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++-------- drivers/phy/tegra/xusb.c | 15 +------------- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++------------- drivers/power/supply/power_supply_core.c | 16 ++++++--------- drivers/staging/gdm724x/gdm_tty.c | 16 ++++----------- drivers/thermal/db8500_thermal.c | 8 +++----- drivers/usb/phy/of.c | 12 +++++------- drivers/vfio/vfio.c | 11 +++-------- drivers/video/fbdev/pxafb.c | 6 ++---- kernel/sched/debug.c | 20 +++++++++---------- security/apparmor/lsm.c | 25 +++++++++++------------- security/integrity/ima/ima_main.c | 11 ++++------- sound/firewire/dice/dice.c | 8 +------- sound/firewire/oxfw/oxfw.c | 8 +------- sound/pci/oxygen/oxygen_mixer.c | 13 ++++++------ sound/soc/codecs/max98088.c | 9 +++------ sound/soc/codecs/max98095.c | 11 ++++------- sound/soc/soc-dapm.c | 18 +++++++---------- 33 files changed, 137 insertions(+), 307 deletions(-)
Signature · 1 line
1.7.12.4
PATCH 1/33 usb: phy: use match_string() helper
match_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/usb/phy/of.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/usb/phy/of.c +5 -7
@@ -28,16 +28,14 @@enum usb_phy_interface of_usb_get_phy_mode (struct device_node *np) {const char *phy_type; -int err, i; +int ret; - err =of_property_read_string (np,"phy_type" , &phy_type); -if (err <0 ) + ret =of_property_read_string (np,"phy_type" , &phy_type); +if (ret <0 )return USBPHY_INTERFACE_MODE_UNKNOWN ; -for (i =0 ; i <ARRAY_SIZE (usbphy_modes); i++) -if (!strcmp (phy_type, usbphy_modes[i])) -return i; + ret =match_string (usbphy_modes,ARRAY_SIZE (usbphy_modes), phy_type); -return USBPHY_INTERFACE_MODE_UNKNOWN ; +return (ret <0 ) ?USBPHY_INTERFACE_MODE_UNKNOWN : ret; }EXPORT_SYMBOL_GPL (of_usb_get_phy_mode);
Re: [PATCH 01/33] usb: phy: use match_string() helper
drivers/usb/phy/of.c line 31
Quoted 5 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.drivers/usb/phy/of.c +1
-1-int err, i; +int ret;
int err;
would still work.
Greg Kroah-Hartman
maintainerRe: [PATCH 01/33] usb: phy: use match_string() helper
Quoted 10 lines · Andy Shevchenko
drivers/usb/phy/of.c line 31
Quoted 5 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.drivers/usb/phy/of.c +1
-1-int err, i; +int ret;int err;
would still work.
And it reduces churn.
---
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
Re: [PATCH 01/33] usb: phy: use match_string() helper
Hi,
Quoted 5 lines · Greg Kroah-Hartman
Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.
Quoted 8 lines
Quoted 6 lines
drivers/usb/phy/of.c line 31
Quoted 2 lines
drivers/usb/phy/of.c +1
-1-int err, i; +int ret;int err;
would still work.
And it reduces churn.
I will keep it as err in next version.
Thanks
Yisheng
Quoted 2 lines
---
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
PATCH 2/33 mfd: omap-usb-host: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/mfd/omap-usb-host.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
drivers/mfd/omap-usb-host.c +2 -22
@@ -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
Re: [PATCH 02/33] mfd: omap-usb-host: 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 intead of open coded variant.
Looks OK to me:
Lee Jones
AppliedRe: [PATCH 02/33] mfd: omap-usb-host: use match_string() helper
In reply to Yisheng XieQuoted 10 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Tony Lindgren <[email protected]>Cc Lee Jones <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- drivers/mfd/omap-usb-host.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-)
Applied, thanks.
Signature · 4 lines
Lee Jones [李琼斯] Linaro Services Technical Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 3/33 Staging: gdm724x: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/staging/gdm724x/gdm_tty.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/staging/gdm724x/gdm_tty.c +4 -12
@@ -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 ((const char **)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
Re: [PATCH 03/33] Staging: gdm724x: use match_string() helper
drivers/staging/gdm724x/gdm_tty.c static int gdm_tty_install(struct tty_driver *driver, struct tty_struct *tty) · line 70
Quoted 6 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.drivers/staging/gdm724x/gdm_tty.c +2
-0+ ret =match_string ((const char **)DRIVER_STRING , +TTY_MAX_COUNT , tty->driver->driver_name);
It looks like DRIVER_STRING should be converted to const * const.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 4/33 gpiolib-of: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/gpio/gpiolib-of.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/gpio/gpiolib-of.c +1 -6
@@ -202,7 +202,6 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char * };struct device_node *np = dev->of_node;struct gpio_desc *desc; -int i;if (!IS_ENABLED (CONFIG_REGULATOR ))return ERR_PTR (-ENOENT );
@@ -210,11 +209,7 @@ static struct gpio_desc *of_find_regulator_gpio(struct device *dev, const char *if (!con_id)return ERR_PTR (-ENOENT ); -for (i =0 ; i <ARRAY_SIZE (whitelist); i++) -if (!strcmp (con_id, whitelist[i])) -break ; - -if (i ==ARRAY_SIZE (whitelist)) +if (match_string (whitelist,ARRAY_SIZE (whitelist), con_id) <0 )return ERR_PTR (-ENOENT ); desc =of_get_named_gpiod_flags (np, con_id,0 , of_flags);
Signature · 1 line
1.7.12.4
Re: [PATCH 04/33] gpiolib-of: 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 intead of open coded variant.
https://patchwork.ozlabs.org/patch/908134/
Quoted 3 lines
Cc Linus Walleij <[email protected]>Signed-off-by Yisheng Xie <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 5/33 cxgb4: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- 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
@@ -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
Re: [PATCH 05/33] cxgb4: 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 intead of open coded variant.drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +0
-5-for (i =0 ; i <ARRAY_SIZE (cudbg_region); i++) { -if (!strcmp (cudbg_region[i], region_name)) { - found =1 ; - idx = i; -break ;
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c static int cudbg_get_mem_region(struct adapter *padap, · line 789
Quoted 10 lines
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +4
-5- } - } -if (!found) -return -EINVAL ; + rc =match_string (cudbg_region,ARRAY_SIZE (cudbg_region), region_name); +if (rc <0 ) +return rc; - found =0 ; + idx = rc;
Is found still in use after this?
If so, is it initialized properly now?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 05/33] cxgb4: use match_string() helper
Hi Andy,
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +3
-9-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;
Quoted 5 lines
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c static int cudbg_get_mem_region(struct adapter *padap, · line 789
Quoted 2 lines
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c +1
-1- found =0 ; + idx = rc;Is found still in use after this?
If so, is it initialized properly now?
it is initialized when define 'found', so no need to be initialized once more.
Thanks
Yisheng
Quoted 1 line
PATCH 6/33 hp100: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/net/ethernet/hp/hp100.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/hp/hp100.c +1 -8
@@ -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
PATCH 7/33 iwlwifi: mvm: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +3 -8
@@ -671,14 +671,9 @@ 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)) + bt_force_ant_mode =match_string (modes_str, +ARRAY_SIZE (modes_str), buf); +if (bt_force_ant_mode <0 )return -EINVAL ; ret =0 ;
Signature · 1 line
1.7.12.4
Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
Quoted 38 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead 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]>Signed-off-by Yisheng Xie <[email protected]>--- drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +3
-8@@ -671,14 +671,9 @@ 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)) + bt_force_ant_mode =match_string (modes_str, +ARRAY_SIZE (modes_str), buf); +if (bt_force_ant_mode <0 )return -EINVAL ;
Quoted 1 line
ret = 0;
Looks fine, I'll push this to our internal tree for review and take a closer look at what the match_string() function does exactly.
Thanks for the patch.
--
Cheers,
Luca.
Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
In reply to Yisheng XieQuoted 6 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.int ret, bt_force_ant_mode;drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +0
-1- for (bt_force_ant_mode = 0;
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf,
Quoted 10 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +2
-7- 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)) + bt_force_ant_mode =match_string (modes_str, +ARRAY_SIZE (modes_str), buf);
One line?
Quoted 2 lines
+ if (
bt_force_ant_mode< 0)return -EINVAL;
I would rather use
ret = match_string();
if (ret < 0)
return ret;
bt_force_... = ret;
But it's up tu Loca.
Quoted 2 lines
ret = 0;Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
Hi Andy,
Quoted 15 lines · Andy Shevchenko
Quoted 13 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.int ret, bt_force_ant_mode;drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +0
-8-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))
Quoted 4 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c static ssize_t iwl_dbgfs_bt_cmd_read(struct file *file, char __user *user_buf, · line 675
Quoted 2 lines
drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c +2
-0+ bt_force_ant_mode =match_string (modes_str, +ARRAY_SIZE (modes_str), buf);One line?
hmm, if use ret instead it will no over 80 chars.
Quoted 6 lines
Quoted 3 lines
+ if (
bt_force_ant_mode< 0)return -EINVAL;I would rather use
Quoted 7 lines
ret =
match_string();
if (ret < 0)
return ret;
bt_force_... = ret;But it's up tu Loca.
OK, I will change it if Loca agree your opinion.
Thanks
Yisheng
Quoted 6 lines
Quoted 3 lines
ret = 0;
Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper
Quoted 1 line · Yisheng Xie
Quoted 1 line
But it's up tu Loca.
Shame on me. I meant Luca, of course!
Luca, sorry.
Quoted 1 line
OK, I will change it if Loca agree your opinion.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 8/33 vfio: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/vfio/vfio.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/vfio/vfio.c +3 -8
@@ -630,8 +630,6 @@ static struct vfio_device *vfio_group_get_device(struct vfio_group *group,static bool vfio_dev_whitelisted (struct device *dev,struct device_driver *drv) { -int i; -if (dev_is_pci (dev)) {struct pci_dev *pdev =to_pci_dev (dev);
@@ -639,12 +637,9 @@ static bool vfio_dev_whitelisted(struct device *dev, struct device_driver *drv)return true; } -for (i =0 ; i <ARRAY_SIZE (vfio_driver_whitelist); i++) { -if (!strcmp (drv->name, vfio_driver_whitelist[i])) -return true; - } - -return false; +return match_string (vfio_driver_whitelist, +ARRAY_SIZE (vfio_driver_whitelist), + drv->name) >=0 ; }/*
Signature · 1 line
1.7.12.4
Alex Williamson
AppliedRe: [PATCH 08/33] vfio: use match_string() helper
Quoted 9 lines · On Mon, 21 May 2018 19:57:45 +0800 Yisheng Xie <[email protected]> wrote:
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Alex Williamson <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- drivers/vfio/vfio.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
Applied to the vfio next branch for v4.18 with Andy's R-b. Thanks,
Alex
Quoted 29 lines
drivers/vfio/vfio.c +3
-8@@ -630,8 +630,6 @@ static struct vfio_device *vfio_group_get_device(struct vfio_group *group,static bool vfio_dev_whitelisted (struct device *dev,struct device_driver *drv) { -int i; -if (dev_is_pci (dev)) {struct pci_dev *pdev =to_pci_dev (dev);@@ -639,12 +637,9 @@ static bool vfio_dev_whitelisted(struct device *dev, struct device_driver *drv)return true; } -for (i =0 ; i <ARRAY_SIZE (vfio_driver_whitelist); i++) { -if (!strcmp (drv->name, vfio_driver_whitelist[i])) -return true; - } - -return false; +return match_string (vfio_driver_whitelist, +ARRAY_SIZE (vfio_driver_whitelist), + drv->name) >=0 ; }/*
PATCH 9/33 phy: tegra: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/phy/tegra/xusb.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
drivers/phy/tegra/xusb.c +1 -14
@@ -102,19 +102,6 @@ static struct phy *tegra_xusb_pad_of_xlate(struct device *dev,return np; } -static int -tegra_xusb_lane_lookup_function (struct tegra_xusb_lane *lane, -const char *function) -{ -unsigned int i; - -for (i =0 ; i < lane->soc->num_funcs; i++) -if (strcmp (function, lane->soc->funcs[i]) ==0 ) -return i; - -return -EINVAL ; -} -int tegra_xusb_lane_parse_dt (struct tegra_xusb_lane *lane,struct device_node *np) {
@@ -126,7 +113,7 @@ int tegra_xusb_lane_parse_dt(struct tegra_xusb_lane *lane,if (err <0 )return err; - err =tegra_xusb_lane_lookup_function (lane, function); + err =match_string (lane->soc->funcs, lane->soc->num_funcs, function);if (err <0 ) {dev_err (dev,"invalid function \"%s\" for lane \"%s\"\n" , function, np->name);
Signature · 1 line
1.7.12.4
Re: [PATCH 09/33] phy: tegra: 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 intead of open coded variant.
https://patchwork.ozlabs.org/patch/908133/
Quoted 4 lines
Cc Kishon Vijay Abraham I <[email protected]>Cc Thierry Reding <[email protected]>Cc Jonathan Hunter <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 10/33 pata_hpt37x: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/ata/pata_hpt37x.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/ata/pata_hpt37x.c +5 -8
@@ -224,17 +224,14 @@ static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char * const list[]) {unsigned char model_num[ATA_ID_PROD_LEN +1 ]; -int i =0 ; +int i;ata_id_c_string (dev->id, model_num,ATA_ID_PROD ,sizeof (model_num)); -while (list[i] !=NULL ) { -if (!strcmp (list[i], model_num)) { -pr_warn ("%s is not supported for %s\n" , - modestr, list[i]); -return 1 ; - } - i++; + i =match_string (list,-1 , model_num); +if (i >=0 ) { +pr_warn ("%s is not supported for %s\n" , modestr, list[i]); +return 1 ; }return 0 ; }
Signature · 1 line
1.7.12.4
Re: [PATCH 10/33] pata_hpt37x: 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 intead of open coded variant.
https://www.spinics.net/lists/linux-ide/msg55658.html
Quoted 3 lines
Cc Bartlomiej Zolnierkiewicz <[email protected]>Cc Tejun Heo <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 11/33 bus: fsl-mc: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- 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
@@ -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
PATCH 12/33 clk: bcm2835: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/clk/bcm/clk-bcm2835.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/clk/bcm/clk-bcm2835.c +6 -8
@@ -1395,8 +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; -int ret; +int i, ret;/* * Replace our strings referencing parent clocks with the
@@ -1405,12 +1404,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
Re: [PATCH 12/33] clk: bcm2835: use match_string() helper
Quoted 34 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead 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.orgCc linux-rpi-kernel at lists.infradead.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Yisheng Xie <[email protected]>--- drivers/clk/bcm/clk-bcm2835.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)drivers/clk/bcm/clk-bcm2835.c +1
-3@@ -1395,8 +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; -int ret; +int i, ret;/* * Replace our strings referencing parent clocks with the @@ -1405,12 +1404,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++) {
drivers/clk/bcm/clk-bcm2835.c static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman, · line 1411
Quoted 10 lines
drivers/clk/bcm/clk-bcm2835.c +5
-5-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];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180521/d011e272/attachment.sig>
Re: [PATCH 12/33] clk: bcm2835: use match_string() helper
In reply to Yisheng XieQuoted 12 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead 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.orgCc linux-rpi-kernel at lists.infradead.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Yisheng Xie <[email protected]>
drivers/clk/bcm/clk-bcm2835.c static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman, · line 1398
Quoted 3 lines
drivers/clk/bcm/clk-bcm2835.c +1
-2-size_t i, j; -int ret; +int i, ret;
I do not see any need to change type for i.
Quoted 5 lines
drivers/clk/bcm/clk-bcm2835.c +5
-0+ ret =match_string (cprman_parent_names, +ARRAY_SIZE (cprman_parent_names), + parents[i]); +if (ret >=0 ) + parents[i] = cprman->real_parent_names[ret];
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 12/33] clk: bcm2835: use match_string() helper
Hi Andy,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead 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.orgCc linux-rpi-kernel at lists.infradead.orgCc linux-arm-kernel at lists.infradead.orgSigned-off-by Yisheng Xie <[email protected]>
Quoted 5 lines
drivers/clk/bcm/clk-bcm2835.c static struct clk_hw *bcm2835_register_clock(struct bcm2835_cprman *cprman, · line 1398
Quoted 3 lines
drivers/clk/bcm/clk-bcm2835.c +1
-2-size_t i, j; -int ret; +int i, ret;I do not see any need to change type for i.
Right, I just want to smaller the line of code, for unsinged int is also OK for i. Anyway, I can change it as your suggestion in next version.
Thanks
Yisheng
Quoted 8 lines
Quoted 6 lines
drivers/clk/bcm/clk-bcm2835.c +5
-0+ ret =match_string (cprman_parent_names, +ARRAY_SIZE (cprman_parent_names), + parents[i]); +if (ret >=0 ) + parents[i] = cprman->real_parent_names[ret];
PATCH 13/33 clk: rockchip: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/clk/rockchip/clk.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/clk/rockchip/clk.c +5 -11
@@ -274,18 +274,10 @@ static struct clk *rockchip_clk_register_frac_branch(struct clk_mux *frac_mux = &frac->mux;struct clk_init_data init;struct clk *mux_clk; -int i, ret; - - frac->mux_frac_idx =-1 ; -for (i =0 ; i < child->num_parents; i++) { -if (!strcmp (name, child->parent_names[i])) { -pr_debug ("%s: found fractional parent in mux at pos %d\n" , - __func__, i); - frac->mux_frac_idx = i; -break ; - } - } +int ret; + frac->mux_frac_idx =match_string (child->parent_names, + child->num_parents, name); frac->mux_ops = &clk_mux_ops; frac->clk_nb.notifier_call = rockchip_clk_frac_notifier_cb;
@@ -312,6 +304,8 @@ static struct clk *rockchip_clk_register_frac_branch(/* notifier on the fraction divider to catch rate changes */ if (frac->mux_frac_idx >=0 ) { +pr_debug ("%s: find fractional parent in mux at pos %d\n" , + __func__, frac->mux_frac_idx); ret =clk_notifier_register (clk, &frac->clk_nb);if (ret) pr_err("%s: failed to register clock notifier for %s\n",
Signature · 1 line
1.7.12.4
Re: [PATCH 13/33] clk: rockchip: use match_string() helper
Am Montag, 21. Mai 2018, 13:57:50 CEST schrieb Yisheng Xie:
Quoted 12 lines
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Michael Turquette <[email protected]>Cc Stephen Boyd <[email protected]>Cc Heiko Stuebner <[email protected]>Cc linux-clk at vger.kernel.orgCc linux-arm-kernel at lists.infradead.orgCc linux-rockchip at lists.infradead.orgSigned-off-by Yisheng Xie <[email protected]>
drivers/clk/rockchip/clk.c static struct clk *rockchip_clk_register_frac_branch( · line 308
Quoted 5 lines
drivers/clk/rockchip/clk.c +2
-0@@ -312,6 +304,8 @@ static struct clk *rockchip_clk_register_frac_branch(/* notifier on the fraction divider to catch rate changes */ if (frac->mux_frac_idx >=0 ) { +pr_debug ("%s: find fractional parent in mux at pos %d\n" , + __func__, frac->mux_frac_idx);
applied to my Rockchip clk branch for 4.18 after changing the "find" above to "found" again ;-) .
Thanks for the nice cleanup
Heiko
PATCH 14/33 clk: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/clk/clk.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/clk/clk.c +2 -6
@@ -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
Re: [PATCH 14/33] clk: use match_string() helper
drivers/clk/clk.c bool clk_has_parent(struct clk *clk, struct clk *parent) · line 2187
Quoted 5 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.drivers/clk/clk.c +2
-0+return match_string (core->parent_names, + core->num_parents, parent_core->name) >=0 ;
More logical split is to leave second parameter on the first line.
P.S. I would rather to put everything to one line even if takes ~83 characters.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 15/33 cpufreq: intel_pstate: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/cpufreq/intel_pstate.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
drivers/cpufreq/intel_pstate.c +6 -9
@@ -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
PATCH 16/33 mmc: sdhci-xenon: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/mmc/host/sdhci-xenon-phy.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/mmc/host/sdhci-xenon-phy.c +3 -8
@@ -814,15 +814,10 @@ static int xenon_add_phy(struct device_node *np, struct sdhci_host *host, {struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct xenon_priv *priv =sdhci_pltfm_priv (pltfm_host); -int i, ret; +int ret; -for (i =0 ; i <NR_PHY_TYPES ; i++) { -if (!strcmp (phy_name, phy_types[i])) { - priv->phy_type = i; -break ; - } - } -if (i ==NR_PHY_TYPES ) { + priv->phy_type =match_string (phy_types,NR_PHY_TYPES , phy_name); +if (priv->phy_type <0 ) {dev_err (mmc_dev (host->mmc),"Unable to determine PHY name %s. Use default eMMC 5.1 PHY\n" , phy_name);
Signature · 1 line
1.7.12.4
Re: [PATCH 16/33] mmc: sdhci-xenon: 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 intead of open coded variant.Cc Adrian Hunter <[email protected]>Cc Hu Ziji <[email protected]>Cc Ulf Hansson <[email protected]>Signed-off-by Yisheng Xie <[email protected]>
Quoted 28 lines
--- drivers/mmc/host/sdhci-xenon-phy.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)drivers/mmc/host/sdhci-xenon-phy.c +3
-8@@ -814,15 +814,10 @@ static int xenon_add_phy(struct device_node *np, struct sdhci_host *host, {struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct xenon_priv *priv =sdhci_pltfm_priv (pltfm_host); -int i, ret; +int ret; -for (i =0 ; i <NR_PHY_TYPES ; i++) { -if (!strcmp (phy_name, phy_types[i])) { - priv->phy_type = i; -break ; - } - } -if (i ==NR_PHY_TYPES ) { + priv->phy_type =match_string (phy_types,NR_PHY_TYPES , phy_name); +if (priv->phy_type <0 ) {dev_err (mmc_dev (host->mmc),"Unable to determine PHY name %s. Use default eMMC 5.1 PHY\n" , phy_name);
Ulf Hansson
AppliedRe: [PATCH 16/33] mmc: sdhci-xenon: use match_string() helper
In reply to Yisheng XieQuoted 8 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Adrian Hunter <[email protected]>Cc Hu Ziji <[email protected]>Cc Ulf Hansson <[email protected]>Signed-off-by Yisheng Xie <[email protected]>
Thanks, applied for next!
Kind regards
Uffe
Quoted 30 lines
--- drivers/mmc/host/sdhci-xenon-phy.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)drivers/mmc/host/sdhci-xenon-phy.c +3
-9@@ -814,15 +814,10 @@ static int xenon_add_phy(struct device_node *np, struct sdhci_host *host, {struct sdhci_pltfm_host *pltfm_host =sdhci_priv (host);struct xenon_priv *priv =sdhci_pltfm_priv (pltfm_host); -int i, ret; +int ret; -for (i =0 ; i <NR_PHY_TYPES ; i++) { -if (!strcmp (phy_name, phy_types[i])) { - priv->phy_type = i; -break ; - } - } -if (i ==NR_PHY_TYPES ) { + priv->phy_type =match_string (phy_types,NR_PHY_TYPES , phy_name); +if (priv->phy_type <0 ) {dev_err (mmc_dev (host->mmc),"Unable to determine PHY name %s. Use default eMMC 5.1 PHY\n" , phy_name); --1.7.12.4
PATCH 17/33 pinctrl: armada-37xx: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c +2 -14
@@ -214,18 +214,6 @@ static inline void armada_37xx_update_reg(unsigned int *reg, } } -static int armada_37xx_get_func_reg (struct armada_37xx_pin_group *grp, -const char *func) -{ -int f; - -for (f =0 ; (f <NB_FUNCS ) && grp->funcs[f]; f++) -if (!strcmp (grp->funcs[f], func)) -return f; - -return -ENOTSUPP ; -} -static struct armada_37xx_pin_group *armada_37xx_find_next_grp_by_pin (struct armada_37xx_pinctrl *info,int pin,int *grp) {
@@ -344,10 +332,10 @@ static int armada_37xx_pmx_set_by_name(struct pinctrl_dev *pctldev,dev_dbg (info->dev,"enable function %s group %s\n" , name, grp->name); - func =armada_37xx_get_func_reg (grp, name); + func =match_string (grp->funcs,NB_FUNCS , name);if (func <0 ) -return func; +return -ENOTSUPP ; val = grp->val[func];
Signature · 1 line
1.7.12.4
Re: [PATCH 17/33] pinctrl: armada-37xx: 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 intead of open coded variant.
https://patchwork.kernel.org/patch/10378781/
Quoted 7 lines
Cc Jason Cooper <[email protected]>Cc Andrew Lunn <[email protected]>Cc Gregory Clement <[email protected]>Cc Sebastian Hesselbarth <[email protected]>Cc Linus Walleij <[email protected]>Cc linux-arm-kernel at lists.infradead.orgCc linux-gpio at vger.kernel.org
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 18/33 power: supply: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/power/supply/power_supply_core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/power/supply/power_supply_core.c +6 -10
@@ -36,8 +36,6 @@static bool __power_supply_is_supplied_by (struct power_supply *supplier,struct power_supply *supply) { -int i; -if (!supply->supplied_from && !supplier->supplied_to)return false;
@@ -45,18 +43,16 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,if (supply->supplied_from) {if (!supplier->desc->name)return false; -for (i =0 ; i < supply->num_supplies; i++) -if (!strcmp (supplier->desc->name, supply->supplied_from[i])) -return true; +return match_string ((const char **)supply->supplied_from, + supply->num_supplies, + supplier->desc->name) >=0 ; }else {if (!supply->desc->name)return false; -for (i =0 ; i < supplier->num_supplicants; i++) -if (!strcmp (supplier->supplied_to[i], supply->desc->name)) -return true; +return match_string ((const char **)supplier->supplied_to, + supplier->num_supplicants, + supply->desc->name) >=0 ; } - -return false; }static int __power_supply_changed_work (struct device *dev,void *data)
Signature · 1 line
1.7.12.4
Re: [PATCH 18/33] power: supply: 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 intead of open coded variant.
This doesn't make code looks better anyhow. I even think it makes it worse to read.
That's why I dropped my version of the change (and yes, I missed the type conversion which looks here just ugly).
Sebastian, if my opinion makes any difference here, I would say NAK to this one.
Quoted 48 lines
Cc Sebastian Reichel <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- drivers/power/supply/power_supply_core.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/power/supply/power_supply_core.c +6
-11@@ -36,8 +36,6 @@static bool __power_supply_is_supplied_by (struct power_supply *supplier,struct power_supply *supply) { -int i; -if (!supply->supplied_from && !supplier->supplied_to)return false;@@ -45,18 +43,16 @@ static bool __power_supply_is_supplied_by(struct power_supply *supplier,if (supply->supplied_from) {if (!supplier->desc->name)return false; -for (i =0 ; i < supply->num_supplies; i++) -if (!strcmp (supplier->desc->name, supply->supplied_from[i])) -return true; +return match_string ((const char **)supply->supplied_from, + supply->num_supplies, + supplier->desc->name) >=0 ; }else {if (!supply->desc->name)return false; -for (i =0 ; i < supplier->num_supplicants; i++) -if (!strcmp (supplier->supplied_to[i], supply->desc->name)) -return true; +return match_string ((const char **)supplier->supplied_to, + supplier->num_supplicants, + supply->desc->name) >=0 ; } - -return false; }static int __power_supply_changed_work (struct device *dev,void *data) --1.7.12.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sebastian Reichel
maintainerRe: [PATCH 18/33] power: supply: use match_string() helper
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 3 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.This doesn't make code looks better anyhow. I even think it makes it worse to read. That's why I dropped my version of the change (and yes, I missed the type conversion which looks here just ugly).
Sebastian, if my opinion makes any difference here, I would say NAK to this one.
I agree.
-- Sebastian
PATCH 19/33 thermal: db8500: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/thermal/db8500_thermal.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/thermal/db8500_thermal.c +3 -5
@@ -50,12 +50,10 @@ static int db8500_thermal_match_cdev(struct thermal_cooling_device *cdev,if (!strlen (cdev->type))return -EINVAL ; -for (i =0 ; i <COOLING_DEV_MAX ; i++) { -if (!strcmp (trip_point->cdev_name[i], cdev->type)) -return 0 ; - } + i =match_string ((const char **)trip_point->cdev_name, +COOLING_DEV_MAX , cdev->type); -return -ENODEV ; +return (i <0 ) ? -ENODEV :0 ; }/* Callback to bind cooling device to thermal zone */
Signature · 1 line
1.7.12.4
Re: [PATCH 19/33] thermal: db8500: use match_string() helper
Quoted 4 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.+ i = match_string((const char **)trip_point->cdev_name,
Casting looks ugly. You need to constify the variable itself.
drivers/thermal/db8500_thermal.c static int db8500_thermal_match_cdev(struct thermal_cooling_device *cdev, · line 56
Quoted 4 lines
drivers/thermal/db8500_thermal.c +2
-1+ COOLING_DEV_MAX, cdev->type); -return -ENODEV ; +return (i <0 ) ? -ENODEV :0 ;
I would rather go with
if (ret < 0)
return -ENODEV;
return 0;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 19/33] thermal: db8500: use match_string() helper
Hi Andy,
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.+ i = match_string((const char **)trip_point->cdev_name,
Casting looks ugly. You need to constify the variable itself.
When I tried to const cdev_name like:
+++ b/include/linux/platform_data/db8500_thermal.h @@ -27,7 +27,7 @@
struct db8500_trip_point {
unsigned long temp;
enum thermal_trip_type type;- char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH];
+ char const cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; // const char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH] will also the same
};
The compiler will also warning:drivers/thermal/db8500_thermal.c: In function ‘db8500_thermal_match_cdev’:drivers/thermal/db8500_thermal.c:53:2: warning: passing argument 1 of ‘match_string’ from incompatible pointer type [enabled by default]
i = match_string(trip_point->cdev_name, COOLING_DEV_MAX, cdev->type);
^
In file included from include/linux/bitmap.h:9:0,
from include/linux/cpumask.h:12,
from include/linux/rcupdate.h:44,
from include/linux/radix-tree.h:28,
from include/linux/idr.h:15,
from include/linux/kernfs.h:14,
from include/linux/sysfs.h:16,
from kernel/include/linux/kobject.h:20,
from kernel/include/linux/of.h:17,
from include/linux/cpu_cooling.h:27,
from drivers/thermal/db8500_thermal.c:20:include/linux/string.h:184:5: note: expected ‘const char * const*’ but argument is of type ‘const char (*)[20]’
Any idea?
Thanks
Yisheng
Quoted 13 lines
drivers/thermal/db8500_thermal.c static int db8500_thermal_match_cdev(struct thermal_cooling_device *cdev, · line 56
Quoted 5 lines
drivers/thermal/db8500_thermal.c +2
-1+ COOLING_DEV_MAX, cdev->type); -return -ENODEV ; +return (i <0 ) ? -ENODEV :0 ;I would rather go with
if (ret < 0)
return-ENODEV;return 0;
Re: [PATCH 19/33] thermal: db8500: use match_string() helper
Quoted 36 lines · Yisheng Xie
Hi Andy,
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.+ i = match_string((const char **)trip_point->cdev_name,
Casting looks ugly. You need to constify the variable itself.
When I tried to const
cdev_namelike:
+++b/include/linux/platform_data/db8500_thermal.h(quoted diff) +1
-1@@ -27,7 +27,7 @@ struct db8500_trip_point { unsigned long temp; enum thermal_trip_type type; - char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; + char const cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH]; // const char cdev_name[COOLING_DEV_MAX][THERMAL_NAME_LENGTH] will also the same };The compiler will also warning:
drivers/thermal/db8500_thermal.c: In function ‘db8500_thermal_match_cdev’:drivers/thermal/db8500_thermal.c:53:2: warning: passing argument 1 of ‘match_string’ from incompatible pointer type [enabled by default]
i =match_string(trip_point->cdev_name, COOLING_DEV_MAX, cdev->type);
^
In file included frominclude/linux/bitmap.h:9:0,from include/linux/cpumask.h:12, from include/linux/rcupdate.h:44, from include/linux/radix-tree.h:28, from include/linux/idr.h:15, from include/linux/kernfs.h:14, from include/linux/sysfs.h:16, from kernel/include/linux/kobject.h:20, from kernel/include/linux/of.h:17, from include/linux/cpu_cooling.h:27, from drivers/thermal/db8500_thermal.c:20:
Quoted 3 lines
include/linux/string.h:184:5: note: expected ‘const char * const*’ but argument is of type ‘const char (*)[20]’Any idea?
Yes.
If you wish to continue, you need to do two patches instead, where in first you are changing fixed array size of pointers to dynamic one and replace or loops from being by size to ones being NULL terminated.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 20/33 video: fbdev: pxafb: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Arvind Yadav <[email protected]>
Cc: [email protected] [email protected]
--- drivers/video/fbdev/pxafb.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/video/fbdev/pxafb.c +2 -4
@@ -2115,10 +2115,8 @@ static int of_get_pxafb_display(struct device *dev, struct device_node *disp,if (ret) s ="color-tft" ; -for (i =0 ; lcd_types[i]; i++) -if (!strcmp (s, lcd_types[i])) -break ; -if (!i || !lcd_types[i]) { + i =match_string (lcd_types,-1 , s); +if (i <=0 ) {dev_err (dev,"lcd-type %s is unknown\n" , s);return -EINVAL ; }
Signature · 1 line
1.7.12.4
Re: [PATCH 20/33] video: fbdev: pxafb: 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 intead of open coded variant.
https://patchwork.kernel.org/patch/10378815/
Quoted 4 lines
Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Arvind Yadav <[email protected]>
Cc: [email protected] [email protected]
Signature · 6 lines
With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 21/33 drm/nouveau: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +5 -8
@@ -644,14 +644,11 @@ 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 ) + tv_enc->tv_norm = i; +else NV_WARN (drm,"Invalid TV norm setting \"%s\"\n" , nouveau_tv_norm); }
Signature · 1 line
1.7.12.4
Re: [PATCH 21/33] drm/nouveau: use match_string() helper
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c static int nv17_tv_create_resources(struct drm_encoder *encoder, · line 648
Quoted 7 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.if (nouveau_tv_norm) {drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +2
-0+ i =match_string (nv17_tv_norm_names, + num_tv_norms, nouveau_tv_norm);
Same comment for logical split, 2nd parameter looks better on the previous line.
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c static int nv17_tv_create_resources(struct drm_encoder *encoder, · line 653
Quoted 5 lines
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c +3
-0+if (i >=0 ) + tv_enc->tv_norm = i; +else NV_WARN (drm,"Invalid TV norm setting \"%s\"\n" , nouveau_tv_norm);
I would rather go with
if (i < 0)
NV_WARN
else
...
Quoted 1 line
}
Signature · 6 lines
With Best Regards, Andy Shevchenko _______________________________________________ Nouveau mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/nouveau
PATCH 22/33 drm/i915: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/gpu/drm/i915/intel_pipe_crc.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_pipe_crc.c +10 -12
@@ -764,13 +764,12 @@ enum intel_pipe_crc_object { {int i; -for (i =0 ; i <ARRAY_SIZE (pipe_crc_objects); i++) -if (!strcmp (buf, pipe_crc_objects[i])) { - *o = i; -return 0 ; - } + i =match_string (pipe_crc_objects,ARRAY_SIZE (pipe_crc_objects), buf); +if (i <0 ) +return -EINVAL ; -return -EINVAL ; + *o = i; +return 0 ; } static int display_crc_ctl_parse_pipe(struct drm_i915_private *dev_priv,
@@ -796,13 +795,12 @@ static int display_crc_ctl_parse_pipe(struct drm_i915_private *dev_priv,return 0 ; } -for (i =0 ; i <ARRAY_SIZE (pipe_crc_sources); i++) -if (!strcmp (buf, pipe_crc_sources[i])) { - *s = i; -return 0 ; - } + i =match_string (pipe_crc_sources,ARRAY_SIZE (pipe_crc_sources), buf); +if (i <0 ) +return -EINVAL ; -return -EINVAL ; + *s = i; +return 0 ; } static int display_crc_ctl_parse(struct drm_i915_private *dev_priv,
Signature · 1 line
1.7.12.4
Re: [PATCH 22/33] drm/i915: 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 intead of open coded variant.
https://patchwork.kernel.org/patch/10382323/
Quoted 6 lines
Cc Jani Nikula <[email protected]>Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc David Airlie <[email protected]>
Signature · 6 lines
With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Jani Nikula
maintainerRe: [PATCH 22/33] drm/i915: use match_string() helper
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.
Even more convincingly,
47d4cb8ae8e7 ("i915: Convert to use match_string() helper")
BR,
Jani.
Quoted 7 lines
Quoted 7 lines
Cc Jani Nikula <[email protected]>Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc David Airlie <[email protected]>
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center
Re: [PATCH 22/33] drm/i915: use match_string() helper
Hi Jani,
Quoted 10 lines · Jani Nikula
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Even more convincingly,
47d4cb8ae8e7("i915: Convert to usematch_string()helper")
Sorry, but I will definitely remove them in next version, I just miss these.
Thanks
Yisheng
Quoted 12 lines
BR,
Jani.Quoted 7 lines
Quoted 7 lines
Cc Jani Nikula <[email protected]>Cc Joonas Lahtinen <[email protected]>Cc Rodrigo Vivi <[email protected]>Cc David Airlie <[email protected]>
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 23/33 drm: i2c: ch7006: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/gpu/drm/i2c/ch7006_drv.c +5 -8
@@ -464,14 +464,11 @@ 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 ) + priv->norm = i; +else ch7006_err (client,"Invalid TV norm setting \"%s\".\n" , ch7006_tv_norm); }
Signature · 1 line
1.7.12.4
PATCH 24/33 drm: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- drivers/gpu/drm/drm_panel_orientation_quirks.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_panel_orientation_quirks.c +2 -5
@@ -136,7 +136,6 @@ int drm_get_panel_orientation_quirk(int width, int height)const struct dmi_system_id *match;const struct drm_dmi_panel_orientation_data *data;const char *bios_date; -int i; for (match = dmi_first_match(orientation_data); match;
@@ -154,10 +153,8 @@ int drm_get_panel_orientation_quirk(int width, int height)if (!bios_date)continue ; -for (i =0 ; data->bios_dates[i]; i++) { -if (!strcmp (data->bios_dates[i], bios_date)) -return data->orientation; - } +if (match_string (data->bios_dates,-1 , bios_date) >=0 ) +return data->orientation; }return DRM_MODE_PANEL_ORIENTATION_UNKNOWN ;
Signature · 1 line
1.7.12.4
Re: [PATCH 24/33] drm: 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 intead of open coded variant.
https://patchwork.kernel.org/patch/10382377/
Quoted 5 lines
Cc Gustavo Padovan <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Sean Paul <[email protected]>Cc David Airlie <[email protected]>
Signature · 6 lines
With Best Regards, Andy Shevchenko _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Jani Nikula
maintainerRe: [PATCH 24/33] drm: use match_string() helper
Quoted 5 lines · Andy Shevchenko
Quoted 2 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.
818c05d8e267 ("drm: panel-orientation-quirks: Convert to use match_string() helper")
BR,
Jani.
Quoted 6 lines
Quoted 6 lines
Cc Gustavo Padovan <[email protected]>Cc Maarten Lankhorst <[email protected]>Cc Sean Paul <[email protected]>Cc David Airlie <[email protected]>
Signature · 5 lines
Jani Nikula, Intel Open Source Graphics Center _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 25/33 ima: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- security/integrity/ima/ima_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
security/integrity/ima/ima_main.c +4 -7
@@ -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
Re: [PATCH 25/33] ima: use match_string() helper
Quoted 10 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead 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.orgCc linux-security-module at vger.kernel.orgSigned-off-by Yisheng Xie <[email protected]>
Quoted 17 lines
--- security/integrity/ima/ima_main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)security/integrity/ima/ima_main.c +0
-5@@ -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
PATCH 26/33 apparmor: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- security/apparmor/lsm.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)
security/apparmor/lsm.c +11 -14
@@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <AUDIT_MAX_INDEX ; i++) { -if (strcmp (val, audit_mode_names[i]) ==0 ) { - aa_g_audit = i; -return 0 ; - } - } + i =match_string (audit_mode_names,AUDIT_MAX_INDEX , val); +if (i <0 ) +return -EINVAL ; -return -EINVAL ; + aa_g_audit = i; +return 0 ; }static int param_get_mode (char *buffer,const struct kernel_param *kp)
@@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <APPARMOR_MODE_NAMES_MAX_INDEX ; i++) { -if (strcmp (val, aa_profile_mode_names[i]) ==0 ) { - aa_g_profile_mode = i; -return 0 ; - } - } + i =match_string (aa_profile_mode_names, +APPARMOR_MODE_NAMES_MAX_INDEX , val); +if (i) +return -EINVAL ; -return -EINVAL ; + aa_g_profile_mode = i; +return 0 ; }/*
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
John Johansen
maintainerRe: [PATCH 26/33] apparmor: 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 intead of open coded variant.
Andy Shevchenko patch to do the same thing is already in apparmor-next
Quoted 45 lines
Cc John Johansen <[email protected]>Cc James Morris <[email protected]>Cc "Serge E. Hallyn" <[email protected]>Cc linux-security-module at vger.kernel.orgSigned-off-by Yisheng Xie <[email protected]>--- security/apparmor/lsm.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)security/apparmor/lsm.c +6
-13@@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <AUDIT_MAX_INDEX ; i++) { -if (strcmp (val, audit_mode_names[i]) ==0 ) { - aa_g_audit = i; -return 0 ; - } - } + i =match_string (audit_mode_names,AUDIT_MAX_INDEX , val); +if (i <0 ) +return -EINVAL ; -return -EINVAL ; + aa_g_audit = i; +return 0 ; }static int param_get_mode (char *buffer,const struct kernel_param *kp)@@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <APPARMOR_MODE_NAMES_MAX_INDEX ; i++) { -if (strcmp (val, aa_profile_mode_names[i]) ==0 ) { - aa_g_profile_mode = i; -return 0 ; - } - } + i = match_string(aa_profile_mode_names,
security/apparmor/lsm.c static int param_set_mode(const char *val, const struct kernel_param *kp) · line 1419
Quoted 10 lines
security/apparmor/lsm.c +5
-1+ APPARMOR_MODE_NAMES_MAX_INDEX, val); +if (i) +return -EINVAL ; -return -EINVAL ; + aa_g_profile_mode = i; +return 0 ; }/*
--
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
Re: [PATCH 26/33] apparmor: use match_string() helper
Hi John,
Quoted 6 lines · John Johansen
Quoted 3 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Andy Shevchenko patch to do the same thing is already in apparmor-next
Sorry, I will drop this one.
Thanks
Yisheng
Quoted 49 lines
Quoted 49 lines
Cc John Johansen <[email protected]>Cc James Morris <[email protected]>Cc "Serge E. Hallyn" <[email protected]>Cc linux-security-module at vger.kernel.orgSigned-off-by Yisheng Xie <[email protected]>--- security/apparmor/lsm.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-)security/apparmor/lsm.c +9
-13@@ -1378,14 +1378,12 @@ static int param_set_audit(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <AUDIT_MAX_INDEX ; i++) { -if (strcmp (val, audit_mode_names[i]) ==0 ) { - aa_g_audit = i; -return 0 ; - } - } + i =match_string (audit_mode_names,AUDIT_MAX_INDEX , val); +if (i <0 ) +return -EINVAL ; -return -EINVAL ; + aa_g_audit = i; +return 0 ; }static int param_get_mode (char *buffer,const struct kernel_param *kp)@@ -1409,14 +1407,13 @@ static int param_set_mode(const char *val, const struct kernel_param *kp)if (apparmor_initialized && !policy_admin_capable (NULL ))return -EPERM ; -for (i =0 ; i <APPARMOR_MODE_NAMES_MAX_INDEX ; i++) { -if (strcmp (val, aa_profile_mode_names[i]) ==0 ) { - aa_g_profile_mode = i; -return 0 ; - } - } + i =match_string (aa_profile_mode_names, +APPARMOR_MODE_NAMES_MAX_INDEX , val); +if (i) +return -EINVAL ;
Quoted 10 lines
security/apparmor/lsm.c static int param_set_mode(const char *val, const struct kernel_param *kp) · line 1419
Quoted 7 lines
security/apparmor/lsm.c +2
-1-return -EINVAL ; + aa_g_profile_mode = i; +return 0 ; }/*
--
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
Re: [PATCH 26/33] apparmor: use match_string() helper
In reply to Yisheng XieQuoted 2 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.
http://kernsec.org/pipermail/linux-security-module-archi
Quoted 4 lines
Cc John Johansen <[email protected]>Cc James Morris <[email protected]>Cc "Serge E. Hallyn" <[email protected]>Cc linux-security-module at vger.kernel.org
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
PATCH 27/33 sched/debug: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- kernel/sched/debug.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)
kernel/sched/debug.c +9 -11
@@ -111,16 +111,14 @@ 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 ) { +if (neg) { + sysctl_sched_features &= ~(1UL << i); +sched_feat_disable (i); + }else { + sysctl_sched_features |= (1UL << i); +sched_feat_enable (i); } }
@@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)inode_lock (inode); i =sched_feat_set (cmp);inode_unlock (inode); -if (i == __SCHED_FEAT_NR) +if (i <0 )return -EINVAL ; *ppos += cnt;
Signature · 1 line
1.7.12.4
Re: [PATCH 27/33] sched/debug: use match_string() helper
Quoted 21 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- kernel/sched/debug.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)kernel/sched/debug.c +0
-3@@ -111,16 +111,14 @@ 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) {
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 116
Quoted 10 lines
kernel/sched/debug.c +2
-7- 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 ) {
Why not
if (i < 0)
return i;
?
Quoted 10 lines
kernel/sched/debug.c +6
-0+if (neg) { + sysctl_sched_features &= ~(1UL << i); +sched_feat_disable (i); + }else { + sysctl_sched_features |= (1UL << i); +sched_feat_enable (i); } }
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 153
Quoted 7 lines
kernel/sched/debug.c +1
-1@@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)inode_lock (inode); i =sched_feat_set (cmp);inode_unlock (inode); -if (i == __SCHED_FEAT_NR) +if (i <0 )return -EINVAL ;
Now it would be
if (i < 0)
return i;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 27/33] sched/debug: use match_string() helper
Hi Andy,
Quoted 31 lines · Andy Shevchenko
Quoted 29 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- kernel/sched/debug.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-)kernel/sched/debug.c +1
-10@@ -111,16 +111,14 @@ 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);
Quoted 6 lines
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 115
Quoted 1 line
kernel/sched/debug.c +1
-0+if (i >=0 ) {Why not
if (i < 0)
return i;
if i >=0 it will also return i. so need return i just if (i < 0), right ?
Quoted 17 lines
?
Quoted 13 lines
kernel/sched/debug.c +6
-0+if (neg) { + sysctl_sched_features &= ~(1UL << i); +sched_feat_disable (i); + }else { + sysctl_sched_features |= (1UL << i); +sched_feat_enable (i); } }@@ -150,7 +148,7 @@ static int sched_feat_set(char *cmp)inode_lock (inode); i =sched_feat_set (cmp);inode_unlock (inode);
Quoted 8 lines
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 152
Quoted 3 lines
kernel/sched/debug.c +1
-1-if (i == __SCHED_FEAT_NR) +if (i <0 )return -EINVAL ;Now it would be
if (i < 0)
return i;
Right, will change it in next version
Thanks
Yisheng Xie
Quoted 1 line
Re: [PATCH 27/33] sched/debug: use match_string() helper
Quoted 9 lines · Yisheng Xie
Quoted 7 lines
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 115
Quoted 2 lines
kernel/sched/debug.c +2
-0+ i =match_string (sched_feat_names, __SCHED_FEAT_NR, cmp); +if (i >=0 ) {Why not
if (i < 0)
return i;if i >=0 it will also return i. so need return i just if (i < 0), right ?
Looking to the only (modified) caller, I think yes, either you return error code or just 0.
Quoted 8 lines
Quoted 8 lines
kernel/sched/debug.c static int sched_feat_set(char *cmp) · line 152
Quoted 3 lines
kernel/sched/debug.c +1
-1-if (i == __SCHED_FEAT_NR) +if (i <0 )return -EINVAL ;Now it would be
if (i < 0)
...even if (i) and rename i to ret to show the change in returned value meaning.
Quoted 3 lines
Quoted 1 line
return i;
Right, will change it in next version
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 28/33 ALSA: dice use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/firewire/dice/dice.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
sound/firewire/dice/dice.c +1 -7
@@ -35,19 +35,13 @@ static bool force_two_pcm_support(struct fw_unit *unit) "SAFFIRE_PRO_40_1", };char model[32 ]; -unsigned int i;int err; err =fw_csr_string (unit->directory,CSR_MODEL , model,sizeof (model));if (err <0 )return false; -for (i =0 ; i <ARRAY_SIZE (models); i++) { -if (strcmp (models[i], model) ==0 ) -break ; - } - -return i <ARRAY_SIZE (models); +return match_string (models,ARRAY_SIZE (models), model) >=0 ; }static int check_dice_category (struct fw_unit *unit)
Signature · 1 line
1.7.12.4
Takashi Sakamoto
maintainerRe: [PATCH 28/33] ALSA: dice use match_string() helper
Hi,
Quoted 9 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Clemens Ladisch <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Cc Takashi Sakamoto <[email protected]>Signed-off-by Yisheng Xie <[email protected]>
Quoted 3 lines
--- sound/firewire/dice/dice.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
I'm welcome to this change, while in the latest subsystem tree for v4.18 the 'force_to_pcm_support()' local function was removed by my patch[1]. Your patch can be abandon.
Quoted 15 lines
sound/firewire/dice/dice.c +0
-1@@ -35,19 +35,13 @@ static bool force_two_pcm_support(struct fw_unit *unit) "SAFFIRE_PRO_40_1", };char model[32 ]; -unsigned int i;int err; err =fw_csr_string (unit->directory,CSR_MODEL , model,sizeof (model));if (err <0 )return false;
sound/firewire/dice/dice.c static bool force_two_pcm_support(struct fw_unit *unit) · line 47
Quoted 10 lines
sound/firewire/dice/dice.c +1
-6-for (i =0 ; i <ARRAY_SIZE (models); i++) { -if (strcmp (models[i], model) ==0 ) -break ; - } - -return i <ARRAY_SIZE (models); +return match_string (models,ARRAY_SIZE (models), model) >=0 ; }static int check_dice_category (struct fw_unit *unit)
[1] ALSA: dice: remove local frag of force_two_pcms
https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/commit/?h=for-next&id=9c367c01d3d5
Thanks
Takashi Sakamoto
PATCH 29/33 ALSA: oxfw: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/firewire/oxfw/oxfw.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
sound/firewire/oxfw/oxfw.c +1 -7
@@ -49,7 +49,6 @@ static bool detect_loud_models(struct fw_unit *unit)"Tapco LINK.firewire 4x6" , "U.420"};char model[32 ]; -unsigned int i;int err; err = fw_csr_string(unit->directory, CSR_MODEL,
@@ -57,12 +56,7 @@ static bool detect_loud_models(struct fw_unit *unit)if (err <0 )return false; -for (i =0 ; i <ARRAY_SIZE (models); i++) { -if (strcmp (models[i], model) ==0 ) -break ; - } - -return (i <ARRAY_SIZE (models)); +return match_string (models,ARRAY_SIZE (models), model) >=0 ; }static int name_card (struct snd_oxfw *oxfw)
Signature · 1 line
1.7.12.4
Re: [alsa-devel] [PATCH 29/33] ALSA: oxfw: use match_string() helper
Hi,
Quoted 11 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Clemens Ladisch <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- sound/firewire/oxfw/oxfw.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
For my information, use_match_string() helper was firstly introduced to v4.6 kernel by a commit 56b060814e2d ('lib/string: introduce match_string() helper').
Quoted 16 lines
sound/firewire/oxfw/oxfw.c +0
-1@@ -49,7 +49,6 @@ static bool detect_loud_models(struct fw_unit *unit)"Tapco LINK.firewire 4x6" , "U.420"};char model[32 ]; -unsigned int i;int err; err = fw_csr_string(unit->directory, CSR_MODEL,@@ -57,12 +56,7 @@ static bool detect_loud_models(struct fw_unit *unit)if (err <0 )return false;
sound/firewire/oxfw/oxfw.c static bool detect_loud_models(struct fw_unit *unit) · line 62
Quoted 10 lines
sound/firewire/oxfw/oxfw.c +1
-6-for (i =0 ; i <ARRAY_SIZE (models); i++) { -if (strcmp (models[i], model) ==0 ) -break ; - } - -return (i <ARRAY_SIZE (models)); +return match_string (models,ARRAY_SIZE (models), model) >=0 ; }static int name_card (struct snd_oxfw *oxfw)
Thanks
Takashi Sakamoto
Re: [alsa-devel] [PATCH 29/33] ALSA: oxfw: use match_string() helper
Quoted 16 lines · Takashi Sakamoto
Hi,
Quoted 11 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Clemens Ladisch <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- sound/firewire/oxfw/oxfw.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
Quoted 5 lines
Reviewed-by Takashi Sakamoto <[email protected]>For my information,
use_match_string()helper was firstly introduced to v4.6 kernel by a commit56b060814e2d('lib/string: introducematch_string()helper').
OK, applied now. Thanks.
Takashi
PATCH 30/33 ALSA: oxygen: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/pci/oxygen/oxygen_mixer.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
sound/pci/oxygen/oxygen_mixer.c +6 -7
@@ -1052,10 +1052,9 @@ 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;struct snd_kcontrol_new template;struct snd_kcontrol *ctl; -int err; +int i, j, err;for (i =0 ; i < count; ++i) { template = controls[i];
@@ -1086,11 +1085,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
Re: [PATCH 30/33] ALSA: oxygen: use match_string() helper
Quoted 17 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.Cc Clemens Ladisch <[email protected]>Cc Jaroslav Kysela <[email protected]>Cc Takashi Iwai <[email protected]>Signed-off-by Yisheng Xie <[email protected]>--- sound/pci/oxygen/oxygen_mixer.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)sound/pci/oxygen/oxygen_mixer.c +0
-0
sound/pci/oxygen/oxygen_mixer.c static int add_controls(struct oxygen *chip, · line 1057
Quoted 8 lines
sound/pci/oxygen/oxygen_mixer.c +1
-2@@ -1052,10 +1052,9 @@ 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;struct snd_kcontrol_new template;struct snd_kcontrol *ctl; -int err; +int i, j, err;
What's wrong with
unsigned int i;
?
Quoted 23 lines
sound/pci/oxygen/oxygen_mixer.c +5
-6for (i =0 ; i < count; ++i) { template = controls[i];@@ -1086,11 +1085,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 ; } --1.7.12.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 31/33 ASoC: max98088: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/soc/codecs/max98088.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
sound/soc/codecs/max98088.c +3 -6
@@ -1382,14 +1382,11 @@ 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; - -for (i =0 ; i <ARRAY_SIZE (eq_mode_name); i++) -if (strcmp (name, eq_mode_name[i]) ==0 ) -return i; +int ret =match_string (eq_mode_name,ARRAY_SIZE (eq_mode_name), name);/* Shouldn't happen */ -dev_err (component->dev,"Bad EQ channel name '%s'\n" , name); +if (ret <0 ) +dev_err (component->dev,"Bad EQ channel name '%s'\n" , name);return -EINVAL ; }
Signature · 1 line
1.7.12.4
Re: [PATCH 31/33] ASoC: max98088: 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 intead of open coded variant.static int
max98088_get_channel(struct snd_soc_component *component, const char *name){+ int ret =
match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
I would rather split this and move an assignment to the line before 'if'
sound/soc/codecs/max98088.c static int max98088_set_bias_level(struct snd_soc_component *component,
Quoted 7 lines
/* Shouldn't happen */sound/soc/codecs/max98088.c +2
-0+if (ret <0 ) +dev_err (component->dev,"Bad EQ channel name '%s'\n" , name);return -EINVAL ;
return ret;
?
Quoted 5 lines
}
--
1.7.12.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 31/33] ASoC: max98088: use match_string() helper
Hi Andy,
Quoted 9 lines · Andy Shevchenko
Quoted 7 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.static int
max98088_get_channel(struct snd_soc_component *component, const char *name){+ int ret =
match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);I would rather split this and move an assignment to the line before 'if'
hmm, you mean something like:
int ret; ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name); if (ret < 0) /* Shouldn't happen */ dev_err(component->dev, "Bad EQ channel name '%s'\n", name); return ret;
Quoted 9 lines
sound/soc/codecs/max98088.c static int max98088_set_bias_level(struct snd_soc_component *component,
Quoted 7 lines
/* Shouldn't happen */sound/soc/codecs/max98088.c +2
-0+if (ret <0 ) +dev_err (component->dev,"Bad EQ channel name '%s'\n" , name);return -EINVAL ;return ret;
Right, sorry for this big mistake.
Thanks
Yisheng
Quoted 11 lines
?
Quoted 5 lines
}
--
1.7.12.4
Re: [PATCH 31/33] ASoC: max98088: use match_string() helper
Quoted 8 lines · Yisheng Xie
hmm, you mean something like:
int ret; ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name); if (ret < 0) /* Shouldn't happen */ dev_err(component->dev, "Bad EQ channel name '%s'\n", name); return ret;
Yes. (But remove that useless comment).
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 32/33 ASoC: max98095: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/soc/codecs/max98095.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
sound/soc/codecs/max98095.c +4 -7
@@ -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 =match_string (bq_mode_name,ARRAY_SIZE (bq_mode_name), name);/* Shouldn't happen */ -dev_err (component->dev,"Bad biquad channel name '%s'\n" , name); -return -EINVAL ; +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
Re: [PATCH 32/33] ASoC: max98095: use match_string() helper
Quoted 5 lines · Yisheng Xie
match_string()returns the index of an array for a matching string, which can be used intead of open coded variant.+ int ret =
match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);
Rather split and move an assignment to the line before 'if'.
Quoted 7 lines
/* Shouldn't happen */sound/soc/codecs/max98095.c +3
-0+if (ret <0 ) +dev_err (component->dev,"Bad biquad channel name '%s'\n" , name); +return ret; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 33/33 ASoC: dapm: use match_string() helper
In reply to Yisheng Xiematch_string() returns the index of an array for a matching string, which can be used intead of open coded variant.
--- sound/soc/soc-dapm.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
sound/soc/soc-dapm.c +7 -11
@@ -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
Mark Brown
maintainerApplied "ASoC: dapm: use match_string() helper" to the asoc tree
The patch
ASoC: dapm: 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
f9e0b4afd4e9b19e95158962d81b5b776d57ca06Mon Sep 17 00:00:00 2001
From: Xie Yisheng <[email protected]>
Date: Thu, 31 May 2018 19:11:23 +0800
Subject: [PATCH] ASoC: dapm: 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.
--- sound/soc/soc-dapm.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
sound/soc/soc-dapm.c +7 -11
@@ -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
2.17.0
Quoted 3 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 intead of open coded variant.
You forgot to Cc that Andy.
For the patches I didn't comment, LGTM
Quoted 76 lines
I just try to make this API be used more commonly, sorry if this makes too much big patchset.
Yisheng Xie (33):
usb: phy: usematch_string()helper
mfd: omap-usb-host: usematch_string()helper
Staging: gdm724x: usematch_string()helper
gpiolib-of: usematch_string()helper
cxgb4: usematch_string()helper
hp100: usematch_string()helper
iwlwifi: mvm: usematch_string()helper
vfio: usematch_string()helper
phy: tegra: usematch_string()helper
pata_hpt37x: usematch_string()helper
bus: fsl-mc: usematch_string()helper
clk: bcm2835: usematch_string()helper
clk: rockchip: usematch_string()helper
clk: usematch_string()helper
cpufreq:intel_pstate: usematch_string()helper
mmc: sdhci-xenon: usematch_string()helper
pinctrl: armada-37xx: usematch_string()helper
power: supply: usematch_string()helper
thermal: db8500: usematch_string()helper
video: fbdev: pxafb: usematch_string()helper drm/nouveau: usematch_string()helper drm/i915: usematch_string()helper
drm: i2c: ch7006: usematch_string()helper
drm: usematch_string()helper
ima: usematch_string()helper
apparmor: usematch_string()helper sched/debug: usematch_string()helper
ALSA: dice usematch_string()helper
ALSA: oxfw: usematch_string()helper
ALSA: oxygen: usematch_string()helper
ASoC: max98088: usematch_string()helper
ASoC: max98095: usematch_string()helper
ASoC: dapm: usematch_string()helperdrivers/ata/pata_hpt37x.c | 13 +++++------- drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +++++------------------ drivers/clk/bcm/clk-bcm2835.c | 14 ++++++------- drivers/clk/clk.c | 8 ++------ drivers/clk/rockchip/clk.c | 16 +++++---------- drivers/cpufreq/intel_pstate.c | 15 ++++++-------- drivers/gpio/gpiolib-of.c | 7 +------ drivers/gpu/drm/drm_panel_orientation_quirks.c | 7 ++----- drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++------- drivers/gpu/drm/i915/intel_pipe_crc.c | 22 ++++++++++----------- drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++------- drivers/mfd/omap-usb-host.c | 24 ++--------------------- drivers/mmc/host/sdhci-xenon-phy.c | 11 +++-------- drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++--------- drivers/net/ethernet/hp/hp100.c | 9 +-------- drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c | 11 +++-------- drivers/phy/tegra/xusb.c | 15 +------------- drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++------------- drivers/power/supply/power_supply_core.c | 16 ++++++--------- drivers/staging/gdm724x/gdm_tty.c | 16 ++++----------- drivers/thermal/db8500_thermal.c | 8 +++----- drivers/usb/phy/of.c | 12 +++++------- drivers/vfio/vfio.c | 11 +++-------- drivers/video/fbdev/pxafb.c | 6 ++---- kernel/sched/debug.c | 20 +++++++++---------- security/apparmor/lsm.c | 25 +++++++++++------------- security/integrity/ima/ima_main.c | 11 ++++------- sound/firewire/dice/dice.c | 8 +------- sound/firewire/oxfw/oxfw.c | 8 +------- sound/pci/oxygen/oxygen_mixer.c | 13 ++++++------ sound/soc/codecs/max98088.c | 9 +++------ sound/soc/codecs/max98095.c | 11 ++++------- sound/soc/soc-dapm.c | 18 +++++++---------- 33 files changed, 137 insertions(+), 307 deletions(-)--
1.7.12.4
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi Andy,
Quoted 6 lines · Andy Shevchenko
Quoted 3 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 intead of open coded variant.You forgot to Cc that Andy.
Yeah, I just forgot it when send them out.
Quoted 4 lines
For the patches I didn't comment, LGTM
Reviewed-by Andy Shevchenko <[email protected]>
Thanks, and I will drop the ones you already sent out, and make a v2 as your comment!
Thanks
Yisheng