Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1224682 > unrolled thread
| Started by | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| First post | 2015-09-15 09:00 +0200 |
| Last post | 2015-09-15 17:40 +0200 |
| Articles | 5 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v1 0/3] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-09-15 09:00 +0200
[PATCH v1 2/3] drm/edid: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-09-15 09:00 +0200
[PATCH v1 3/3] ata: hpt366: convert to use match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-09-15 09:00 +0200
[PATCH v1 1/3] lib/string: introduce match_string() helper Andy Shevchenko <andriy.shevchenko@linux.intel.com> - 2015-09-15 09:00 +0200
Re: [PATCH v1 0/3] lib/string: introduce match_string() helper Tejun Heo <tj@kernel.org> - 2015-09-15 17:40 +0200
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2015-09-15 09:00 +0200 |
| Subject | [PATCH v1 0/3] lib/string: introduce match_string() helper |
| Message-ID | <q8SnE-5Cp-13@gated-at.bofh.it> |
There are users of a simple string matching in the array. Let's do a common helper for that. Two users are updated in the series. one more is coming [1]. [1] http://www.spinics.net/lists/kernel/msg2074265.html The series is compile tested. Andy Shevchenko (3): lib/string: introduce match_string() helper drm/edid: convert to use match_string() helper ata: hpt366: convert to use match_string() helper drivers/ata/pata_hpt366.c | 13 +++++-------- drivers/gpu/drm/drm_edid_load.c | 17 ++++++----------- include/linux/string.h | 7 +++++++ lib/string.c | 26 ++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 19 deletions(-) -- 2.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2015-09-15 09:00 +0200 |
| Subject | [PATCH v1 2/3] drm/edid: convert to use match_string() helper |
| Message-ID | <q8SnE-5Cp-15@gated-at.bofh.it> |
| In reply to | #1224682 |
The new helper returns index of the mathing string in an array. We would use it
here.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpu/drm/drm_edid_load.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid_load.c b/drivers/gpu/drm/drm_edid_load.c
index 698b8c3..9a401ae 100644
--- a/drivers/gpu/drm/drm_edid_load.c
+++ b/drivers/gpu/drm/drm_edid_load.c
@@ -170,16 +170,11 @@ static void *edid_load(struct drm_connector *connector, const char *name,
int i, valid_extensions = 0;
bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
- builtin = 0;
- for (i = 0; i < GENERIC_EDIDS; i++) {
- if (strcmp(name, generic_edid_name[i]) == 0) {
- fwdata = generic_edid[i];
- fwsize = sizeof(generic_edid[i]);
- builtin = 1;
- break;
- }
- }
- if (!builtin) {
+ builtin = match_string(generic_edid_name, GENERIC_EDIDS, name);
+ if (builtin >= 0) {
+ fwdata = generic_edid[builtin];
+ fwsize = sizeof(generic_edid[builtin]);
+ } else {
struct platform_device *pdev;
int err;
@@ -252,7 +247,7 @@ static void *edid_load(struct drm_connector *connector, const char *name,
}
DRM_INFO("Got %s EDID base block and %d extension%s from "
- "\"%s\" for connector \"%s\"\n", builtin ? "built-in" :
+ "\"%s\" for connector \"%s\"\n", (builtin >= 0) ? "built-in" :
"external", valid_extensions, valid_extensions == 1 ? "" : "s",
name, connector_name);
--
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2015-09-15 09:00 +0200 |
| Subject | [PATCH v1 3/3] ata: hpt366: convert to use match_string() helper |
| Message-ID | <q8SnF-5Cp-17@gated-at.bofh.it> |
| In reply to | #1224682 |
The new helper returns index of the mathing string in an array. We would use it
here.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/ata/pata_hpt366.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 0038dc4..3dcf350 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -176,17 +176,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_stringnul(list, model_num);
+ if (i >= 0) {
+ pr_warn("%s is not supported for %s\n", modestr, list[i]);
+ return 1;
}
return 0;
}
--
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Andy Shevchenko <andriy.shevchenko@linux.intel.com> |
|---|---|
| Date | 2015-09-15 09:00 +0200 |
| Subject | [PATCH v1 1/3] lib/string: introduce match_string() helper |
| Message-ID | <q8SnF-5Cp-21@gated-at.bofh.it> |
| In reply to | #1224682 |
From time to time we have to match a string in an array. Make a simple helper
for that purpose.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string.h | 7 +++++++
lib/string.c | 26 ++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/include/linux/string.h b/include/linux/string.h
index a8d90db..15e6116 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -126,6 +126,13 @@ extern void argv_free(char **argv);
extern bool sysfs_streq(const char *s1, const char *s2);
extern int strtobool(const char *s, bool *res);
+int match_string(const char * const *array, size_t len, const char *string);
+
+static inline int match_stringnul(const char * const *array, const char *string)
+{
+ return match_string(array, 0, string);
+}
+
#ifdef CONFIG_BINARY_PRINTF
int vbin_printf(u32 *bin_buf, size_t size, const char *fmt, va_list args);
int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf);
diff --git a/lib/string.c b/lib/string.c
index 13d1e84..0771359 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -542,6 +542,32 @@ bool sysfs_streq(const char *s1, const char *s2)
EXPORT_SYMBOL(sysfs_streq);
/**
+ * match_string - matches given string in an array
+ * @array: array of strings
+ * @len: number of strings in the array or 0 for NULL terminated arrays
+ * @string: string to match with
+ *
+ * Return:
+ * index of a @string in the array if matches, or -1 otherwise.
+ */
+int match_string(const char * const *array, size_t len, const char *string)
+{
+ int index = 0;
+ const char *item;
+
+ do {
+ item = array[index];
+ if (!item)
+ break;
+ if (!strcmp(item, string))
+ return index;
+ } while (++index < len || !len);
+
+ return -1;
+}
+EXPORT_SYMBOL(match_string);
+
+/**
* strtobool - convert common user inputs into boolean values
* @s: input string
* @res: result
--
2.5.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Tejun Heo <tj@kernel.org> |
|---|---|
| Date | 2015-09-15 17:40 +0200 |
| Message-ID | <q90uS-xv-35@gated-at.bofh.it> |
| In reply to | #1224682 |
Hello, On Tue, Sep 15, 2015 at 09:53:48AM +0300, Andy Shevchenko wrote: > There are users of a simple string matching in the array. Let's do a common > helper for that. > > Two users are updated in the series. one more is coming [1]. > > [1] http://www.spinics.net/lists/kernel/msg2074265.html > > The series is compile tested. > > Andy Shevchenko (3): > lib/string: introduce match_string() helper > drm/edid: convert to use match_string() helper > ata: hpt366: convert to use match_string() helper > > drivers/ata/pata_hpt366.c | 13 +++++-------- > drivers/gpu/drm/drm_edid_load.c | 17 ++++++----------- > include/linux/string.h | 7 +++++++ > lib/string.c | 26 ++++++++++++++++++++++++++ > 4 files changed, 44 insertions(+), 19 deletions(-) While increase in LOC isn't the only indicator, we're adding two helper functions each for two usages. I'm not quite sure the addition of helpers is paying off here. Thanks. -- tejun -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web