2018-05-21 12:18:13

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 00/33] 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(-)

--
1.7.12.4



2018-05-21 12:10:36

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 30/33] ALSA: oxygen: 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.

Cc: Clemens Ladisch <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/pci/oxygen/oxygen_mixer.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 4ca1266..fbd8f5e 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -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;
}
--
1.7.12.4


2018-05-21 12:10:51

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 25/33] ima: 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.

Cc: Mimi Zohar <[email protected]>
Cc: Dmitry Kasatkin <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
security/integrity/ima/ima_main.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 74d0bd7..f807093 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -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;
--
1.7.12.4


2018-05-21 12:11:06

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 29/33] ALSA: oxfw: 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.

Cc: Clemens Ladisch <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/firewire/oxfw/oxfw.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
index 413ab63..1e5b2c8 100644
--- a/sound/firewire/oxfw/oxfw.c
+++ b/sound/firewire/oxfw/oxfw.c
@@ -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)
--
1.7.12.4


2018-05-21 12:11:21

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 33/33] ASoC: dapm: 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.

Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/soc/soc-dapm.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2d97091..1e9a363 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -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 */
--
1.7.12.4


2018-05-21 12:11:27

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 26/33] apparmor: 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.

Cc: John Johansen <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
security/apparmor/lsm.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index ce2b89e..9b5904f 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -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;
}

/*
--
1.7.12.4


2018-05-21 12:11:37

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 24/33] drm: 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.

Cc: Gustavo Padovan <[email protected]>
Cc: Maarten Lankhorst <[email protected]>
Cc: Sean Paul <[email protected]>
Cc: David Airlie <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/gpu/drm/drm_panel_orientation_quirks.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_panel_orientation_quirks.c b/drivers/gpu/drm/drm_panel_orientation_quirks.c
index 902cc1a..3367c36 100644
--- a/drivers/gpu/drm/drm_panel_orientation_quirks.c
+++ b/drivers/gpu/drm/drm_panel_orientation_quirks.c
@@ -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;
--
1.7.12.4


2018-05-21 12:11:57

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 28/33] ALSA: dice 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.

Cc: Clemens Ladisch <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Takashi Sakamoto <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/firewire/dice/dice.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c
index 96bb01b..0639074 100644
--- a/sound/firewire/dice/dice.c
+++ b/sound/firewire/dice/dice.c
@@ -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)
--
1.7.12.4


2018-05-21 12:12:52

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 15/33] cpufreq: intel_pstate: 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.

Cc: Srinivas Pandruvada <[email protected]>
Cc: Len Brown <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Viresh Kumar <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/cpufreq/intel_pstate.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 17e566af..d701e26 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -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(
--
1.7.12.4


2018-05-21 12:12:53

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 02/33] mfd: omap-usb-host: 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.

Cc: Tony Lindgren <[email protected]>
Cc: Lee Jones <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/mfd/omap-usb-host.c | 24 ++----------------------
1 file changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/mfd/omap-usb-host.c b/drivers/mfd/omap-usb-host.c
index 7aab376..e11ab12 100644
--- a/drivers/mfd/omap-usb-host.c
+++ b/drivers/mfd/omap-usb-host.c
@@ -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);
--
1.7.12.4


2018-05-21 12:13:23

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 32/33] ASoC: max98095: 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.

Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/soc/codecs/max98095.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/sound/soc/codecs/max98095.c b/sound/soc/codecs/max98095.c
index 6bf2d0b..0ef42dc 100644
--- a/sound/soc/codecs/max98095.c
+++ b/sound/soc/codecs/max98095.c
@@ -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,
--
1.7.12.4


2018-05-21 12:13:39

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 23/33] drm: i2c: ch7006: 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.

Cc: David Airlie <[email protected]>
Cc: Yisheng Xie <[email protected]>
Cc: Daniel Vetter <[email protected]>
Cc: Arvind Yadav <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/gpu/drm/i2c/ch7006_drv.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 544a8a2..405c7fb 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -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);
}
--
1.7.12.4


2018-05-21 12:13:51

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 31/33] ASoC: max98088: 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.

Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
sound/soc/codecs/max98088.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 865f64c..7383f90 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -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;
}

--
1.7.12.4


2018-05-21 12:14:27

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 18/33] power: supply: 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.

Cc: Sebastian Reichel <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/power/supply/power_supply_core.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index feac7b0..84da3a2 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -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


2018-05-21 12:14:31

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 27/33] sched/debug: 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.

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(-)

diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 15b10e2..9e34499 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -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;
--
1.7.12.4


2018-05-21 12:14:31

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 22/33] drm/i915: 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.

Cc: Jani Nikula <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Rodrigo Vivi <[email protected]>
Cc: David Airlie <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/gpu/drm/i915/intel_pipe_crc.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_pipe_crc.c b/drivers/gpu/drm/i915/intel_pipe_crc.c
index 1f5cd57..f6b1335 100644
--- a/drivers/gpu/drm/i915/intel_pipe_crc.c
+++ b/drivers/gpu/drm/i915/intel_pipe_crc.c
@@ -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,
--
1.7.12.4


2018-05-21 12:14:40

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 19/33] thermal: db8500: 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.

Cc: Zhang Rui <[email protected]>
Cc: Eduardo Valentin <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/thermal/db8500_thermal.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/db8500_thermal.c b/drivers/thermal/db8500_thermal.c
index f491faf..dd83614 100644
--- a/drivers/thermal/db8500_thermal.c
+++ b/drivers/thermal/db8500_thermal.c
@@ -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 */
--
1.7.12.4


