diff options
author | Chris Metcalf <cmetcalf@mellanox.com> | 2016-07-28 15:07:04 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-08-30 08:45:50 -0400 |
commit | 069b188f43d9a44422eb35a8f95533d2c44ad315 (patch) | |
tree | fed6b8e65379cf74c34ba6901506c5f71d8a23c5 /drivers/char/tile-srom.c | |
parent | acde785e492d6ce838f50937f7547124e0837a55 (diff) |
tile-srom: avoid krealloc(... __GFP_ZERO) pattern
Joe Perches points out [1] that this pattern isn't currently safe.
This driver doesn't really need the zeroing semantic anyway;
by restructuring the code slightly we can initialize all the
fields of the structure up front instead.
[1] https://lkml.kernel.org/r/1469729491.3998.58.camel@perches.com
Signed-off-by: Chris Metcalf <cmetcalf@mellanox.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/char/tile-srom.c')
-rw-r--r-- | drivers/char/tile-srom.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/drivers/char/tile-srom.c b/drivers/char/tile-srom.c index 69f6b4acc377..398800edb2cc 100644 --- a/drivers/char/tile-srom.c +++ b/drivers/char/tile-srom.c | |||
@@ -331,13 +331,11 @@ static const struct file_operations srom_fops = { | |||
331 | /** | 331 | /** |
332 | * srom_setup_minor() - Initialize per-minor information. | 332 | * srom_setup_minor() - Initialize per-minor information. |
333 | * @srom: Per-device SROM state. | 333 | * @srom: Per-device SROM state. |
334 | * @index: Device to set up. | 334 | * @devhdl: Partition device handle. |
335 | */ | 335 | */ |
336 | static int srom_setup_minor(struct srom_dev *srom, int index) | 336 | static int srom_setup_minor(struct srom_dev *srom, int devhdl) |
337 | { | 337 | { |
338 | struct device *dev; | 338 | srom->hv_devhdl = devhdl; |
339 | int devhdl = srom->hv_devhdl; | ||
340 | |||
341 | mutex_init(&srom->lock); | 339 | mutex_init(&srom->lock); |
342 | 340 | ||
343 | if (_srom_read(devhdl, &srom->total_size, | 341 | if (_srom_read(devhdl, &srom->total_size, |
@@ -350,9 +348,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index) | |||
350 | SROM_PAGE_SIZE_OFF, sizeof(srom->page_size)) < 0) | 348 | SROM_PAGE_SIZE_OFF, sizeof(srom->page_size)) < 0) |
351 | return -EIO; | 349 | return -EIO; |
352 | 350 | ||
353 | dev = device_create(srom_class, &srom_parent->dev, | 351 | return 0; |
354 | MKDEV(srom_major, index), srom, "%d", index); | ||
355 | return PTR_ERR_OR_ZERO(dev); | ||
356 | } | 352 | } |
357 | 353 | ||
358 | /** srom_init() - Initialize the driver's module. */ | 354 | /** srom_init() - Initialize the driver's module. */ |
@@ -365,7 +361,7 @@ static int srom_init(void) | |||
365 | * Start with a plausible number of partitions; the krealloc() call | 361 | * Start with a plausible number of partitions; the krealloc() call |
366 | * below will yield about log(srom_devs) additional allocations. | 362 | * below will yield about log(srom_devs) additional allocations. |
367 | */ | 363 | */ |
368 | srom_devices = kzalloc(4 * sizeof(struct srom_dev), GFP_KERNEL); | 364 | srom_devices = kmalloc(4 * sizeof(struct srom_dev), GFP_KERNEL); |
369 | 365 | ||
370 | /* Discover the number of srom partitions. */ | 366 | /* Discover the number of srom partitions. */ |
371 | for (i = 0; ; i++) { | 367 | for (i = 0; ; i++) { |
@@ -373,7 +369,7 @@ static int srom_init(void) | |||
373 | char buf[20]; | 369 | char buf[20]; |
374 | struct srom_dev *new_srom_devices = | 370 | struct srom_dev *new_srom_devices = |
375 | krealloc(srom_devices, (i+1) * sizeof(struct srom_dev), | 371 | krealloc(srom_devices, (i+1) * sizeof(struct srom_dev), |
376 | GFP_KERNEL | __GFP_ZERO); | 372 | GFP_KERNEL); |
377 | if (!new_srom_devices) { | 373 | if (!new_srom_devices) { |
378 | result = -ENOMEM; | 374 | result = -ENOMEM; |
379 | goto fail_mem; | 375 | goto fail_mem; |
@@ -387,7 +383,9 @@ static int srom_init(void) | |||
387 | i, devhdl); | 383 | i, devhdl); |
388 | break; | 384 | break; |
389 | } | 385 | } |
390 | srom_devices[i].hv_devhdl = devhdl; | 386 | result = srom_setup_minor(&srom_devices[i], devhdl); |
387 | if (result != 0) | ||
388 | goto fail_mem; | ||
391 | } | 389 | } |
392 | srom_devs = i; | 390 | srom_devs = i; |
393 | 391 | ||
@@ -431,9 +429,13 @@ static int srom_init(void) | |||
431 | srom_class->dev_groups = srom_dev_groups; | 429 | srom_class->dev_groups = srom_dev_groups; |
432 | srom_class->devnode = srom_devnode; | 430 | srom_class->devnode = srom_devnode; |
433 | 431 | ||
434 | /* Do per-partition initialization */ | 432 | /* Create per-partition devices */ |
435 | for (i = 0; i < srom_devs; i++) { | 433 | for (i = 0; i < srom_devs; i++) { |
436 | result = srom_setup_minor(srom_devices + i, i); | 434 | struct device *dev = |
435 | device_create(srom_class, &srom_parent->dev, | ||
436 | MKDEV(srom_major, i), srom_devices + i, | ||
437 | "%d", i); | ||
438 | result = PTR_ERR_OR_ZERO(dev); | ||
437 | if (result < 0) | 439 | if (result < 0) |
438 | goto fail_class; | 440 | goto fail_class; |
439 | } | 441 | } |