Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5945236ybi; Wed, 31 Jul 2019 05:55:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsmUQM+/NnamXWAt7d10QhHJVkM6co34/K+1F/Q2W6IMyWXBtu745KJnPVUgStREf2ajHR X-Received: by 2002:a65:50c8:: with SMTP id s8mr74090317pgp.339.1564577734446; Wed, 31 Jul 2019 05:55:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564577734; cv=none; d=google.com; s=arc-20160816; b=fgu3hbftmDEWg9CNBJ5gsqCZLveR9D/wv/IzcRTcMQCrNWXGn2U6ZAQfTsnzTFvEag GifYo2DcFin9nHpkStirkfF51svZWb7m7/OMd3jcPRWW1ES2VZaYDX5HrdKPZO6bsnf9 Q5IM/ehs9px0L1NP6Xp8cbJOjUDz1T98Enc1/zFam/5y46dp53Jn5HH5xFUa4Mu1EAD4 t5X/kS+C/ZjvPFHZZB2NjEaa1uue8ntSamGG4m4VmvyuCGeVZnjlM1MHuIshjFbKak2e 14nqGDF1qhQZUZToRLOqGDcGk1HERsJ9LKNt6AgSVaoM4IhQX3NeBrnQUfnI9syvgidX M/9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8i/dmpZbUdS0O/bo6P9TYxLTWNRZahRc5Oy9fk4Gu7A=; b=c+Q4lgEa9ghIC0UMSvVRiTQ14suin2XLz94XaMfXYu34x/jR4js8sD5Ld6/x15Qfc8 JiZRy2tMR9KEDdKd3Bwke2mTP+n0S89P6hoi3v5UnspUm/fEi30FDEtrhaLY1Xw36/aU OqogxSPLEZ9/Ou1XkrlqcRxFznGv7Np4sTnAPb2PYF0ewyWDZXYbqH67xgnnDY6sQqSt C36Htv/3TsFA3eCPQkB/fwSwSN1REfLXpaQjkE5OrBtFbiCVcBqAXY4PRvjY3V/6eFtA NOx9MIlJIFEGb5sO5GwIZjHuqV44TdQqWGRJnbyClLd6XrwTj/uW6tyATEgoSLNR6SaS TbRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1uw509b3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si29363521plq.125.2019.07.31.05.55.19; Wed, 31 Jul 2019 05:55:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1uw509b3; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387800AbfGaMoH (ORCPT + 99 others); Wed, 31 Jul 2019 08:44:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:36274 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbfGaMoD (ORCPT ); Wed, 31 Jul 2019 08:44:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4AD9C208E3; Wed, 31 Jul 2019 12:44:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564577042; bh=7reqGB1oneZIvnBYyl+e01KzuP0iwc/xUA6OSeWmXBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1uw509b3gXm5yAW7uuB6EetTqGB8HhRpSMLiG7Ppjay2X6HdPFbCqVbsExJkmR5cy SlAEWEwBJhVHks+EvZdNNwwSNTheqZqcu/Icf1qd42ezG8Z2bh0MlIj3YrHzX2XqPl kJ95oL8TKrHzSGo/l1xsd/hFpBh/5pCbywFgNusM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, Richard Gong , Dmitry Torokhov Cc: Greg Kroah-Hartman Subject: [PATCH v2 01/10] driver core: add dev_groups to all drivers Date: Wed, 31 Jul 2019 14:43:40 +0200 Message-Id: <20190731124349.4474-2-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190731124349.4474-1-gregkh@linuxfoundation.org> References: <20190731124349.4474-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dmitry Torokhov Add the ability for the driver core to create and remove a list of attribute groups automatically when the device is bound/unbound from a specific driver. Signed-off-by: Greg Kroah-Hartman --- drivers/base/dd.c | 14 ++++++++++++++ include/linux/device.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 994a90747420..d811e60610d3 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -554,9 +554,16 @@ static int really_probe(struct device *dev, struct device_driver *drv) goto probe_failed; } + if (device_add_groups(dev, drv->dev_groups)) { + dev_err(dev, "device_add_groups() failed\n"); + goto dev_groups_failed; + } + if (test_remove) { test_remove = false; + device_remove_groups(dev, drv->dev_groups); + if (dev->bus->remove) dev->bus->remove(dev); else if (drv->remove) @@ -584,6 +591,11 @@ static int really_probe(struct device *dev, struct device_driver *drv) drv->bus->name, __func__, dev_name(dev), drv->name); goto done; +dev_groups_failed: + if (dev->bus->remove) + dev->bus->remove(dev); + else if (drv->remove) + drv->remove(dev); probe_failed: if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, @@ -1114,6 +1126,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) pm_runtime_put_sync(dev); + device_remove_groups(dev, drv->dev_groups); + if (dev->bus && dev->bus->remove) dev->bus->remove(dev); else if (drv->remove) diff --git a/include/linux/device.h b/include/linux/device.h index c330b75c6c57..98c00b71b598 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -262,6 +262,8 @@ enum probe_type { * @resume: Called to bring a device from sleep mode. * @groups: Default attributes that get created by the driver core * automatically. + * @dev_groups: Additional attributes attached to device instance once the + * it is bound to the driver. * @pm: Power management operations of the device which matched * this driver. * @coredump: Called when sysfs entry is written to. The device driver @@ -296,6 +298,7 @@ struct device_driver { int (*suspend) (struct device *dev, pm_message_t state); int (*resume) (struct device *dev); const struct attribute_group **groups; + const struct attribute_group **dev_groups; const struct dev_pm_ops *pm; void (*coredump) (struct device *dev); -- 2.22.0