2018-05-21 12:14:59

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 21/33] drm/nouveau: 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.

Cc: Ben Skeggs <[email protected]>
Cc: David Airlie <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
index 6d99f11..a6b4c4a 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
@@ -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);
}
--
1.7.12.4


2018-05-21 12:15:00

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 03/33] Staging: gdm724x: 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.

Cc: Greg Kroah-Hartman <[email protected]>
Cc: Quytelda Kahja <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/staging/gdm724x/gdm_tty.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index 3cdebb8..ba53a06 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -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;
--
1.7.12.4


2018-05-21 12:15:24

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 20/33] video: fbdev: pxafb: 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.

Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Arvind Yadav <[email protected]>
Cc: [email protected]
[email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/video/fbdev/pxafb.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/video/fbdev/pxafb.c b/drivers/video/fbdev/pxafb.c
index c3d49e1..702193d 100644
--- a/drivers/video/fbdev/pxafb.c
+++ b/drivers/video/fbdev/pxafb.c
@@ -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;
}
--
1.7.12.4


2018-05-21 12:15:44

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 06/33] hp100: 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.

Cc: Jaroslav Kysela <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/net/ethernet/hp/hp100.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/hp/hp100.c b/drivers/net/ethernet/hp/hp100.c
index c8c7ad2..84501b3 100644
--- a/drivers/net/ethernet/hp/hp100.c
+++ b/drivers/net/ethernet/hp/hp100.c
@@ -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;
--
1.7.12.4


2018-05-21 12:15:51

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 08/33] vfio: 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.

Cc: Alex Williamson <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/vfio/vfio.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 721f97f..6483387 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -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;
}

/*
--
1.7.12.4


2018-05-21 12:16:22

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 04/33] gpiolib-of: 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.

Cc: Linus Walleij <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/gpio/gpiolib-of.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 586d151..9cbc898 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -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);
--
1.7.12.4


2018-05-21 12:16:40

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 05/33] cxgb4: 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.

Cc: Ganesh Goudar <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c | 14 ++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
index 9da6f57..bd61610 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
@@ -782,17 +782,11 @@ static int cudbg_get_mem_region(struct adapter *padap,
if (rc)
return rc;

- for (i = 0; i < ARRAY_SIZE(cudbg_region); i++) {
- if (!strcmp(cudbg_region[i], region_name)) {
- found = 1;
- idx = i;
- break;
- }
- }
- if (!found)
- return -EINVAL;
+ rc = match_string(cudbg_region, ARRAY_SIZE(cudbg_region), region_name);
+ if (rc < 0)
+ return rc;

- found = 0;
+ idx = rc;
for (i = 0; i < meminfo->mem_c; i++) {
if (meminfo->mem[i].idx >= ARRAY_SIZE(cudbg_region))
continue; /* Skip holes */
--
1.7.12.4


2018-05-21 12:16:42

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 10/33] pata_hpt37x: 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.

Cc: Bartlomiej Zolnierkiewicz <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/ata/pata_hpt37x.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 3ba843f..ef8aaeb 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -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;
}
--
1.7.12.4


