From: Matt Domsch <Matt_Domsch@dell.com>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] edd: fix error paths in module_init
Date: Sat, 24 May 2008 00:22:05 -0500 [thread overview]
Message-ID: <20080524052205.GE20890@auslistsprd01.us.dell.com> (raw)
In-Reply-To: <20080524020321.GA3470@APFDCB5C>
On Sat, May 24, 2008 at 11:03:23AM +0900, Akinobu Mita wrote:
> This patch fixes error handlings when kzalloc() or edd_device_register()
> failed in module_init. It needs to clean registered edd_devices before
> return error.
>
> Also this patch fixes return value of module_init. module_init should not
> return positive value.
Thanks for these. You caught me on holiday; I'll take a more thorough
look when I'm back next week.
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
> Cc: Matt Domsch <Matt_Domsch@Dell.com>
> ---
> drivers/firmware/edd.c | 30 ++++++++++++++++++------------
> 1 file changed, 18 insertions(+), 12 deletions(-)
>
> Index: 2.6-git/drivers/firmware/edd.c
> ===================================================================
> --- 2.6-git.orig/drivers/firmware/edd.c
> +++ 2.6-git/drivers/firmware/edd.c
> @@ -718,8 +718,7 @@ edd_device_register(struct edd_device *e
> {
> int error;
>
> - if (!edev)
> - return 1;
> + BUG_ON(!edev);
Wouldn't WARN_ON() and return failure be sufficient? I hate crashing
the system when loading a driver if I can avoid it.
> edd_dev_set_info(edev, i);
> edev->kobj.kset = edd_kset;
> error = kobject_init_and_add(&edev->kobj, &edd_ktype, NULL,
> @@ -744,8 +743,8 @@ static inline int edd_num_devices(void)
> static int __init
> edd_init(void)
> {
> - unsigned int i;
> - int rc=0;
> + int i;
> + int rc;
> struct edd_device *edev;
>
> printk(KERN_INFO "BIOS EDD facility v%s %s, %d devices found\n",
> @@ -753,29 +752,36 @@ edd_init(void)
>
> if (!edd_num_devices()) {
> printk(KERN_INFO "EDD information not available.\n");
> - return 1;
> + return -ENODEV;
> }
>
> edd_kset = kset_create_and_add("edd", NULL, firmware_kobj);
> if (!edd_kset)
> return -ENOMEM;
>
> - for (i = 0; i < edd_num_devices() && !rc; i++) {
> + for (i = 0; i < edd_num_devices(); i++) {
> edev = kzalloc(sizeof (*edev), GFP_KERNEL);
> - if (!edev)
> - return -ENOMEM;
> + if (!edev) {
> + rc = -ENOMEM;
> + goto out;
> + }
>
> rc = edd_device_register(edev, i);
> if (rc) {
> kfree(edev);
> - break;
> + goto out;
> }
> edd_devices[i] = edev;
> }
>
> - if (rc)
> - kset_unregister(edd_kset);
> - return rc;
> + return 0;
> +out:
> + while (--i >= 0)
> + edd_device_unregister(edd_devices[i]);
> +
> + kset_unregister(edd_kset);
> +
> + return rc;
I didn't really like my initial approach, but the question was: when
you hit a failure, do you try to back completely out (unregister
everything that had successfully registered until now), or do you
leave the things that have succeeded, and only fail the current and
future devices? For my purposes, having even the first device be
reported, even if the others couldn't be, is useful. Hence why I
didn't undo all the registrations on failure.
--
Matt Domsch
Linux Technology Strategist, Dell Office of the CTO
linux.dell.com & www.dell.com/linux
next prev parent reply other threads:[~2008-05-24 5:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-24 2:03 [PATCH] edd: fix error paths in module_init Akinobu Mita
2008-05-24 5:22 ` Matt Domsch [this message]
2008-05-24 8:13 ` Akinobu Mita
-- strict thread matches above, loose matches on Subject: below --
2008-05-29 17:56 devzero
2008-05-30 14:02 ` Akinobu Mita
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=20080524052205.GE20890@auslistsprd01.us.dell.com \
--to=matt_domsch@dell.com \
--cc=akinobu.mita@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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