LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Markus Pargmann <mpa@pengutronix.de>
To: Ingo Flaschberger <ingo.flaschberger@gmail.com>
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org
Subject: Re: Fwd: Re: unbind/bind w1-gpio with device tree produce a crash
Date: Thu, 5 Mar 2015 08:35:24 +0100	[thread overview]
Message-ID: <20150305073524.GC8062@pengutronix.de> (raw)
In-Reply-To: <54F7C5D4.3000604@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2819 bytes --]

Hi Ingo,

On Thu, Mar 05, 2015 at 03:56:20AM +0100, Ingo Flaschberger wrote:
> Dear Markus,
> 
> as I get no answer at the kernel mailinglist:
> your patch to use devm_kzalloc instead of kzalloc produce driver crashes
> when the 1wire bus is unbound and bound again (see details below).
> 
> What do you suggest to solve this problem?

Good point. The easy way to solve this may be to check in the remove
function if the devicetree node for this device is available. If it is,
we know that platform_data was allocated with devm_* and we can set
platform_data to NULL.

I think the better solution would be to create a private structure with
the same data as w1_gpio_platform_data. It may even use the same struct.
But it should not be stored in platform_data. Instead it should be
handled seperately. For DT we can allocate it using devm_kzalloc(). And
for probing with pdata, this could just be the pointer to the pdata
within the device struct.

Adding the list as CC again.

Best Regards,

Markus

> 
> Kind regards,
>     Ingo Flaschberger
> 
> -------- Weitergeleitete Nachricht --------
> Betreff: 	Re: unbind/bind w1-gpio with device tree produce a crash
> Datum: 	Wed, 04 Mar 2015 17:38:48 +0100
> Von: 	Ingo Flaschberger <ingo.flaschberger@gmail.com>
> An: 	linux-kernel@vger.kernel.org
> 
> 
> 
> is it ok, to create a new global variable that tracks if pdata was
> alloced via devm_kzalloc and sets pdata to NULL in w1_gpio_remove?
> 
> Am 04.03.2015 um 04:53 schrieb Ingo Flaschberger:
> >If w1-gpio is probed via device-tree configuration, pdata is allocated
> >via devm_kzalloc.
> >When the device is unbind (and bind later) the allocated memory of
> >pdate is freed - but it will not be allocacted again.
> >
> >static int w1_gpio_probe(struct platform_device *pdev)
> >        struct w1_bus_master *master;
> >        struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
> >        int err;
> >
> >        if(pdata == NULL) {
> >                if (of_have_populated_dt()) {
> >                        err = w1_gpio_probe_dt(pdev);
> >                        if (err < 0)
> >                                return err;
> >                }
> >        }
> >
> >How to detect if pdata was allocated via device-tree devm_kzalloc and
> >not "hardcoded"?
> >Then I could set pdev->dev.platform_data to NULL in w1_gpio_remove
> >which will solve the crash.
> >
> >Kind regards,
> >   Ingo Flascherger
> >
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2015-03-05  7:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-04  3:53 Ingo Flaschberger
2015-03-04 16:38 ` Ingo Flaschberger
     [not found]   ` <54F7C5D4.3000604@gmail.com>
2015-03-05  7:35     ` Markus Pargmann [this message]
2015-03-05 11:56       ` Fwd: " Ingo Flaschberger
2015-03-09 10:18         ` [PATCH] w1: gpio: Fix problematic platform_data usage Markus Pargmann
2015-04-10 10:22           ` Markus Pargmann
2016-03-22 11:59             ` Ingo Flaschberger

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=20150305073524.GC8062@pengutronix.de \
    --to=mpa@pengutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ingo.flaschberger@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: Fwd: Re: unbind/bind w1-gpio with device tree produce a crash' \
    /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

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).