aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-01-02 06:19:40 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-09 17:39:30 -0500
commit8bfa79fcb81d2bdb043f60ab4171704467808b55 (patch)
tree8b81b15237110ee30626057541e07b0ba8aa80bc /drivers
parenta0cf733b333eeeafb7324e2897448006c693c26c (diff)
libata: use ata_id_c_string()
There were several places where ATA ID strings are manually terminated and in some places possibly unterminated strings were passed to string functions which don't limit length like strstr(). This patch converts all of them over to ata_id_c_string(). Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ata/libata-core.c27
-rw-r--r--drivers/ata/pata_ali.c4
-rw-r--r--drivers/ata/pata_hpt366.c18
-rw-r--r--drivers/ata/pata_hpt37x.c18
-rw-r--r--drivers/ata/pata_it821x.c17
-rw-r--r--drivers/ata/pata_serverworks.c17
6 files changed, 23 insertions, 78 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 7d4b002568e7..a03019c40ac4 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -3325,35 +3325,20 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3325 { } 3325 { }
3326}; 3326};
3327 3327
3328static int ata_strim(char *s, size_t len)
3329{
3330 len = strnlen(s, len);
3331
3332 /* ATAPI specifies that empty space is blank-filled; remove blanks */
3333 while ((len > 0) && (s[len - 1] == ' ')) {
3334 len--;
3335 s[len] = 0;
3336 }
3337 return len;
3338}
3339
3340unsigned long ata_device_blacklisted(const struct ata_device *dev) 3328unsigned long ata_device_blacklisted(const struct ata_device *dev)
3341{ 3329{
3342 unsigned char model_num[ATA_ID_PROD_LEN]; 3330 unsigned char model_num[ATA_ID_PROD_LEN + 1];
3343 unsigned char model_rev[ATA_ID_FW_REV_LEN]; 3331 unsigned char model_rev[ATA_ID_FW_REV_LEN + 1];
3344 unsigned int nlen, rlen;
3345 const struct ata_blacklist_entry *ad = ata_device_blacklist; 3332 const struct ata_blacklist_entry *ad = ata_device_blacklist;
3346 3333
3347 ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 3334 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
3348 ata_id_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev)); 3335 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev));
3349 nlen = ata_strim(model_num, sizeof(model_num));
3350 rlen = ata_strim(model_rev, sizeof(model_rev));
3351 3336
3352 while (ad->model_num) { 3337 while (ad->model_num) {
3353 if (!strncmp(ad->model_num, model_num, nlen)) { 3338 if (!strcmp(ad->model_num, model_num)) {
3354 if (ad->model_rev == NULL) 3339 if (ad->model_rev == NULL)
3355 return ad->horkage; 3340 return ad->horkage;
3356 if (!strncmp(ad->model_rev, model_rev, rlen)) 3341 if (!strcmp(ad->model_rev, model_rev))
3357 return ad->horkage; 3342 return ad->horkage;
3358 } 3343 }
3359 ad++; 3344 ad++;
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index 76e386043dcd..fde5ce9f7eae 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -153,11 +153,11 @@ static void ali_early_error_handler(struct ata_port *ap)
153 153
154static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 154static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
155{ 155{
156 char model_num[ATA_ID_PROD_LEN]; 156 char model_num[ATA_ID_PROD_LEN + 1];
157 /* No DMA on anything but a disk for now */ 157 /* No DMA on anything but a disk for now */
158 if (adev->class != ATA_DEV_ATA) 158 if (adev->class != ATA_DEV_ATA)
159 mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 159 mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
160 ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 160 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
161 if (strstr(model_num, "WDC")) 161 if (strstr(model_num, "WDC"))
162 return mask &= ~ATA_MASK_UDMA; 162 return mask &= ~ATA_MASK_UDMA;
163 return ata_pci_default_filter(ap, adev, mask); 163 return ata_pci_default_filter(ap, adev, mask);
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 81deb2c3824c..2202c7ec16e3 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -151,23 +151,13 @@ static const char *bad_ata66_3[] = {
151 151
152static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 152static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[])
153{ 153{
154 unsigned char model_num[ATA_ID_PROD_LEN]; 154 unsigned char model_num[ATA_ID_PROD_LEN + 1];
155 char *s;
156 unsigned int len;
157 int i = 0; 155 int i = 0;
158 156
159 ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 157 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
160 s = &model_num[0];
161 len = strnlen(s, sizeof(model_num));
162 158
163 /* ATAPI specifies that empty space is blank-filled; remove blanks */ 159 while (list[i] != NULL) {
164 while ((len > 0) && (s[len - 1] == ' ')) { 160 if (!strcmp(list[i], model_num)) {
165 len--;
166 s[len] = 0;
167 }
168
169 while(list[i] != NULL) {
170 if (!strncmp(list[i], s, len)) {
171 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", 161 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
172 modestr, list[i]); 162 modestr, list[i]);
173 return 1; 163 return 1;
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index ff767755e98b..9e1eb473c0a1 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -349,23 +349,13 @@ static u32 hpt37x_find_mode(struct ata_port *ap, int speed)
349 349
350static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 350static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[])
351{ 351{
352 unsigned char model_num[ATA_ID_PROD_LEN]; 352 unsigned char model_num[ATA_ID_PROD_LEN + 1];
353 char *s;
354 unsigned int len;
355 int i = 0; 353 int i = 0;
356 354
357 ata_id_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 355 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
358 s = &model_num[0];
359 len = strnlen(s, sizeof(model_num));
360 356
361 /* ATAPI specifies that empty space is blank-filled; remove blanks */ 357 while (list[i] != NULL) {
362 while ((len > 0) && (s[len - 1] == ' ')) { 358 if (!strcmp(list[i], model_num)) {
363 len--;
364 s[len] = 0;
365 }
366
367 while(list[i] != NULL) {
368 if (!strncmp(list[i], s, len)) {
369 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", 359 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
370 modestr, list[i]); 360 modestr, list[i]);
371 return 1; 361 return 1;
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index c84dfaede89c..171fbd206bd5 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -531,22 +531,9 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
531 531
532static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev) 532static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev)
533{ 533{
534 unsigned char model_num[ATA_ID_PROD_LEN]; 534 unsigned char model_num[ATA_ID_PROD_LEN + 1];
535 char *s;
536 unsigned int len;
537 535
538 /* This block ought to be a library routine as it is in several 536 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
539 drivers now */
540
541 ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
542 s = &model_num[0];
543 len = strnlen(s, sizeof(model_num));
544
545 /* ATAPI specifies that empty space is blank-filled; remove blanks */
546 while ((len > 0) && (s[len - 1] == ' ')) {
547 len--;
548 s[len] = 0;
549 }
550 537
551 if (adev->max_sectors > 255) 538 if (adev->max_sectors > 255)
552 adev->max_sectors = 255; 539 adev->max_sectors = 255;
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index bf9452728d19..4b8c2352cdca 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -218,25 +218,18 @@ static unsigned long serverworks_osb4_filter(const struct ata_port *ap, struct a
218static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 218static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
219{ 219{
220 const char *p; 220 const char *p;
221 char model_num[ATA_ID_PROD_LEN]; 221 char model_num[ATA_ID_PROD_LEN + 1];
222 int len, i; 222 int i;
223 223
224 /* Disk, UDMA */ 224 /* Disk, UDMA */
225 if (adev->class != ATA_DEV_ATA) 225 if (adev->class != ATA_DEV_ATA)
226 return ata_pci_default_filter(ap, adev, mask); 226 return ata_pci_default_filter(ap, adev, mask);
227 227
228 /* Actually do need to check */ 228 /* Actually do need to check */
229 ata_id_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 229 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
230 /* Precuationary - why not do this in the libata core ?? */
231 230
232 len = strlen(model_num); 231 for (i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
233 while ((len > 0) && (model_num[len - 1] == ' ')) { 232 if (!strcmp(p, model_num))
234 len--;
235 model_num[len] = 0;
236 }
237
238 for(i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
239 if (!strncmp(p, model_num, len))
240 mask &= ~(0x1F << ATA_SHIFT_UDMA); 233 mask &= ~(0x1F << ATA_SHIFT_UDMA);
241 } 234 }
242 return ata_pci_default_filter(ap, adev, mask); 235 return ata_pci_default_filter(ap, adev, mask);