Skip to contentSkip to conversation

libata-core: support wildcard matching in ata_blacklist_entry

PATCH In review David Milburn 3 participants 3 messages Aug 8, 2007 – Aug 16, 2007 libata

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libata-core: support wildcard matching in ata_blacklist_entry

Support the use of '*' in model_num and model_rev entries in ata_device_blacklist[].

---

 drivers/ata/libata-core.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
drivers/ata/libata-core.c +9 -2
index 60e78be..1c9c208 100644
@@ -3806,10 +3806,17 @@ static unsigned long ata_dev_blacklisted(const struct ata_device *dev)
 	ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev));
 
 	while (ad->model_num) {
-		if (!strcmp(ad->model_num, model_num)) {
+		char *wc;
+		wc = strchr(ad->model_num, '*');
+		if (!strncmp(ad->model_num, model_num, 
+			     wc ? wc - ad->model_num : 
+			     strlen(ad->model_num))) {
 			if (ad->model_rev == NULL)
 				return ad->horkage;
-			if (!strcmp(ad->model_rev, model_rev))
+			wc = strchr(ad->model_rev, '*');
+			if (!strncmp(ad->model_rev, model_rev,
+				     wc ? wc - ad->model_rev : 
+				     strlen(ad->model_rev)))
 				return ad->horkage;
 		}
 		ad++;
#1 lore raw
Quoted 5 lines · On Wed, 8 Aug 2007 15:20:57 -0500 David Milburn <[email protected]> wrote:

Support the use of '*' in model_num and model_rev entries in ata_device_blacklist[].

Suggestion: Pull the match function out of line so you don't have two copies of it and can remove all the wacky ? operators

something like this ? (untested)

	strpatterncmp(const char *name, const char *patt)
	{
		const char *p = strchr(patt, '*');
		if (p == NULL)
			p = patt + strlen(patt);
		return strncmp(name, patt, p-patt);
	}
#2 lore raw
Quoted 14 lines · Alan Cox
Quoted 5 lines · On Wed, 8 Aug 2007 15:20:57 -0500 David Milburn <[email protected]> wrote:

Support the use of '*' in model_num and model_rev entries in ata_device_blacklist[].

Suggestion: Pull the match function out of line so you don't have two copies of it and can remove all the wacky ? operators

something like this ? (untested)

Quoted 7 lines
	strpatterncmp(const char *name, const char *patt)
	{
		const char *p = strchr(patt, '*');
		if (p == NULL)
			p = patt + strlen(patt);
		return strncmp(name, patt, p-patt);
	}

Seems quite sane to me...

And I support the addition of wildcard operators; that should make maintenance a bit easier.