[2/4] gpio: tegra: Prefer kcalloc() over kzalloc() with multiplies

Message ID 20170724145508.7388-2-thierry.reding@gmail.com
State Accepted
Headers show

Commit Message

Thierry Reding July 24, 2017, 2:55 p.m.
From: Thierry Reding <treding@nvidia.com>

Rather than manually compute the size of an array, pass the number and
element size to kcalloc().

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/gpio/gpio-tegra.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jon Hunter July 25, 2017, 8:27 a.m. | #1
On 24/07/17 15:55, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Rather than manually compute the size of an array, pass the number and
> element size to kcalloc().
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/gpio/gpio-tegra.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
> index 63ee221f9be9..1d4df290d7ab 100644
> --- a/drivers/gpio/gpio-tegra.c
> +++ b/drivers/gpio/gpio-tegra.c
> @@ -621,10 +621,10 @@ static int tegra_gpio_probe(struct platform_device *pdev)
>  	if (tgi->soc->debounce_supported)
>  		tgi->gc.set_config = tegra_gpio_set_config;
>  
> -	tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count *
> +	tgi->bank_info = devm_kcalloc(&pdev->dev, tgi->bank_count,
>  				      sizeof(*tgi->bank_info), GFP_KERNEL);
>  	if (!tgi->bank_info)
> -		return -ENODEV;
> +		return -ENOMEM;
>  
>  	tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node,
>  						tgi->gc.ngpio,
> 

Acked-by: Jon Hunter <jonathanh@nvidia.com>

Cheers
Jon
Linus Walleij Aug. 2, 2017, 12:16 p.m. | #2
On Mon, Jul 24, 2017 at 4:55 PM, Thierry Reding
<thierry.reding@gmail.com> wrote:

> From: Thierry Reding <treding@nvidia.com>
>
> Rather than manually compute the size of an array, pass the number and
> element size to kcalloc().
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Patch applied with Jon's ACK.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 63ee221f9be9..1d4df290d7ab 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -621,10 +621,10 @@  static int tegra_gpio_probe(struct platform_device *pdev)
 	if (tgi->soc->debounce_supported)
 		tgi->gc.set_config = tegra_gpio_set_config;
 
-	tgi->bank_info = devm_kzalloc(&pdev->dev, tgi->bank_count *
+	tgi->bank_info = devm_kcalloc(&pdev->dev, tgi->bank_count,
 				      sizeof(*tgi->bank_info), GFP_KERNEL);
 	if (!tgi->bank_info)
-		return -ENODEV;
+		return -ENOMEM;
 
 	tgi->irq_domain = irq_domain_add_linear(pdev->dev.of_node,
 						tgi->gc.ngpio,