public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <zonque@gmail.com>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: Balaji T K <balajitk@ti.com>,
	linux-mmc@vger.kernel.org, Venkatraman S <svenkatr@ti.com>,
	Chris Ball <cjb@laptop.org>,
	Rob Herring <rob.herring@calxeda.com>,
	linux-omap@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/4] MMC: omap_hsmmc: set platform data after probe from DT node
Date: Sat, 13 Oct 2012 10:53:11 +0200	[thread overview]
Message-ID: <50792BF7.5020908@gmail.com> (raw)
In-Reply-To: <CACxGe6tGYrO8Z0MxiOV+rjBprRxzT-4v6CiBh8wV0Avufd0doA@mail.gmail.com>

On 13.10.2012 10:48, Grant Likely wrote:
> On Sat, Oct 13, 2012 at 9:05 AM, Daniel Mack <zonque@gmail.com> wrote:
>> Hi Grant,
>>
>> On 13.10.2012 02:05, Grant Likely wrote:
>>>
>>>
>>> Balaji T K <balajitk@ti.com> wrote:
>>>
>>>> On Friday 12 October 2012 08:44 PM, Daniel Mack wrote:
>>>>> On 12.10.2012 16:56, Balaji T K wrote:
>>>>>> On Friday 12 October 2012 07:59 PM, Daniel Mack wrote:
>>>>>>> On 12.10.2012 12:58, Daniel Mack wrote:
>>>>>>>> diff --git a/drivers/mmc/host/omap_hsmmc.c
>>>> b/drivers/mmc/host/omap_hsmmc.c
>>>>>>>> index 19ccb59..4b70823 100644 ---
>>>>>>>> a/drivers/mmc/host/omap_hsmmc.c +++
>>>>>>>> b/drivers/mmc/host/omap_hsmmc.c @@ -1728,6 +1728,7 @@
>>>>>>>> static int __devinit omap_hsmmc_probe(struct
>>>> platform_device *pdev)
>>>>>>>> const u16 *offsetp = match->data; pdata->reg_offset =
>>>>>>>> *offsetp; } +            pdev->dev.platform_data = pdata; }
>>>>>>>>
>>>>>>>> if (pdata == NULL) {
>>>>>>>>
>>>>>>>
>>>>>>> FWIW, this is the Oops I see without this patch:
>>>>>> Hi, Shouldn't pdev->dev.platform_data be set to NULL on _remove
>>>>>> ?
>>>>>
>>>>> Why?
>>>>
>>>> To make sure on second insmod it is NULL, When built as module, So
>>>> that of_get_hsmmc_pdata is called to create pdata.
>>>
>>> Actually the driver should *never* modify the value of
>>> dev->platform_data. Ever.
>>
>> That's interesting, because many drivers do this, especially since they
>> were converted to DT probing. Mostly because that way, the platform data
>> logic in callback functions can be reused, and often the platform
>> specific data is only stored in pdata and taken from there during the
>> lifetime of a device.
>>
>> Is there any particular reason why this approach is frowned upon?
> 
> Yes. The platform data pointer is "owned" by the code that registered
> the platform device, not by the device driver. Some drivers do it, but
> it is definitely illegal. I should add code to the platform bus core
> code to throw a warning to any drivers that do that. It is a problem
> because it becomes easy to mess up the lifetime model of device data,
> particularly when it comes to unbinding/rebinding devices. For
> example, if a driver changes the pdata pointer and then gets unbound,
> then there will be a stale pdata pointer that may point to either
> incorrect data or a data structure that is no longer allocated. You
> could argue that it is fine if the driver is smart about how it cleans
> up after itself, but in my experience driver authors rarely get it
> correct and it results in a lot more code than is necessary. It is far
> better for the driver to either grab all the data it needs out of
> pdata at .probe() time, or to keep a copy of the 'correct' pdata
> (correct depending on where the device retrieved it's data) in it's
> private data structure instead of modifying the device.

Ok, interesting. Thanks for writing this up.

>>> Make a copy instead.
>>
>> A copy of what exactly? Of all members of the legacy pdata you mean?
> 
> Yes. If the driver directly accesses the pdata structure outside of
> the .probe() hook, then it should be modified to either copy the pdata
> into the driver's private data structure, or it should copy the
> pointer to the pdata so that OF usage can allocate one itself. For
> example:
> 
> somedriver_probe(struct platform_device *pdev)
> {
>       struct somedriver_private *somedriver;
> 
>       somedriver = devm_kzalloc(sizeof (*somedriver), GFP_KERNEL);
>       somedriver->pdata = pdev->platform_data;
>       if (OF)
>               somedriver->pdata = devm_kzalloc(sizeof
> (*somedriver->pdata), GFP_KERNEL);
> }
> 
> The bonus with using devm_kzalloc is the driver doesn't even need to
> do anything special to undo these allocations on failure or release.
> :-)

Ok, understood. Will keep an eye on this in the future. Thanks again for
the explanation.

For this particular driver, this means that both my and Balaji's ways of
fixing this are wrong?


Daniel


  reply	other threads:[~2012-10-13  8:53 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-12 10:58 [PATCH 0/4] MMC: some omap_hsmmc fixes Daniel Mack
2012-10-12 10:58 ` [PATCH 1/4] MMC: omap_hsmmc: set platform data after probe from DT node Daniel Mack
2012-10-12 14:29   ` Daniel Mack
2012-10-12 14:56     ` Balaji T K
2012-10-12 15:14       ` Daniel Mack
2012-10-12 15:23         ` Balaji T K
2012-10-13  0:05           ` Grant Likely
2012-10-13  8:05             ` Daniel Mack
2012-10-13  8:48               ` Grant Likely
2012-10-13  8:53                 ` Daniel Mack [this message]
2012-10-13 12:37                   ` Grant Likely
2012-10-12 10:58 ` [PATCH 2/4] MMC: omap_hsmmc: fix DMA config block Daniel Mack
2012-10-12 11:07   ` Porter, Matt
2012-10-12 11:12   ` Russell King - ARM Linux
2012-10-12 14:19     ` Daniel Mack
2012-10-12 10:58 ` [PATCH 3/4] MMC: omap_hsmmc: claim pinctrl at probe time Daniel Mack
2012-10-12 11:08   ` Linus Walleij
2012-10-12 10:58 ` [PATCH 4/4] MMC: omap_hsmmc: add DT property for max bus frequency Daniel Mack
2012-10-12 15:25   ` Rob Herring
2012-10-12 15:26     ` Daniel Mack
2012-10-13  9:01 ` [PATCH 0/4] MMC: some omap_hsmmc fixes Daniel Mack
2012-10-15 16:07   ` Venkatraman S

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=50792BF7.5020908@gmail.com \
    --to=zonque@gmail.com \
    --cc=balajitk@ti.com \
    --cc=cjb@laptop.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=svenkatr@ti.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