2018-05-21 12:16:54

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 17/33] pinctrl: armada-37xx: 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.

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: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/pinctrl/mvebu/pinctrl-armada-37xx.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
index 5b63248..e338327 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-37xx.c
@@ -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];

--
1.7.12.4


2018-05-21 12:17:15

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 09/33] phy: tegra: 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.

Cc: Kishon Vijay Abraham I <[email protected]>
Cc: Thierry Reding <[email protected]>
Cc: Jonathan Hunter <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/phy/tegra/xusb.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index 11aa590..de1b4eb 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -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);
--
1.7.12.4


2018-05-21 12:17:18

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 13/33] clk: rockchip: 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.

Cc: Michael Turquette <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/clk/rockchip/clk.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 3cd8ad5..514032d 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -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",
--
1.7.12.4


2018-05-21 12:17:21

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 14/33] clk: 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.

Cc: Michael Turquette <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/clk/clk.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 7af555f..4469eca 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -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);

--
1.7.12.4


2018-05-21 12:17:33

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 12/33] clk: bcm2835: 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.

Cc: Michael Turquette <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Eric Anholt <[email protected]>
Cc: Stefan Wahren <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/clk/bcm/clk-bcm2835.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
index fa0d5c8..a27c0d2 100644
--- a/drivers/clk/bcm/clk-bcm2835.c
+++ b/drivers/clk/bcm/clk-bcm2835.c
@@ -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));
--
1.7.12.4


2018-05-21 12:17:42

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 11/33] bus: fsl-mc: 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.

Cc: Stuart Yoder <[email protected]>
Cc: Laurentiu Tudor <[email protected]>
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/bus/fsl-mc/fsl-mc-allocator.c | 24 +++++-------------------
1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index fb1442b..63c4735 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -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)
--
1.7.12.4


2018-05-21 12:18:01

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 16/33] mmc: sdhci-xenon: 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.

Cc: Adrian Hunter <[email protected]>
Cc: Hu Ziji <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/mmc/host/sdhci-xenon-phy.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c
index ec87943..a35804b 100644
--- a/drivers/mmc/host/sdhci-xenon-phy.c
+++ b/drivers/mmc/host/sdhci-xenon-phy.c
@@ -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


2018-05-21 12:18:26

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 07/33] iwlwifi: mvm: 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.

