From: Lee Jones <lee.jones@linaro.org>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: linux-omap@vger.kernel.org, Tony Lindgren <tony@atomide.com>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@lip6.fr>
Subject: Re: [PATCH] mfd: twl-core: One function call less in add_numbered_child() after error detection
Date: Mon, 11 Jan 2016 08:29:22 +0000 [thread overview]
Message-ID: <20160111082922.GB14104@x1> (raw)
In-Reply-To: <5682D228.7070902@users.sourceforge.net>
On Tue, 29 Dec 2015, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 29 Dec 2015 19:29:08 +0100
>
> The platform_device_put() function was called in one case by the
> add_numbered_child() function during error handling even if the passed
> variable "pdev" contained a null pointer.
>
> Implementation details could be improved by the adjustment of jump targets
> according to the Linux coding style convention.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/mfd/twl-core.c | 21 ++++++++++-----------
> 1 file changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
> index 831696e..0d9350c 100644
> --- a/drivers/mfd/twl-core.c
> +++ b/drivers/mfd/twl-core.c
> @@ -625,7 +625,7 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
> if (!pdev) {
> dev_dbg(&twl->client->dev, "can't alloc dev\n");
Change this to be dev_err()
> status = -ENOMEM;
> - goto err;
> + goto report_failure;
... and just return status from here.
> }
>
> pdev->dev.parent = &twl->client->dev;
> @@ -634,7 +634,7 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
> status = platform_device_add_data(pdev, pdata, pdata_len);
> if (status < 0) {
> dev_dbg(&pdev->dev, "can't add platform_data\n");
> - goto err;
> + goto put_device;
> }
> }
>
> @@ -647,21 +647,20 @@ add_numbered_child(unsigned mod_no, const char *name, int num,
> status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
> if (status < 0) {
> dev_dbg(&pdev->dev, "can't add irqs\n");
> - goto err;
> + goto put_device;
> }
> }
>
> status = platform_device_add(pdev);
> - if (status == 0)
> + if (!status) {
You've changed the way you handle errors from this point. To be more
consistent it would be better if you checked for status, then jump to
put_device in the case of a failure, as you do above.
> device_init_wakeup(&pdev->dev, can_wakeup);
> -
> -err:
> - if (status < 0) {
> - platform_device_put(pdev);
> - dev_err(&twl->client->dev, "can't add %s dev\n", name);
> - return ERR_PTR(status);
> + return &pdev->dev;
> }
> - return &pdev->dev;
> +put_device:
> + platform_device_put(pdev);
> +report_failure:
> + dev_err(&twl->client->dev, "can't add %s dev\n", name);
> + return ERR_PTR(status);
> }
>
> static inline struct device *add_child(unsigned mod_no, const char *name,
--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-01-11 8:29 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-29 18:34 ` [PATCH] mfd: twl-core: One function call less in add_numbered_child() after error detection SF Markus Elfring
2016-01-11 8:29 ` Lee Jones [this message]
2016-05-15 18:11 ` [PATCH 0/2] mfd: twl-core: Fine-tuning for add_numbered_child() SF Markus Elfring
2016-05-16 6:26 ` [PATCH 1/2] mfd: twl-core: Return directly after a failed platform_device_alloc() in add_numbered_child() SF Markus Elfring
2016-05-16 6:51 ` Julia Lawall
2016-05-16 7:54 ` SF Markus Elfring
2016-05-16 8:07 ` Julia Lawall
2016-05-17 6:00 ` Lee Jones
2016-05-17 14:15 ` SF Markus Elfring
2016-05-16 6:28 ` [PATCH 2/2] mfd: twl-core: Refactoring for add_numbered_child() SF Markus Elfring
2016-06-08 11:14 ` Lee Jones
2016-06-26 13:34 ` [PATCH 0/6] mfd: Fine-tuning for three function implementations SF Markus Elfring
2016-06-26 13:45 ` [PATCH 1/6] mfd: twl-core: Return directly after a failed platform_device_alloc() in add_numbered_child() SF Markus Elfring
2016-06-28 15:02 ` Lee Jones
2016-06-26 13:47 ` [PATCH 2/6] mfd: twl-core: Refactoring for add_numbered_child() SF Markus Elfring
2016-06-28 15:03 ` Lee Jones
2016-06-26 13:48 ` [PATCH 3/6] mfd: dm355evm_msp: Return directly after a failed platform_device_alloc() in add_child() SF Markus Elfring
2016-06-28 15:03 ` Lee Jones
2016-06-26 13:50 ` [PATCH 4/6] mfd: dm355evm_msp: Refactoring for add_child() SF Markus Elfring
2016-06-28 15:07 ` Lee Jones
2016-06-28 15:40 ` SF Markus Elfring
2016-06-28 16:31 ` Lee Jones
2016-06-26 13:51 ` [PATCH 5/6] mfd: smsc-ece1099: Delete an unnecessary variable initialisation in smsc_i2c_probe() SF Markus Elfring
2016-06-28 15:07 ` Lee Jones
2016-06-26 13:54 ` [PATCH 6/6] mfd: smsc-ece1099: Return directly after a function failure " SF Markus Elfring
2016-06-28 15:08 ` Lee Jones
2016-06-28 15:01 ` [PATCH 0/6] mfd: Fine-tuning for three function implementations Lee Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160111082922.GB14104@x1 \
--to=lee.jones@linaro.org \
--cc=elfring@users.sourceforge.net \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).