From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754431AbbCEHf2 (ORCPT ); Thu, 5 Mar 2015 02:35:28 -0500 Received: from metis.ext.pengutronix.de ([92.198.50.35]:39501 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754188AbbCEHf0 (ORCPT ); Thu, 5 Mar 2015 02:35:26 -0500 Date: Thu, 5 Mar 2015 08:35:24 +0100 From: Markus Pargmann To: Ingo Flaschberger Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: Fwd: Re: unbind/bind w1-gpio with device tree produce a crash Message-ID: <20150305073524.GC8062@pengutronix.de> References: <54F73518.3000304@gmail.com> <54F7C5D4.3000604@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="R+My9LyyhiUvIEro" Content-Disposition: inline In-Reply-To: <54F7C5D4.3000604@gmail.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 08:28:00 up 42 days, 21:35, 44 users, load average: 18.35, 14.05, 9.61 User-Agent: Mutt/1.5.23 (2014-03-12) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: mpa@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --R+My9LyyhiUvIEro Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Ingo, On Thu, Mar 05, 2015 at 03:56:20AM +0100, Ingo Flaschberger wrote: > Dear Markus, >=20 > 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). >=20 > 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 >=20 > Kind regards, > Ingo Flaschberger >=20 > -------- 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 > An: linux-kernel@vger.kernel.org >=20 >=20 >=20 > 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? >=20 > 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 =3D pdev->dev.platform_data; > > int err; > > > > if(pdata =3D=3D NULL) { > > if (of_have_populated_dt()) { > > err =3D 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 > > >=20 >=20 >=20 --=20 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 | --R+My9LyyhiUvIEro Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJU+Ac8AAoJEEpcgKtcEGQQFMUP/0PQ3Rg+8baeupkf1lSv/MsL ccFouGcRZ+dt4WO/wFH8LXPSntQB4jQNFsPnHsjgEbRpeAQ/dB8cDgA+6+Z05erS adV0Vmmtv2bCisEvfTsIQstNasck4YBWG2umylmTrMOCZtVu8UcMR+bfXRdjIy/4 /fMjuUwVv5AxQvnxqnGgfISuyp5JJmwaS2CZh5WifenxEAqtWbYzkgzF/zsj87jg 91FSe7XrSlsfKDxxhC4WUTtobrf+XOZf/PPpaJ4JrNKtw27xPSwTEUCrtAHTJ/bj 87+TI2KK+uUTE7KTh+7o4Rs0MkPbGctPCEjER/2N5xo2ZnLR7FEjM2bbcm8RJ452 3zJBfHTFP88sqG97/Ggl0jNUx7iSbT5ARv2keK1V3e4+JspbGXMGfEJ0UK3Kjuau b0CL1YFHXUbDE7cZi8yU+ZCoePWw7WxDXZu947TN7C4RHwRhmhRgDfUeG5xrLpNj WrsCdEtSca2+z0K9gvxunpyOZULp8lZZSL+0Mb4t55Z0sNOQHVBUsvlH1DKKCZIb o7IP2UHy6f9TAySOt8tqe8bBdykrB/0OYTvkJvXwiZKqdPqKhzT2T7Lsgu1xGxu3 FFssMi/zU6BrKfEPnbmj7Fipi/Y/PicQdzdRoMEz0HQ+brZB0ORbk2vJ1anTDC0E FwJLn/tPxSPWbs84UYi5 =lCOT -----END PGP SIGNATURE----- --R+My9LyyhiUvIEro--