From: Richard Purdie <rpurdie@rpsys.net>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Jaya Kumar <jayakumar.lkml@gmail.com>,
Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: Clarifying platform_device_unregister
Date: Sat, 05 Apr 2008 12:44:52 +0100 [thread overview]
Message-ID: <1207395892.5021.20.camel@dax.rpnet.com> (raw)
In-Reply-To: <20080401104533.ZZRA012@mailhub.coreip.homeip.net>
On Tue, 2008-04-01 at 10:54 -0400, Dmitry Torokhov wrote:
> On Tue, Apr 01, 2008 at 12:47:54AM -0700, Jaya Kumar wrote:
> > That's interesting. I noticed though that a lot of platform device
> > code assigns a statically allocated structure to platform_data. For
> > example:
> >
> > arch/arm/mach-pxa/corgi_pm.c
> > static struct sharpsl_charger_machinfo corgi_pm_machinfo = {
> > ...
> > }
> > corgipm_device->dev.platform_data = &corgi_pm_machinfo;
> >
> > same with spitz_pm.c.
> >
> > egrep "platform_data.*=.*\&" *.c shows quite a lot of users doing
> > that. I guess most of these below are probably okay since these
> > drivers can't be rmmoded.
> >
>
> Hmm, are you sure they can't be removed? Why do they all have
> module_exit methods?
>
> Even if they can't be unloaded the whole thing will blow to pieces
> if registration fails. Consider this:
>
> static int __devinit spitzpm_init(void)
> {
> int ret;
>
> spitzpm_device = platform_device_alloc("sharpsl-pm", -1);
> if (!spitzpm_device)
> return -ENOMEM;
>
> spitzpm_device->dev.platform_data = &spitz_pm_machinfo;
> ret = platform_device_add(spitzpm_device);
>
> if (ret)
> platform_device_put(spitzpm_device);
> ^^^^^^^^^^^
> This will try to kfree(spitzpm_device->dev.platform_data) and it gonna
> blow. We need to do spitzpm_device->dev.platform_data = NULL before doing
> put.
>
> Also spitzpm_init() shoudl be marked __init, not __devinit and
> spitzpm_exit() should be __exit() if it is event needed at all.
>
> Richard, I think you work with spitz and corgi, any comments?
Looking at this I agree there are some problems there.
In the real world the spitz/corgi devices are pretty useless without
power management and therefore these code paths aren't well used. I
think this has happened since the platform data was a later addition to
the code and the internal use of kfree on platform_data wasn't realised.
I'll make sure some patches are submitted to address these issues.
Cheers,
Richard
prev parent reply other threads:[~2008-04-05 11:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-01 1:14 Clarifying platform_device_unregister Jaya Kumar
2008-04-01 5:19 ` Dmitry Torokhov
2008-04-01 7:47 ` Jaya Kumar
2008-04-01 14:54 ` Dmitry Torokhov
2008-04-02 1:57 ` Jaya Kumar
2008-04-05 12:07 ` Richard Purdie
2008-04-05 11:44 ` Richard Purdie [this message]
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=1207395892.5021.20.camel@dax.rpnet.com \
--to=rpurdie@rpsys.net \
--cc=dmitry.torokhov@gmail.com \
--cc=jayakumar.lkml@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