Cc: Kalle Valo <[email protected]>
Cc: Intel Linux Wireless <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Emmanuel Grumbach <[email protected]>
Cc: [email protected]
Cc: [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(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
index 0e6401c..e8249a6 100644
--- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
+++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
@@ -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;
--
1.7.12.4


2018-05-21 12:19:04

by Yisheng Xie

[permalink] [raw]
Subject: [PATCH 01/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.

Cc: [email protected]
Cc: Felipe Balbi <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Yisheng Xie <[email protected]>
---
drivers/usb/phy/of.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/phy/of.c b/drivers/usb/phy/of.c
index 1ab134f..5777c9f 100644
--- a/drivers/usb/phy/of.c
+++ b/drivers/usb/phy/of.c
@@ -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);
--
1.7.12.4


2018-05-21 15:34:30

by John Johansen

[permalink] [raw]
Subject: Re: [PATCH 26/33] apparmor: use match_string() helper

On 05/21/2018 04:58 AM, Yisheng Xie wrote:
> 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

> Cc: John Johansen <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: "Serge E. Hallyn" <[email protected]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> security/apparmor/lsm.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
> index ce2b89e..9b5904f 100644
> --- a/security/apparmor/lsm.c
> +++ b/security/apparmor/lsm.c
> @@ -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;
> }
>
> /*
>


2018-05-21 17:44:17

by Tony Lindgren

[permalink] [raw]
Subject: Re: [PATCH 02/33] mfd: omap-usb-host: use match_string() helper

* Yisheng Xie <[email protected]> [180521 12:11]:
> 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:

Acked-by: Tony Lindgren <[email protected]>

2018-05-21 17:50:35

by Eric Anholt

[permalink] [raw]
Subject: Re: [PATCH 12/33] clk: bcm2835: use match_string() helper

Yisheng Xie <[email protected]> writes:

> 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: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> drivers/clk/bcm/clk-bcm2835.c | 14 ++++++--------
> 1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
> index fa0d5c8..a27c0d2 100644
> --- a/drivers/clk/bcm/clk-bcm2835.c
> +++ b/drivers/clk/bcm/clk-bcm2835.c
> @@ -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];

Reviewed-by: Eric Anholt <[email protected]>


Attachments:
signature.asc (847.00 B)

2018-05-21 20:13:24

by Luca Coelho

[permalink] [raw]
Subject: Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

On Mon, 2018-05-21 at 19:57 +0800, Yisheng Xie wrote:
> 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]>
> Cc: [email protected]
> Cc: [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(-)
>
> diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> index 0e6401c..e8249a6 100644
> --- a/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> +++ b/drivers/net/wireless/intel/iwlwifi/mvm/debugfs.c
> @@ -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;

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.

2018-05-21 21:35:30

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 03/33] Staging: gdm724x: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.


> + 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.

--
With Best Regards,
Andy Shevchenko

2018-05-21 21:37:32

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 04/33] gpiolib-of: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.
>

https://patchwork.ozlabs.org/patch/908134/

> Cc: Linus Walleij <[email protected]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>


--
With Best Regards,
Andy Shevchenko

2018-05-21 21:40:20

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 05/33] cxgb4: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> - 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;

Is found still in use after this?
If so, is it initialized properly now?

--
With Best Regards,
Andy Shevchenko

2018-05-21 21:45:01

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> 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);

One line?

> + 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.

>
> ret = 0;



--
With Best Regards,
Andy Shevchenko

2018-05-21 21:47:04

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 10/33] pata_hpt37x: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.
>

https://www.spinics.net/lists/linux-ide/msg55658.html

> Cc: Bartlomiej Zolnierkiewicz <[email protected]>
> Cc: Tejun Heo <[email protected]>
> Cc: [email protected]


--
With Best Regards,
Andy Shevchenko

2018-05-21 21:47:26

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 09/33] phy: tegra: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.
>

https://patchwork.ozlabs.org/patch/908133/

> Cc: Kishon Vijay Abraham I <[email protected]>
> Cc: Thierry Reding <[email protected]>
> Cc: Jonathan Hunter <[email protected]>
> Cc: [email protected]


--
With Best Regards,
Andy Shevchenko

2018-05-21 21:51:28

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 12/33] clk: bcm2835: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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: Michael Turquette <[email protected]>
> Cc: Stephen Boyd <[email protected]>
> Cc: Eric Anholt <[email protected]>
> Cc: Stefan Wahren <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>

> - size_t i, j;
> - int ret;
> + int i, ret;

I do not see any need to change type for i.

> + ret = match_string(cprman_parent_names,
> + ARRAY_SIZE(cprman_parent_names),
> + parents[i]);
> + if (ret >= 0)
> + parents[i] = cprman->real_parent_names[ret];


--
With Best Regards,
Andy Shevchenko

2018-05-21 21:53:49

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 14/33] clk: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> + 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.

--
With Best Regards,
Andy Shevchenko

2018-05-21 21:56:23

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 17/33] pinctrl: armada-37xx: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

https://patchwork.kernel.org/patch/10378781/

> 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: [email protected]
> Cc: [email protected]

--
With Best Regards,
Andy Shevchenko

2018-05-21 21:58:43

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 18/33] power: supply: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.
>

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.

> Cc: Sebastian Reichel <[email protected]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> drivers/power/supply/power_supply_core.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index feac7b0..84da3a2 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -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
>



--
With Best Regards,
Andy Shevchenko

2018-05-21 22:01:00

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 19/33] thermal: db8500: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> + i = match_string((const char **)trip_point->cdev_name,

Casting looks ugly. You need to constify the variable itself.

> + COOLING_DEV_MAX, cdev->type);
>
> - return -ENODEV;
> + return (i < 0) ? -ENODEV : 0;

I would rather go with

if (ret < 0)
return -ENODEV;

return 0;

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:02:25

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 20/33] video: fbdev: pxafb: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

https://patchwork.kernel.org/patch/10378815/

> Cc: Bartlomiej Zolnierkiewicz <[email protected]>
> Cc: Arvind Yadav <[email protected]>
> Cc: [email protected]
> [email protected]

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:05:03

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 21/33] drm/nouveau: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> if (nouveau_tv_norm) {

> + 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.

> + 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
...

> }


--
With Best Regards,
Andy Shevchenko

2018-05-21 22:06:08

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 22/33] drm/i915: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

https://patchwork.kernel.org/patch/10382323/

> Cc: Jani Nikula <[email protected]>
> Cc: Joonas Lahtinen <[email protected]>
> Cc: Rodrigo Vivi <[email protected]>
> Cc: David Airlie <[email protected]>
> Cc: [email protected]
> Cc: [email protected]

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:07:20

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 24/33] drm: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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.

https://patchwork.kernel.org/patch/10382377/

> Cc: Gustavo Padovan <[email protected]>
> Cc: Maarten Lankhorst <[email protected]>
> Cc: Sean Paul <[email protected]>
> Cc: David Airlie <[email protected]>
> Cc: [email protected]

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:12:16

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 26/33] apparmor: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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.

http://kernsec.org/pipermail/linux-security-module-archi

> Cc: John Johansen <[email protected]>
> Cc: James Morris <[email protected]>
> Cc: "Serge E. Hallyn" <[email protected]>
> Cc: [email protected]

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:15:22

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 27/33] sched/debug: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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: 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(-)
>
> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
> index 15b10e2..9e34499 100644
> --- a/kernel/sched/debug.c
> +++ b/kernel/sched/debug.c
> @@ -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) {

Why not

if (i < 0)
return i;

?

> + if (neg) {
> + sysctl_sched_features &= ~(1UL << i);
> + sched_feat_disable(i);
> + } else {
> + sysctl_sched_features |= (1UL << i);
> + sched_feat_enable(i);
> }
> }
>
> @@ -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;

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:20:29

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 01/33] usb: phy: use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, 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.

> - int err, i;
> + int ret;

int err;

would still work.

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:23:53

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 30/33] ALSA: oxygen: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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: Clemens Ladisch <[email protected]>
> Cc: Jaroslav Kysela <[email protected]>
> Cc: Takashi Iwai <[email protected]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> sound/pci/oxygen/oxygen_mixer.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
> index 4ca1266..fbd8f5e 100644
> --- a/sound/pci/oxygen/oxygen_mixer.c
> +++ b/sound/pci/oxygen/oxygen_mixer.c
> @@ -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;

?

>
> 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;
> }
> --
> 1.7.12.4
>



--
With Best Regards,
Andy Shevchenko

2018-05-21 22:26:11

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 31/33] ASoC: max98088: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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.

> 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'

>
> /* Shouldn't happen */

> + if (ret < 0)
> + dev_err(component->dev, "Bad EQ channel name '%s'\n", name);

> return -EINVAL;

return ret;

?

> }
>
> --
> 1.7.12.4
>



