diff mbox series

[v2,2/2] i2c: davinci: Use struct name not type with devm_kzalloc()

Message ID 20230515175042.495377-2-afd@ti.com (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] i2c: davinci: Use platform table macro over module_alias | expand

Commit Message

Andrew Davis May 15, 2023, 5:50 p.m. UTC
This reduces chance of error if the type of "dev" changes. While here
remove extra error print out, this is not usually done for memory
allocation failures.

Signed-off-by: Andrew Davis <afd@ti.com>
---
 drivers/i2c/busses/i2c-davinci.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Bartosz Golaszewski May 16, 2023, 2:45 p.m. UTC | #1
On Mon, May 15, 2023 at 7:50 PM Andrew Davis <afd@ti.com> wrote:
>
> This reduces chance of error if the type of "dev" changes. While here
> remove extra error print out, this is not usually done for memory
> allocation failures.
>
> Signed-off-by: Andrew Davis <afd@ti.com>
> ---
>  drivers/i2c/busses/i2c-davinci.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
> index c55bd937def7..135f76593e6f 100644
> --- a/drivers/i2c/busses/i2c-davinci.c
> +++ b/drivers/i2c/busses/i2c-davinci.c
> @@ -767,12 +767,9 @@ static int davinci_i2c_probe(struct platform_device *pdev)
>         if (irq < 0)
>                 return dev_err_probe(&pdev->dev, irq, "can't get irq resource\n");
>
> -       dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev),
> -                       GFP_KERNEL);
> -       if (!dev) {
> -               dev_err(&pdev->dev, "Memory allocation failed\n");
> +       dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
> +       if (!dev)
>                 return -ENOMEM;
> -       }
>
>         init_completion(&dev->cmd_complete);
>
> --
> 2.39.2
>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wolfram Sang June 7, 2023, 9:29 a.m. UTC | #2
On Mon, May 15, 2023 at 12:50:42PM -0500, Andrew Davis wrote:
> This reduces chance of error if the type of "dev" changes. While here
> remove extra error print out, this is not usually done for memory
> allocation failures.
> 
> Signed-off-by: Andrew Davis <afd@ti.com>

Applied to for-next, thanks!
Markus Elfring June 8, 2023, 9:42 a.m. UTC | #3
> This reduces chance of error if the type of "dev" changes. While here
> remove extra error print out, this is not usually done for memory
> allocation failures.

https://lore.kernel.org/linux-i2c/20230515175042.495377-2-afd@ti.com/
http://patchwork.ozlabs.org/project/linux-i2c/patch/20230515175042.495377-2-afd@ti.com/

I find that this change approach does not fit to the known requirement
“Solve only one problem per patch.”.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.4-rc5#n81

Should desirable changes be split into better update steps?

See also:
[PATCH 0/2] I2C-DaVinci: Adjustments for davinci_i2c_probe()
https://lore.kernel.org/linux-i2c/4e668c87-65f5-8a00-132a-0184779faa08@users.sourceforge.net/
https://lkml.org/lkml/2018/2/2/541

* [1/2] i2c-davinci: Delete an error message for a failed memory allocation in davinci_i2c_probe()
  https://patchwork.ozlabs.org/project/linux-i2c/patch/f890924b-ca68-253b-a7c8-fce269393867@users.sourceforge.net/

* [2/2] i2c-davinci: Improve a size determination in davinci_i2c_probe()
  https://patchwork.ozlabs.org/project/linux-i2c/patch/e16ba754-078a-097a-7333-076f43718645@users.sourceforge.net/

Regards,
Markus
Wolfram Sang June 8, 2023, 11:24 a.m. UTC | #4
> Should desirable changes be split into better update steps?

It is done. It has already been applied.
Markus Elfring June 8, 2023, 11:30 a.m. UTC | #5
>> Should desirable changes be split into better update steps?
>
> It is done. It has already been applied.

Will the patch review attention grow anyhow for affected aspects?

Regards,
Markus
Wolfram Sang June 8, 2023, 1:37 p.m. UTC | #6
> Will the patch review attention grow anyhow for affected aspects?

What are "affected aspects" in this case?
Markus Elfring June 8, 2023, 6:46 p.m. UTC | #7
>> Will the patch review attention grow anyhow for affected aspects?
>
> What are "affected aspects" in this case?

Example:
Linux patch requirements and corresponding coding style variations

Regards,
Markus
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index c55bd937def7..135f76593e6f 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -767,12 +767,9 @@  static int davinci_i2c_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return dev_err_probe(&pdev->dev, irq, "can't get irq resource\n");
 
-	dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev),
-			GFP_KERNEL);
-	if (!dev) {
-		dev_err(&pdev->dev, "Memory allocation failed\n");
+	dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
+	if (!dev)
 		return -ENOMEM;
-	}
 
 	init_completion(&dev->cmd_complete);