aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2015-11-13 09:34:01 -0500
committerDavid S. Miller <davem@davemloft.net>2016-01-18 14:12:33 -0500
commit0860bf94712f34f5920193004dfed25408f078b1 (patch)
tree56ca28016cb0edc1f3404fbcc23cf5747d9aac6f /drivers/ide
parent5807fcaa9bf7dd87241df739161c119cf78a6bc4 (diff)
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 <dan.carpenter@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/ide.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index f086ef387475..d127ace6aa57 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)");
178 178
179static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp) 179static int ide_set_dev_param_mask(const char *s, const struct kernel_param *kp)
180{ 180{
181 int a, b, i, j = 1; 181 unsigned int a, b, i, j = 1;
182 unsigned int *dev_param_mask = (unsigned int *)kp->arg; 182 unsigned int *dev_param_mask = (unsigned int *)kp->arg;
183 183
184 /* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */ 184 /* controller . device (0 or 1) [ : 1 (set) | 0 (clear) ] */
185 if (sscanf(s, "%d.%d:%d", &a, &b, &j) != 3 && 185 if (sscanf(s, "%u.%u:%u", &a, &b, &j) != 3 &&
186 sscanf(s, "%d.%d", &a, &b) != 2) 186 sscanf(s, "%u.%u", &a, &b) != 2)
187 return -EINVAL; 187 return -EINVAL;
188 188
189 i = a * MAX_DRIVES + b; 189 i = a * MAX_DRIVES + b;
190 190
191 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1) 191 if (i >= MAX_HWIFS * MAX_DRIVES || j > 1)
192 return -EINVAL; 192 return -EINVAL;
193 193
194 if (j) 194 if (j)
@@ -246,17 +246,17 @@ static struct chs_geom ide_disks_chs[MAX_HWIFS * MAX_DRIVES];
246 246
247static int ide_set_disk_chs(const char *str, struct kernel_param *kp) 247static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
248{ 248{
249 int a, b, c = 0, h = 0, s = 0, i, j = 1; 249 unsigned int a, b, c = 0, h = 0, s = 0, i, j = 1;
250 250
251 /* controller . device (0 or 1) : Cylinders , Heads , Sectors */ 251 /* controller . device (0 or 1) : Cylinders , Heads , Sectors */
252 /* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */ 252 /* controller . device (0 or 1) : 1 (use CHS) | 0 (ignore CHS) */
253 if (sscanf(str, "%d.%d:%d,%d,%d", &a, &b, &c, &h, &s) != 5 && 253 if (sscanf(str, "%u.%u:%u,%u,%u", &a, &b, &c, &h, &s) != 5 &&
254 sscanf(str, "%d.%d:%d", &a, &b, &j) != 3) 254 sscanf(str, "%u.%u:%u", &a, &b, &j) != 3)
255 return -EINVAL; 255 return -EINVAL;
256 256
257 i = a * MAX_DRIVES + b; 257 i = a * MAX_DRIVES + b;
258 258
259 if (i >= MAX_HWIFS * MAX_DRIVES || j < 0 || j > 1) 259 if (i >= MAX_HWIFS * MAX_DRIVES || j > 1)
260 return -EINVAL; 260 return -EINVAL;
261 261
262 if (c > INT_MAX || h > 255 || s > 255) 262 if (c > INT_MAX || h > 255 || s > 255)