--
With Best Regards,
Andy Shevchenko

2018-05-21 22:27:08

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 32/33] ASoC: max98095: use match_string() helper

On Mon, May 21, 2018 at 2:58 PM, 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.


> + int ret = match_string(bq_mode_name, ARRAY_SIZE(bq_mode_name), name);

Rather split and move an assignment to the line before 'if'.

>
> /* Shouldn't happen */

> + if (ret < 0)
> + dev_err(component->dev, "Bad biquad channel name '%s'\n", name);
> + return ret;
> }

--
With Best Regards,
Andy Shevchenko

2018-05-21 22:28:11

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 00/33] use match_string() helper

On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <[email protected]> wrote:
> 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

Reviewed-by: Andy Shevchenko <[email protected]>

> 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(-)
>
> --
> 1.7.12.4
>



--
With Best Regards,
Andy Shevchenko

2018-05-21 22:28:26

by Takashi Sakamoto

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 29/33] ALSA: oxfw: use match_string() helper

Hi,

On May 21 2018 20:58, Yisheng Xie wrote:
> 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: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> sound/firewire/oxfw/oxfw.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)

Reviewed-by: Takashi Sakamoto <[email protected]>

For my information, use_match_string() helper was firstly introduced to
v4.6 kernel by a commit 56b060814e2d ('lib/string: introduce
match_string() helper').

> diff --git a/sound/firewire/oxfw/oxfw.c b/sound/firewire/oxfw/oxfw.c
> index 413ab63..1e5b2c8 100644
> --- a/sound/firewire/oxfw/oxfw.c
> +++ b/sound/firewire/oxfw/oxfw.c
> @@ -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)

Thanks

Takashi Sakamoto

2018-05-21 22:31:49

by Takashi Sakamoto

