diff options
Diffstat (limited to 'drivers/ata/libata-core.c')
-rw-r--r-- | drivers/ata/libata-core.c | 72 |
1 files changed, 3 insertions, 69 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 677c0c1b03bd..dbdc5d32343f 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <linux/async.h> | 59 | #include <linux/async.h> |
60 | #include <linux/log2.h> | 60 | #include <linux/log2.h> |
61 | #include <linux/slab.h> | 61 | #include <linux/slab.h> |
62 | #include <linux/glob.h> | ||
62 | #include <scsi/scsi.h> | 63 | #include <scsi/scsi.h> |
63 | #include <scsi/scsi_cmnd.h> | 64 | #include <scsi/scsi_cmnd.h> |
64 | #include <scsi/scsi_host.h> | 65 | #include <scsi/scsi_host.h> |
@@ -4250,73 +4251,6 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = { | |||
4250 | { } | 4251 | { } |
4251 | }; | 4252 | }; |
4252 | 4253 | ||
4253 | /** | ||
4254 | * glob_match - match a text string against a glob-style pattern | ||
4255 | * @text: the string to be examined | ||
4256 | * @pattern: the glob-style pattern to be matched against | ||
4257 | * | ||
4258 | * Either/both of text and pattern can be empty strings. | ||
4259 | * | ||
4260 | * Match text against a glob-style pattern, with wildcards and simple sets: | ||
4261 | * | ||
4262 | * ? matches any single character. | ||
4263 | * * matches any run of characters. | ||
4264 | * [xyz] matches a single character from the set: x, y, or z. | ||
4265 | * [a-d] matches a single character from the range: a, b, c, or d. | ||
4266 | * [a-d0-9] matches a single character from either range. | ||
4267 | * | ||
4268 | * The special characters ?, [, -, or *, can be matched using a set, eg. [*] | ||
4269 | * Behaviour with malformed patterns is undefined, though generally reasonable. | ||
4270 | * | ||
4271 | * Sample patterns: "SD1?", "SD1[0-5]", "*R0", "SD*1?[012]*xx" | ||
4272 | * | ||
4273 | * This function uses one level of recursion per '*' in pattern. | ||
4274 | * Since it calls _nothing_ else, and has _no_ explicit local variables, | ||
4275 | * this will not cause stack problems for any reasonable use here. | ||
4276 | * | ||
4277 | * RETURNS: | ||
4278 | * 0 on match, 1 otherwise. | ||
4279 | */ | ||
4280 | static int glob_match (const char *text, const char *pattern) | ||
4281 | { | ||
4282 | do { | ||
4283 | /* Match single character or a '?' wildcard */ | ||
4284 | if (*text == *pattern || *pattern == '?') { | ||
4285 | if (!*pattern++) | ||
4286 | return 0; /* End of both strings: match */ | ||
4287 | } else { | ||
4288 | /* Match single char against a '[' bracketed ']' pattern set */ | ||
4289 | if (!*text || *pattern != '[') | ||
4290 | break; /* Not a pattern set */ | ||
4291 | while (*++pattern && *pattern != ']' && *text != *pattern) { | ||
4292 | if (*pattern == '-' && *(pattern - 1) != '[') | ||
4293 | if (*text > *(pattern - 1) && *text < *(pattern + 1)) { | ||
4294 | ++pattern; | ||
4295 | break; | ||
4296 | } | ||
4297 | } | ||
4298 | if (!*pattern || *pattern == ']') | ||
4299 | return 1; /* No match */ | ||
4300 | while (*pattern && *pattern++ != ']'); | ||
4301 | } | ||
4302 | } while (*++text && *pattern); | ||
4303 | |||
4304 | /* Match any run of chars against a '*' wildcard */ | ||
4305 | if (*pattern == '*') { | ||
4306 | if (!*++pattern) | ||
4307 | return 0; /* Match: avoid recursion at end of pattern */ | ||
4308 | /* Loop to handle additional pattern chars after the wildcard */ | ||
4309 | while (*text) { | ||
4310 | if (glob_match(text, pattern) == 0) | ||
4311 | return 0; /* Remainder matched */ | ||
4312 | ++text; /* Absorb (match) this char and try again */ | ||
4313 | } | ||
4314 | } | ||
4315 | if (!*text && !*pattern) | ||
4316 | return 0; /* End of both strings: match */ | ||
4317 | return 1; /* No match */ | ||
4318 | } | ||
4319 | |||
4320 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev) | 4254 | static unsigned long ata_dev_blacklisted(const struct ata_device *dev) |
4321 | { | 4255 | { |
4322 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; | 4256 | unsigned char model_num[ATA_ID_PROD_LEN + 1]; |
@@ -4327,10 +4261,10 @@ static unsigned long ata_dev_blacklisted(const struct ata_device *dev) | |||
4327 | ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); | 4261 | ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); |
4328 | 4262 | ||
4329 | while (ad->model_num) { | 4263 | while (ad->model_num) { |
4330 | if (!glob_match(model_num, ad->model_num)) { | 4264 | if (glob_match(model_num, ad->model_num)) { |
4331 | if (ad->model_rev == NULL) | 4265 | if (ad->model_rev == NULL) |
4332 | return ad->horkage; | 4266 | return ad->horkage; |
4333 | if (!glob_match(model_rev, ad->model_rev)) | 4267 | if (glob_match(model_rev, ad->model_rev)) |
4334 | return ad->horkage; | 4268 | return ad->horkage; |
4335 | } | 4269 | } |
4336 | ad++; | 4270 | ad++; |