From 0860bf94712f34f5920193004dfed25408f078b1 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 13 Nov 2015 17:34:01 +0300 Subject: [PATCH 1/3] ide: silence some underflow warnings Back in the day we used to just say this code was root only so it was ok that the bounds checking was sloppy. These days it annoys static checkers so we fix it. In the original code "c > INT_MAX" was never true since "c" was an int. I am not sure what was intended so I left it alone. But because I made "c" unsigned it means we don't have a warning any more. The second warning is that we cap "i" but allow negatives leading to an underflow of the ide_disks_chs[] array. The third set of warnings is because these values come from the user and we cap most of the upper bounds but allow negative values. Negative cylinders doesn't make sense. drivers/ide/ide.c:262 ide_set_disk_chs() warn: impossible condition '(c > ((~0 >> 1))) => (s32min-s32max > s32max)' drivers/ide/ide.c:270 ide_set_disk_chs() warn: check 'ide_disks_chs[i]' for negative offsets 'i' = s32min. extra = 's32min-19' drivers/ide/ide.c:271 ide_set_disk_chs() warn: no lower bound on 'h' Signed-off-by: Dan Carpenter Signed-off-by: David S. Miller --- drivers/ide/ide.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index f086ef3874759..d127ace6aa575 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c @@ -178,17 +178,17 @@ MODULE_PARM_DESC(pci_clock, "PCI bus clock frequency (in MHz)"); static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp) { - int a, b, i, j = 1; + unsigned int a, b, i, j = 1; unsigned int *dev_param_mask = (unsigned int *)kp->arg; /* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */ - if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 && - sscanf(s, "%d.%d", &a, &b) != 2) + if (sscanf(s, "%u.%u:%u", &a, &b, &j) != 3 && + sscanf(s, "%u.%u", &a, &b) != 2) return -EINVAL; i = a * MAX_DRIVES + b; - if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1) + if (i >= MAX_HWIFS * MAX_DRIVES || j > 1) return -EINVAL; if (j) @@ -246,17 +246,17 @@ static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES]; static int ide_set_disk_chs(const char *str, struct kernel_param *kp) { - int a, b, c = 0, h = 0, s = 0, i, j = 1; + unsigned int a, b, c = 0, h = 0, s = 0, i, j = 1; /* controller . device (0 or 1) : Cylinders , Heads , Sectors */ /* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */ - if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 && - sscanf(str, "%d.%d:%d", &a, &b, &j) != 3) + if (sscanf(str, "%u.%u:%u,%u,%u", &a, &b, &c, &h, &s) != 5 && + sscanf(str, "%u.%u:%u", &a, &b, &j) != 3) return -EINVAL; i = a * MAX_DRIVES + b; - if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1) + if (i >= MAX_HWIFS * MAX_DRIVES || j > 1) return -EINVAL; if (c > INT_MAX || h > 255 || s > 255) From b5a608fb28c84ef3e569b6929e58977f4e2ce480 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sun, 15 Nov 2015 21:36:30 +0100 Subject: [PATCH 2/3] ide: constify ide_dma_ops structures The ide_dma_ops structures are never modified, so declare these as const, as is already done for the others. Done with the help of Coccinelle. Signed-off-by: Julia Lawall Signed-off-by: David S. Miller --- drivers/ide/it821x.c | 2 +- drivers/ide/trm290.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c index f01ba4606be0e..04029d18a6966 100644 --- a/drivers/ide/it821x.c +++ b/drivers/ide/it821x.c @@ -508,7 +508,7 @@ static void it821x_quirkproc(ide_drive_t *drive) } -static struct ide_dma_ops it821x_pass_through_dma_ops = { +static const struct ide_dma_ops it821x_pass_through_dma_ops = { .dma_host_set = ide_dma_host_set, .dma_setup = ide_dma_setup, .dma_start = it821x_dma_start, diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c index 0069f6ce74cf5..d550b379b0f11 100644 --- a/drivers/ide/trm290.c +++ b/drivers/ide/trm290.c @@ -314,7 +314,7 @@ static const struct ide_tp_ops trm290_tp_ops = { .output_data = ide_output_data, }; -static struct ide_dma_ops trm290_dma_ops = { +static const struct ide_dma_ops trm290_dma_ops = { .dma_host_set = trm290_dma_host_set, .dma_setup = trm290_dma_setup, .dma_start = trm290_dma_start, From e04a2bd6d8c95608cbb2c803ee2875cebfd89f52 Mon Sep 17 00:00:00 2001 From: Paul Gortmaker Date: Wed, 9 Dec 2015 16:45:51 -0500 Subject: [PATCH 3/3] drivers/ide: make ide-scan-pci.c driver explicitly non-modular The Kconfig for this support is currently: config IDEPCI_PCIBUS_ORDER bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)" ...meaning that it currently is not being built as a module by anyone. Lets change the initcall to be the equivalent device_initcall, so that when reading the driver code, there is no doubt it is builtin-only. Unlike other similar changes, we leave the module.h header to be included since this code interacts with other drivers and needs to know what a struct module is. Cc: "David S. Miller" Cc: linux-ide@vger.kernel.org Signed-off-by: Paul Gortmaker Signed-off-by: David S. Miller --- drivers/ide/ide-scan-pci.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/ide/ide-scan-pci.c b/drivers/ide/ide-scan-pci.c index c3da53e7bb2b4..86aa88aeb3a6b 100644 --- a/drivers/ide/ide-scan-pci.c +++ b/drivers/ide/ide-scan-pci.c @@ -107,5 +107,4 @@ static int __init ide_scan_pcibus(void) return 0; } - -module_init(ide_scan_pcibus); +device_initcall(ide_scan_pcibus);