[permalink] [raw]
Subject: Re: [PATCH 28/33] ALSA: dice use match_string() helper

Hi,

On May 21 2018 20:58, Yisheng Xie wrote:
> 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]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>
> ---
> 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.

> diff --git a/sound/firewire/dice/dice.c b/sound/firewire/dice/dice.c
> index 96bb01b..0639074 100644
> --- a/sound/firewire/dice/dice.c
> +++ b/sound/firewire/dice/dice.c
> @@ -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)

[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

2018-05-22 00:52:51

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 00/33] use match_string() helper

Hi Andy,

On 2018/5/22 6:27, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, Yisheng Xie <[email protected]> wrote:
>> 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.
>
> 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


2018-05-22 00:56:13

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 05/33] cxgb4: use match_string() helper

Hi Andy,

On 2018/5/22 5:39, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
>
>> - 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;
>
> 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

>


2018-05-22 01:25:55

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 26/33] apparmor: use match_string() helper

Hi John,

On 2018/5/21 23:33, John Johansen wrote:
> On 05/21/2018 04:58 AM, Yisheng Xie wrote:
>> 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
>
>> Cc: John Johansen <[email protected]>
>> Cc: James Morris <[email protected]>
>> Cc: "Serge E. Hallyn" <[email protected]>
>> Cc: [email protected]
>> Signed-off-by: Yisheng Xie <[email protected]>
>> ---
>> security/apparmor/lsm.c | 25 +++++++++++--------------
>> 1 file changed, 11 insertions(+), 14 deletions(-)
>>
>> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
>> index ce2b89e..9b5904f 100644
>> --- a/security/apparmor/lsm.c
>> +++ b/security/apparmor/lsm.c
>> @@ -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;
>> }
>>
>> /*
>>
>
>
>


2018-05-22 03:31:07

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

Hi Andy,

On 2018/5/22 5:43, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
>
>> 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);
>
> One line?

hmm, if use ret instead it will no over 80 chars.

>
>> + 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.

OK, I will change it if Loca agree your opinion.

Thanks
Yisheng
>
>>
>> ret = 0;
>
>
>


2018-05-22 03:43:41

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 12/33] clk: bcm2835: use match_string() helper

Hi Andy,

On 2018/5/22 5:50, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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: Michael Turquette <[email protected]>
>> Cc: Stephen Boyd <[email protected]>
>> Cc: Eric Anholt <[email protected]>
>> Cc: Stefan Wahren <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]
>> Cc: [email protected]
>> Signed-off-by: Yisheng Xie <[email protected]>
>
>> - 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

>
>> + ret = match_string(cprman_parent_names,
>> + ARRAY_SIZE(cprman_parent_names),
>> + parents[i]);
>> + if (ret >= 0)
>> + parents[i] = cprman->real_parent_names[ret];
>
>


2018-05-22 07:28:08

by Takashi Iwai

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 29/33] ALSA: oxfw: use match_string() helper

On Tue, 22 May 2018 00:26:53 +0200,
Takashi Sakamoto wrote:
>
> Hi,
>
> On May 21 2018 20:58, Yisheng Xie wrote:
> > 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: [email protected]
> > Signed-off-by: Yisheng Xie <[email protected]>
> > ---
> > sound/firewire/oxfw/oxfw.c | 8 +-------
> > 1 file changed, 1 insertion(+), 7 deletions(-)
>
> Reviewed-by: Takashi Sakamoto <[email protected]>
>
> For my information, use_match_string() helper was firstly introduced to
> v4.6 kernel by a commit 56b060814e2d ('lib/string: introduce
> match_string() helper').

OK, applied now. Thanks.


Takashi

2018-05-22 08:36:23

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH 22/33] drm/i915: use match_string() helper

On Tue, 22 May 2018, Andy Shevchenko <[email protected]> wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
>
> https://patchwork.kernel.org/patch/10382323/

Even more convincingly,

47d4cb8ae8e7 ("i915: Convert to use match_string() helper")

BR,
Jani.

>
>> Cc: Jani Nikula <[email protected]>
>> Cc: Joonas Lahtinen <[email protected]>
>> Cc: Rodrigo Vivi <[email protected]>
>> Cc: David Airlie <[email protected]>
>> Cc: [email protected]
>> Cc: [email protected]

--
Jani Nikula, Intel Open Source Graphics Center

2018-05-22 08:37:23

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH 24/33] drm: use match_string() helper

On Tue, 22 May 2018, Andy Shevchenko <[email protected]> wrote:
> On Mon, May 21, 2018 at 2:58 PM, 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.
>
> https://patchwork.kernel.org/patch/10382377/

818c05d8e267 ("drm: panel-orientation-quirks: Convert to use match_string() helper")

BR,
Jani.

>
>> Cc: Gustavo Padovan <[email protected]>
>> Cc: Maarten Lankhorst <[email protected]>
>> Cc: Sean Paul <[email protected]>
>> Cc: David Airlie <[email protected]>
>> Cc: [email protected]

--
Jani Nikula, Intel Open Source Graphics Center

2018-05-22 09:25:29

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 22/33] drm/i915: use match_string() helper

Hi Jani,

On 2018/5/22 16:36, Jani Nikula wrote:
> On Tue, 22 May 2018, Andy Shevchenko <[email protected]> wrote:
>> On Mon, May 21, 2018 at 2:57 PM, 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.
>>
>> https://patchwork.kernel.org/patch/10382323/
>
> Even more convincingly,
>
> 47d4cb8ae8e7 ("i915: Convert to use match_string() helper")

Sorry, but I will definitely remove them in next version, I just miss these.

Thanks
Yisheng
>
> BR,
> Jani.
>
>>
>>> Cc: Jani Nikula <[email protected]>
>>> Cc: Joonas Lahtinen <[email protected]>
>>> Cc: Rodrigo Vivi <[email protected]>
>>> Cc: David Airlie <[email protected]>
>>> Cc: [email protected]
>>> Cc: [email protected]
>


2018-05-22 10:03:10

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 01/33] usb: phy: use match_string() helper

On Tue, May 22, 2018 at 01:20:01AM +0300, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
>
> > - int err, i;
> > + int ret;
>
> int err;
>
> would still work.

And it reduces churn.

2018-05-22 11:15:39

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 01/33] usb: phy: use match_string() helper

Hi,

On 2018/5/22 18:02, Greg Kroah-Hartman wrote:
> On Tue, May 22, 2018 at 01:20:01AM +0300, Andy Shevchenko wrote:
>> On Mon, May 21, 2018 at 2:57 PM, 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.
>>
>>> - 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
>
>


2018-05-22 12:14:03

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 27/33] sched/debug: use match_string() helper

Hi Andy,

On 2018/5/22 6:13, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, 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: 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(-)
>>
>> diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
>> index 15b10e2..9e34499 100644
>> --- a/kernel/sched/debug.c
>> +++ b/kernel/sched/debug.c
>> @@ -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) {
>
> Why not
>
> if (i < 0)
> return i;

if i >=0 it will also return i. so need return i just if (i < 0), right ?

>
> ?
>
>> + 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;
>
> Now it would be
>
> if (i < 0)
> return i;

Right, will change it in next version

Thanks
Yisheng Xie
>


2018-05-22 12:33:33

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 31/33] ASoC: max98088: use match_string() helper

Hi Andy,

On 2018/5/22 6:24, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, 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.
>
>> 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;
>>
>> /* Shouldn't happen */
>
>> + 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
>
> ?
>
>> }
>>
>> --
>> 1.7.12.4
>>
>
>
>


