Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp562899ybt; Wed, 8 Jul 2020 06:34:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7FrukOVYKVuGme6RrHvF/bH86aLb9AtVtUuzQYwVb+ZinKSSfWQYkKfZlSuu5IkwrL5QI X-Received: by 2002:a50:fd12:: with SMTP id i18mr68528202eds.371.1594215274207; Wed, 08 Jul 2020 06:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594215274; cv=none; d=google.com; s=arc-20160816; b=zeHUv7pEOG1Mp7xFOhZLGz45oidrSVmOWGXZj1U7c8agTfEGQuZlau5KisEW7gzjFr y0kIlhcgwd6yoFh1HkVeaEH3V4jU6fYNoudFSe17ss2uZsQq48b+EODGwrGgX/K2s3vA lFcpTka71ziMvSlLNr4Mw5IFGFAua1gGlDo1ACEElXNuYNoIXDD+At6km7+NE1Y1uDoY F/pRUcKRYye7Qugax/qhUNpEJJDaqYLFfnPV2yNgy/rfUITlULsr6y9P08Tegu/4zi0p /PNFAEcS1A8kz1A50OMWiUc05KlEL1SkT+A0dCRtnAL4Dhb7F7FR0sk0OvFDva974tNT PPtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:references :in-reply-to:message-id; bh=rvlGs5L+fcLSMx25av8inLnYaLEzTNgrFs3vLBoOBik=; b=PTrpG/pPTwWlFFVe78hdKp0aCAg/7c3yoKBlCjuDcQ+2HhvIp6akQsGOIoIZzF5/FW /kV1so/uiAy7nZgb96HoVau7PH1pVDHfUkwT7OwKh/b4Y2kssBXsZ33Eu0RRpEP33XuD uLlAYyGnhIv6oxgFWO0dWAC7SY6Bv+6+bHgIH/puCUjiRNirgmuD+VbKKL33p8pqTuT5 qjmQzNjpsmQmcjOAWfYYjqqoaSLEntv1g63gmDZi5G7VhEcIfXvg1tKGdQd/V0GDfsn3 22Sfb/p6tadYgQvKOvqWAJ0dkIl2IpOsbVj1/5hD3RNpRJ+7aiiA//hU9cvkSBzIn9Rx YD3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q5si16869235ejm.661.2020.07.08.06.34.11; Wed, 08 Jul 2020 06:34:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729366AbgGHNd0 (ORCPT + 99 others); Wed, 8 Jul 2020 09:33:26 -0400 Received: from mailout3.hostsharing.net ([176.9.242.54]:40963 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729136AbgGHNd0 (ORCPT ); Wed, 8 Jul 2020 09:33:26 -0400 X-Greylist: delayed 4851 seconds by postgrey-1.27 at vger.kernel.org; Wed, 08 Jul 2020 09:33:25 EDT Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id 34935101E69A5; Wed, 8 Jul 2020 15:33:23 +0200 (CEST) Received: from localhost (unknown [87.130.102.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id C340F6106EC8; Wed, 8 Jul 2020 15:33:22 +0200 (CEST) X-Mailbox-Line: From de88a23a6fe0ef70f7cfd13c8aea9ab51b4edab6 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Lukas Wunner Date: Wed, 8 Jul 2020 15:27:01 +0200 Subject: [PATCH 1/3] driver core: Avoid binding drivers to dead devices To: Greg Kroah-Hartman Cc: "Rafael J. Wysocki" , Dan Williams , Geert Uytterhoeven , Pantelis Antoniou , Alexander Duyck , Mark Brown , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 3451a495ef24 ("driver core: Establish order of operations for device_add and device_del via bitflag") sought to prevent asynchronous driver binding to a device which is being removed. It added a per-device "dead" flag which is checked in the following code paths: * asynchronous binding in __driver_attach_async_helper() * synchronous binding in device_driver_attach() * asynchronous binding in __device_attach_async_helper() It did *not* check the flag upon: * synchronous binding in __device_attach() However __device_attach() may also be called asynchronously from: deferred_probe_work_func() bus_probe_device() device_initial_probe() __device_attach() So if the commit's intention was to check the "dead" flag in all asynchronous code paths, then a check is also necessary in __device_attach(). Add the missing check. Fixes: 3451a495ef24 ("driver core: Establish order of operations for device_add and device_del via bitflag") Signed-off-by: Lukas Wunner Cc: stable@vger.kernel.org # v5.1+ Cc: Alexander Duyck --- drivers/base/dd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 9a1d940342ac4..31c668651e824 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -848,7 +848,9 @@ static int __device_attach(struct device *dev, bool allow_async) int ret = 0; device_lock(dev); - if (dev->driver) { + if (dev->p->dead) { + goto out_unlock; + } else if (dev->driver) { if (device_is_bound(dev)) { ret = 1; goto out_unlock; -- 2.27.0