From patchwork Tue Nov 24 13:15:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 331391 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp501546ilb; Tue, 24 Nov 2020 05:16:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzO3J1ZXoERJgRAS1t0hqR5G2zMfbMOS+FW5pzbt8TUfMrLoxuCkaCpGkgSd5uHetJPH3Y X-Received: by 2002:aa7:c3c4:: with SMTP id l4mr3940379edr.314.1606223800027; Tue, 24 Nov 2020 05:16:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606223800; cv=none; d=google.com; s=arc-20160816; b=ekxXBg/O/63BG9q77Q9aHvFufqkzp6NjQt96xaIw/it3L67QLA/etOQsnlw6oUGYdR ZW2I9d36XWqokpPK0yYo8+qR1Wl36RHAhnUlTv3McIUWQqxv5KkxClzCPVOMDnY3dW9H q+g9rSaqxjkKgY8WTN50Wa8f5eig6DHfDPELyGryZ1CG3IYF0GFfske2jalCOBK+axHl cvD9SWoArXU1F+UKWOmjfphmVF/WYDw5TY0eBNp6I7GPVmPCOEou0ItdqAgHmVXmEgId TxCjLF2dz0hX2LMpPN1rxxQLhOYShIeb9ErO0cF7Z6vgQWl+/adCZl7j+U2DdwBHiifi lG8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=VMIE5grJi+EGHjoSejoXX7yX4OEbolDjXuEvDM6rKGc=; b=bVaCia278KnpNEYT46ZNJVLeY1UddGqXblINq7GdjQ4H3+gNIDGE9KLgxAB1WF4a40 X01c8vCuTKUjlWXrreV6WE/j+STbo1K38VIGvKYpDry05n1O45wtYAi4wTUDLcwCmSeC a8V2Q3DJ5u87ijqZ6LH7P6SSrySD33jczDpKvRpQGhF75Q/glVdJXQyhW4+yzwsclTAB cTg2GCzr+FVDg1ZlpB4WMkvwJPgC3NZrLE829ecY3ptx6WgjnceREYc4y+P55idOC+kL +8XT125mjV3Ru2vos2WZULsbJblID+PBQA8+4qTfSQKQ17hRTzaN3O5E1fwwG1bZF74q T9Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OcOiESpg; spf=pass (google.com: domain of linux-spi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x17si10219069edq.475.2020.11.24.05.16.39; Tue, 24 Nov 2020 05:16:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-spi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=OcOiESpg; spf=pass (google.com: domain of linux-spi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387989AbgKXNPu (ORCPT + 1 other); Tue, 24 Nov 2020 08:15:50 -0500 Received: from mailout2.w1.samsung.com ([210.118.77.12]:47902 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387656AbgKXNPu (ORCPT ); Tue, 24 Nov 2020 08:15:50 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20201124131538euoutp0262020ebcaa81c1a31d8d15c28eda8ecd~Kc-rt9lLe0375803758euoutp02z for ; Tue, 24 Nov 2020 13:15:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20201124131538euoutp0262020ebcaa81c1a31d8d15c28eda8ecd~Kc-rt9lLe0375803758euoutp02z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1606223738; bh=VMIE5grJi+EGHjoSejoXX7yX4OEbolDjXuEvDM6rKGc=; h=From:To:Cc:Subject:Date:References:From; b=OcOiESpgCrygJ43lXwjTd3wiLRKZJUJBJklZxar05CWmg6hjs4vR9n7OWjhJj4Usv kGpEodTouU9qiRzFvADOHJfJbiqMBgXfTUvkeCVq/qJ6j58QkR+82SRygUAVhtQm2b cOz+HD2meDlcPBteh32fN5PsTuqH4eEAoJs9dNgw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20201124131533eucas1p270324139dfa5f41b960cfeb9d4ed0104~Kc-mpCAVX0811808118eucas1p2b; Tue, 24 Nov 2020 13:15:33 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 42.2F.44805.5770DBF5; Tue, 24 Nov 2020 13:15:33 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20201124131532eucas1p22f02c41a48e9768738b4529771ed7820~Kc-mL6iY00914609146eucas1p2T; Tue, 24 Nov 2020 13:15:32 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201124131532eusmtrp1d48af34344ab3485e6c66e463df95850~Kc-mLMjFm2366323663eusmtrp11; Tue, 24 Nov 2020 13:15:32 +0000 (GMT) X-AuditID: cbfec7f4-b37ff7000000af05-31-5fbd07752b63 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 0D.D7.16282.4770DBF5; Tue, 24 Nov 2020 13:15:32 +0000 (GMT) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20201124131532eusmtip209b157e09e83caa73c00236fff181a41~Kc-lx8Ufq0274902749eusmtip2s; Tue, 24 Nov 2020 13:15:32 +0000 (GMT) From: Marek Szyprowski To: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Mark Brown , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Greg Kroah-Hartman , Bartlomiej Zolnierkiewicz Subject: [PATCH] spi: Fix potential NULL pointer dereference in spi_shutdown() Date: Tue, 24 Nov 2020 14:15:23 +0100 Message-Id: <20201124131523.32287-1-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrIIsWRmVeSWpSXmKPExsWy7djP87ql7HvjDa6s5rTYOGM9q8XUh0/Y LJoXr2ezuLxrDptF48eb7BZrj9xlt7g9cTKjA7vHplWdbB77565h9+j/a+DRt2UVo8fnTXIB rFFcNimpOZllqUX6dglcGU8bNzEVPOauODZvLnMD41fOLkZODgkBE4nW/0fYuxi5OIQEVjBK nHjXwwrhfGGUWLhuGhuE85lRouPQCTaYlhdrNjBDJJYzSsxsn8oM13Ju4SlGkCo2AUOJrrdd YB0iAtYS32ZMAytiFmhlkrg3HaSdk0NYIEBiy6EHQNs5OFgEVCVabhaDhHkFbCX+Nx6F2iYv sXrDAbBeCYFGDokTDb+hEi4SE2fOZ4KwhSVeHd/CDmHLSJye3MMC0dDMKPHw3Fp2CKeHUeJy 0wxGiCpriTvnfrGBbGYW0JRYv0sfIuwoceXFOVaQsIQAn8SNt4IgYWYgc9K26cwQYV6JjjYh iGo1iVnH18GtPXjhElSJh8TVc8IgYSGBWIn9f66zT2CUm4WwagEj4ypG8dTS4tz01GKjvNRy veLE3OLSvHS95PzcTYzAVHD63/EvOxiXv/qod4iRiYPxEKMEB7OSCG+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DuCOfH/80TkbHBatF5EwCRHaK9Pvu rPscNzHif+cviaWlBzRnsvGdr3j3YbqboeBJNjPzYpNZ72Tt856e/n10m7OL6l2/ZW8FkqbN 2iC4mH+z+rwbF29dW7xNqO/JQ6GpS7x8ToUfiXF4JLfD0CP76aRr6zoWOiUv2nK3Oqao6pDB HdbGRKGNncsZ/VX7Np1uejtfvO/zovcX7knVnPL6YbBSOTDsZtEz9UliVXW2qncCHvIsYdDh ZZ943NpcS83Z9fuu64rJ23Yu08lZJxO5odSSdXvjEXuNHy3H9y42TH93Tj5rd0chs/xut29K LMUZiYZazEXFiQCf6Cx2ygIAAA== X-CMS-MailID: 20201124131532eucas1p22f02c41a48e9768738b4529771ed7820 X-Msg-Generator: CA X-RootMTR: 20201124131532eucas1p22f02c41a48e9768738b4529771ed7820 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20201124131532eucas1p22f02c41a48e9768738b4529771ed7820 References: Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org Shutdown bus function might be called on the unbound device, so add a check if there is a driver before calling its shutdown function. This fixes following kernel panic obserbed during system reboot: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018 ... 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 ]--- Fixes: 9db34ee64ce4 ("spi: Use bus_type functions for probe, remove and shutdown)" Signed-off-by: Marek Szyprowski --- drivers/spi/spi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 0c3f3a962448..cd3c395b4e90 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -426,10 +426,12 @@ static int spi_remove(struct device *dev) static void spi_shutdown(struct device *dev) { - const struct spi_driver *sdrv = to_spi_driver(dev->driver); + if (dev->driver) { + const struct spi_driver *sdrv = to_spi_driver(dev->driver); - if (sdrv->shutdown) - sdrv->shutdown(to_spi_device(dev)); + if (sdrv->shutdown) + sdrv->shutdown(to_spi_device(dev)); + } } struct bus_type spi_bus_type = {