2018-05-22 13:56:49

by Heiko Stübner

[permalink] [raw]
Subject: Re: [PATCH 13/33] clk: rockchip: use match_string() helper

Am Montag, 21. Mai 2018, 13:57:50 CEST schrieb 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: Heiko Stuebner <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>

> @@ -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





2018-05-22 16:17:22

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH 18/33] power: supply: use match_string() helper

Hi Andy,

On Tue, May 22, 2018 at 12:58:14AM +0300, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
> >
>
> 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


Attachments:
(No filename) (619.00 B)
signature.asc (849.00 B)
Download all attachments

2018-05-22 17:25:07

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 31/33] ASoC: max98088: use match_string() helper

On Tue, May 22, 2018 at 3:30 PM, Yisheng Xie <[email protected]> wrote:

> 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).

--
With Best Regards,
Andy Shevchenko

2018-05-22 20:29:57

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 27/33] sched/debug: use match_string() helper

On Tue, May 22, 2018 at 3:10 PM, Yisheng Xie <[email protected]> wrote:

>>> + 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.

>>> - 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.

>> return i;
>
> Right, will change it in next version

--
With Best Regards,
Andy Shevchenko

2018-05-22 20:42:22

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 07/33] iwlwifi: mvm: use match_string() helper

On Tue, May 22, 2018 at 6:30 AM, Yisheng Xie <[email protected]> wrote:

