linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	linux-kernel@vger.kernel.org, kernel@pengutronix.de,
	linux-spi@vger.kernel.org
Subject: Re: [PATCH v2 2/3] spi: Use bus_type functions for probe, remove and shutdown
Date: Tue, 24 Nov 2020 14:01:07 +0100	[thread overview]
Message-ID: <20201124130107.2yvgk7kheep5gd6z@pengutronix.de> (raw)
In-Reply-To: <9b86504f-c5f4-4c85-9bef-3d1ee4cbaf9c@samsung.com>

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

Hello Marek,

On Tue, Nov 24, 2020 at 01:03:25PM +0100, Marek Szyprowski wrote:
> On 19.11.2020 17:16, Uwe Kleine-König wrote:
> > The eventual goal is to get rid of the callbacks in struct
> > device_driver. Other than not using driver callbacks there should be no
> > side effect of this patch.
> >
> > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> 
> This patch landed recently in linux-next as commit 9db34ee64ce4 ("spi: 
> Use bus_type functions for probe, remove and shutdown").
> 
> It causes a regression on some of my test boards:
> 
> Unable to handle kernel NULL pointer dereference at virtual address 
> 0000000000000018
> Mem abort info:
>    ESR = 0x96000004
>    EC = 0x25: DABT (current EL), IL = 32 bits
>    SET = 0, FnV = 0
>    EA = 0, S1PTW = 0
> Data abort info:
>    ISV = 0, ISS = 0x00000004
>    CM = 0, WnR = 0
> user pgtable: 4k pages, 48-bit VAs, pgdp=00000000318ed000
> [0000000000000018] pgd=0000000000000000, p4d=0000000000000000
> Internal error: Oops: 96000004 [#1] PREEMPT SMP
> Modules linked in: cpufreq_powersave cpufreq_conservative brcmfmac 
> brcmutil cfg80211 crct10dif_ce s3fwrn5_i2c s3fwrn5 nci nfc s5p_mfc 
> s5p_jpeg hci_uart btqca btbc
> buf2_dma_contig videobuf2_memops videobuf2_v4l2 bluetooth 
> videobuf2_common videodev panfrost gpu_sched ecdh_generic mc ecc rfkill 
> ip_tables x_tables ipv6
> CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted 
> 5.10.0-rc5-next-20201124+ #9771
> Hardware name: Samsung TM2E board (DT)
> pstate: 60000005 (nZCv daif -PAN -UAO -TCO BTYPE=--)
> pc : spi_shutdown+0x10/0x38
> lr : device_shutdown+0x10c/0x350
> sp : ffff80001311bc70
> ...
> Call trace:
>   spi_shutdown+0x10/0x38
>   kernel_restart_prepare+0x34/0x40
>   kernel_restart+0x14/0x88
>   __do_sys_reboot+0x148/0x248
>   __arm64_sys_reboot+0x1c/0x28
>   el0_svc_common.constprop.3+0x74/0x198
>   do_el0_svc+0x20/0x98
>   el0_sync_handler+0x140/0x1a8
>   el0_sync+0x140/0x180
> Code: f9403402 d1008041 f100005f 9a9f1021 (f9400c21)
> ---[ end trace 266c07205a2d632e ]---
> Kernel panic - not syncing: Oops: Fatal exception
> Kernel Offset: disabled
> CPU features: 0x0240022,65006087
> Memory Limit: none
> ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---
> 
> > ---
> >   drivers/spi/spi.c | 33 ++++++++++++++++-----------------
> >   1 file changed, 16 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> > index 5becf6c2c409..e8c0a000ee19 100644
> > --- a/drivers/spi/spi.c
> > +++ b/drivers/spi/spi.c
> > @@ -374,16 +374,7 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env)
> >   	return add_uevent_var(env, "MODALIAS=%s%s", SPI_MODULE_PREFIX, spi->modalias);
> >   }
> >   
> > -struct bus_type spi_bus_type = {
> > -	.name		= "spi",
> > -	.dev_groups	= spi_dev_groups,
> > -	.match		= spi_match_device,
> > -	.uevent		= spi_uevent,
> > -};
> > -EXPORT_SYMBOL_GPL(spi_bus_type);
> > -
> > -
> > -static int spi_drv_probe(struct device *dev)
> > +static int spi_probe(struct device *dev)
> >   {
> >   	const struct spi_driver		*sdrv = to_spi_driver(dev->driver);
> >   	struct spi_device		*spi = to_spi_device(dev);
> > @@ -414,7 +405,7 @@ static int spi_drv_probe(struct device *dev)
> >   	return ret;
> >   }
> >   
> > -static int spi_drv_remove(struct device *dev)
> > +static int spi_remove(struct device *dev)
> >   {
> >   	const struct spi_driver		*sdrv = to_spi_driver(dev->driver);
> >   	int ret = 0;
> > @@ -426,13 +417,25 @@ static int spi_drv_remove(struct device *dev)
> >   	return ret;
> >   }
> >   
> > -static void spi_drv_shutdown(struct device *dev)
> > +static void spi_shutdown(struct device *dev)
> >   {
> >   	const struct spi_driver		*sdrv = to_spi_driver(dev->driver);
> >   
> > -	sdrv->shutdown(to_spi_device(dev));
> > +	if (sdrv->shutdown)
> > +		sdrv->shutdown(to_spi_device(dev));
> >   }
> 
> In the above function dev->driver might be NULL, so its use in 
> to_spi_driver() and sdrv->shutdown leads to NULL pointer dereference. I 
> didn't check the details, but a simple check for NULL dev->driver and 
> return is enough to fix this issue. I can send such fix if you want.

Ah, I see. shutdown is called for unbound devices, too. Assuming that
Mark prefers a fix on top instead of an updated patch: Yes, please send
a fix. Otherwise I can do this, too, as I introduced the problem.

Best regards and thanks,
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-11-24 13:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-19 16:16 [PATCH v2 1/3] spi: fix resource leak for drivers without .remove callback Uwe Kleine-König
2020-11-19 16:16 ` [PATCH v2 2/3] spi: Use bus_type functions for probe, remove and shutdown Uwe Kleine-König
     [not found]   ` <CGME20201124120324eucas1p189ec6eed6d6477e27a194f9d75d7b43a@eucas1p1.samsung.com>
2020-11-24 12:03     ` Marek Szyprowski
2020-11-24 13:01       ` Uwe Kleine-König [this message]
2020-11-24 13:31         ` Mark Brown
2020-11-19 16:16 ` [PATCH v2 3/3] spi: Warn when a driver's remove callback returns an error Uwe Kleine-König

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=20201124130107.2yvgk7kheep5gd6z@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=b.zolnierkie@samsung.com \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=m.szyprowski@samsung.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;
as well as URLs for NNTP newsgroup(s).