diff mbox series

[4/8] pinctrl: use krealloc_array()

Message ID 20201027121725.24660-5-brgl@bgdev.pl
State Superseded
Headers show
Series slab: provide and use krealloc_array() | expand

Commit Message

Bartosz Golaszewski Oct. 27, 2020, 12:17 p.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Use the helper that checks for overflows internally instead of manually
calculating the size of the new array.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/pinctrl/pinctrl-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andy Shevchenko Oct. 27, 2020, 1:29 p.m. UTC | #1
On Tue, Oct 27, 2020 at 01:17:21PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

> 

> Use the helper that checks for overflows internally instead of manually

> calculating the size of the new array.

> 

> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

> ---

>  drivers/pinctrl/pinctrl-utils.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drivers/pinctrl/pinctrl-utils.c b/drivers/pinctrl/pinctrl-utils.c

> index f2bcbf62c03d..93df0d4c0a24 100644

> --- a/drivers/pinctrl/pinctrl-utils.c

> +++ b/drivers/pinctrl/pinctrl-utils.c

> @@ -39,7 +39,7 @@ int pinctrl_utils_reserve_map(struct pinctrl_dev *pctldev,

>  	if (old_num >= new_num)

>  		return 0;

>  

> -	new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);

> +	new_map = krealloc_array(*map, new_num, sizeof(*new_map), GFP_KERNEL);

>  	if (!new_map) {

>  		dev_err(pctldev->dev, "krealloc(map) failed\n");


...and here?

>  		return -ENOMEM;

> -- 

> 2.29.1

> 


-- 
With Best Regards,
Andy Shevchenko
Andy Shevchenko Oct. 27, 2020, 1:58 p.m. UTC | #2
On Tue, Oct 27, 2020 at 03:29:11PM +0200, Andy Shevchenko wrote:
> On Tue, Oct 27, 2020 at 01:17:21PM +0100, Bartosz Golaszewski wrote:

> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

> > 

> > Use the helper that checks for overflows internally instead of manually

> > calculating the size of the new array.


After addressing a nit in previous message:
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>


-- 
With Best Regards,
Andy Shevchenko
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-utils.c b/drivers/pinctrl/pinctrl-utils.c
index f2bcbf62c03d..93df0d4c0a24 100644
--- a/drivers/pinctrl/pinctrl-utils.c
+++ b/drivers/pinctrl/pinctrl-utils.c
@@ -39,7 +39,7 @@  int pinctrl_utils_reserve_map(struct pinctrl_dev *pctldev,
 	if (old_num >= new_num)
 		return 0;
 
-	new_map = krealloc(*map, sizeof(*new_map) * new_num, GFP_KERNEL);
+	new_map = krealloc_array(*map, new_num, sizeof(*new_map), GFP_KERNEL);
 	if (!new_map) {
 		dev_err(pctldev->dev, "krealloc(map) failed\n");
 		return -ENOMEM;