>> But it's up tu Loca.

Shame on me. I meant Luca, of course!
Luca, sorry.

> OK, I will change it if Loca agree your opinion.


--
With Best Regards,
Andy Shevchenko

2018-05-23 07:50:30

by Yisheng Xie

[permalink] [raw]
Subject: Re: [PATCH 19/33] thermal: db8500: use match_string() helper

Hi Andy,

On 2018/5/22 6:00, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:57 PM, 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.
>
>> + 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
>
>> + COOLING_DEV_MAX, cdev->type);
>>
>> - return -ENODEV;
>> + return (i < 0) ? -ENODEV : 0;
>
> I would rather go with
>
> if (ret < 0)
> return -ENODEV;
>
> return 0;
>


2018-05-23 14:43:55

by Mimi Zohar

[permalink] [raw]
Subject: Re: [PATCH 25/33] ima: use match_string() helper

On Mon, 2018-05-21 at 19:58 +0800, Yisheng Xie wrote:
> 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: [email protected]
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>

Reviewed-by: Mimi Zohar <[email protected]>

> ---
> security/integrity/ima/ima_main.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
> index 74d0bd7..f807093 100644
> --- a/security/integrity/ima/ima_main.c
> +++ b/security/integrity/ima/ima_main.c
> @@ -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;


2018-05-24 08:11:39

by Adrian Hunter

[permalink] [raw]
Subject: Re: [PATCH 16/33] mmc: sdhci-xenon: use match_string() helper

On 21/05/18 14:57, Yisheng Xie wrote:
> 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]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>

Acked-by: Adrian Hunter <[email protected]>

> ---
> drivers/mmc/host/sdhci-xenon-phy.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c
> index ec87943..a35804b 100644
> --- a/drivers/mmc/host/sdhci-xenon-phy.c
> +++ b/drivers/mmc/host/sdhci-xenon-phy.c
> @@ -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);
>


2018-05-25 20:55:56

by Alex Williamson

[permalink] [raw]
Subject: Re: [PATCH 08/33] vfio: use match_string() helper

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]>
> Cc: [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


> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 721f97f..6483387 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -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;
> }
>
> /*


2018-05-28 11:28:26

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH 16/33] mmc: sdhci-xenon: use match_string() helper

On 21 May 2018 at 13:57, 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: Adrian Hunter <[email protected]>
> Cc: Hu Ziji <[email protected]>
> Cc: Ulf Hansson <[email protected]>
> Cc: [email protected]
> Signed-off-by: Yisheng Xie <[email protected]>

Thanks, applied for next!

Kind regards
Uffe

> ---
> drivers/mmc/host/sdhci-xenon-phy.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-xenon-phy.c b/drivers/mmc/host/sdhci-xenon-phy.c
> index ec87943..a35804b 100644
> --- a/drivers/mmc/host/sdhci-xenon-phy.c
> +++ b/drivers/mmc/host/sdhci-xenon-phy.c
> @@ -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
>

2018-05-31 16:11:39

by Mark Brown

[permalink] [raw]
Subject: Applied "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

From f9e0b4afd4e9b19e95158962d81b5b776d57ca06 Mon 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.

Reviewed-by: Andy Shevchenko <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: [email protected]
Signed-off-by: Yisheng Xie <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
---
sound/soc/soc-dapm.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 2d9709104ec5..1e9a36389667 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -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 */
--
2.17.0


2018-06-04 06:17:53

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 02/33] mfd: omap-usb-host: use match_string() helper

On Mon, 21 May 2018, Yisheng Xie wrote:

> 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]>
> Cc: [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.

--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2018-06-05 16:15:19

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH 19/33] thermal: db8500: use match_string() helper

On Wed, May 23, 2018 at 10:47 AM, Yisheng Xie <[email protected]> wrote:
> Hi Andy,
>
> On 2018/5/22 6:00, Andy Shevchenko wrote:
>> On Mon, May 21, 2018 at 2:57 PM, 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.
>>
>>> + 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?

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.


--
With Best Regards,
Andy Shevchenko