* [PATCH] pinctrl-armada-xp: Use devm_kmalloc_array() in armada_xp_pinctrl_probe()
@ 2017-04-14 16:58 SF Markus Elfring
2017-04-21 19:22 ` Chris Packham
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-04-14 16:58 UTC (permalink / raw)
To: linux-gpio, Chris Packham, Kalyan Kinthada, Laxman Dewangan,
Linus Walleij, Paul Gortmaker, Rob Herring, Russell King
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 14 Apr 2017 18:48:15 +0200
* A multiplication for the size determination of a memory allocation
indicated that an array data structure should be processed.
Thus use the corresponding function "devm_kmalloc_array".
This issue was detected by using the Coccinelle software.
* Replace the specification of a data type by a pointer dereference
to make the corresponding size determination a bit safer according to
the Linux coding style convention.
* Delete the local variable "nregs" which became unnecessary with
this refactoring.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/pinctrl/mvebu/pinctrl-armada-xp.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
index b854f1ee5de5..457c54c8fed3 100644
--- a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
+++ b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
@@ -574,7 +574,6 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
struct mvebu_pinctrl_soc_info *soc = &armada_xp_pinctrl_info;
const struct of_device_id *match =
of_match_device(armada_xp_pinctrl_of_match, &pdev->dev);
- int nregs;
if (!match)
return -ENODEV;
@@ -628,10 +627,11 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
break;
}
- nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
-
- mpp_saved_regs = devm_kmalloc(&pdev->dev, nregs * sizeof(u32),
- GFP_KERNEL);
+ mpp_saved_regs = devm_kmalloc_array(&pdev->dev,
+ DIV_ROUND_UP(soc->nmodes,
+ MVEBU_MPPS_PER_REG),
+ sizeof(*mpp_saved_regs),
+ GFP_KERNEL);
if (!mpp_saved_regs)
return -ENOMEM;
--
2.12.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] pinctrl-armada-xp: Use devm_kmalloc_array() in armada_xp_pinctrl_probe()
2017-04-14 16:58 [PATCH] pinctrl-armada-xp: Use devm_kmalloc_array() in armada_xp_pinctrl_probe() SF Markus Elfring
@ 2017-04-21 19:22 ` Chris Packham
0 siblings, 0 replies; 2+ messages in thread
From: Chris Packham @ 2017-04-21 19:22 UTC (permalink / raw)
To: SF Markus Elfring, linux-gpio, Kalyan Kinthada, Laxman Dewangan,
Linus Walleij, Paul Gortmaker, Rob Herring, Russell King
Cc: LKML, kernel-janitors
Hi Markus,
On 15/04/17 05:04, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Fri, 14 Apr 2017 18:48:15 +0200
>
> * A multiplication for the size determination of a memory allocation
> indicated that an array data structure should be processed.
> Thus use the corresponding function "devm_kmalloc_array".
>
> This issue was detected by using the Coccinelle software.
>
> * Replace the specification of a data type by a pointer dereference
> to make the corresponding size determination a bit safer according to
> the Linux coding style convention.
>
> * Delete the local variable "nregs" which became unnecessary with
> this refactoring.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/pinctrl/mvebu/pinctrl-armada-xp.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
> index b854f1ee5de5..457c54c8fed3 100644
> --- a/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
> +++ b/drivers/pinctrl/mvebu/pinctrl-armada-xp.c
> @@ -574,7 +574,6 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
> struct mvebu_pinctrl_soc_info *soc = &armada_xp_pinctrl_info;
> const struct of_device_id *match =
> of_match_device(armada_xp_pinctrl_of_match, &pdev->dev);
> - int nregs;
>
> if (!match)
> return -ENODEV;
> @@ -628,10 +627,11 @@ static int armada_xp_pinctrl_probe(struct platform_device *pdev)
> break;
> }
>
> - nregs = DIV_ROUND_UP(soc->nmodes, MVEBU_MPPS_PER_REG);
> -
> - mpp_saved_regs = devm_kmalloc(&pdev->dev, nregs * sizeof(u32),
> - GFP_KERNEL);
> + mpp_saved_regs = devm_kmalloc_array(&pdev->dev,
> + DIV_ROUND_UP(soc->nmodes,
> + MVEBU_MPPS_PER_REG),
> + sizeof(*mpp_saved_regs),
> + GFP_KERNEL);
I personally think having nregs makes the code a bit more readable but
that's just me.
With or without a change
Reviewed-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> if (!mpp_saved_regs)
> return -ENOMEM;
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-04-21 19:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-14 16:58 [PATCH] pinctrl-armada-xp: Use devm_kmalloc_array() in armada_xp_pinctrl_probe() SF Markus Elfring
2017-04-21 19:22 ` Chris Packham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®