From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751375AbdBMAgX (ORCPT ); Sun, 12 Feb 2017 19:36:23 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34352 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751000AbdBMAgW (ORCPT ); Sun, 12 Feb 2017 19:36:22 -0500 From: Dmitry Torokhov To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH 1/2] driver core: emit uevents when device is bound to a driver Date: Sun, 12 Feb 2017 16:36:18 -0800 Message-Id: <20170213003619.4083-1-dmitry.torokhov@gmail.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Majority of standard for a subsystem device attributes are created at the same time devices are created, before KOBJECT_ADD uevent is emitted by the driver core. This means that attributes are there when userspace is notified about new device appearance. However many drivers create additional driver-specific device attributes when binding to the device, to provide userspace with additional controls, and such attributes may not be there yet when userpsace receives KOBJECT_ADD event. Changing the drivers to introduce intermediate "dummy" device as a container for such attributes would be wasteful, and in many cases, braking our sysfs ABI. Let's add a new event, KOBJECT_BIND (and its counterpart, KOBJECT_UNBIND) that is emitted after a driver is bound to a device. It can be used by userspace wishing to use driver-specific attributes of a device. Signed-off-by: Dmitry Torokhov --- drivers/base/dd.c | 4 ++++ include/linux/kobject.h | 2 ++ lib/kobject_uevent.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index a1fbf55c4d3a..a9a5cc0560e5 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -258,6 +258,8 @@ static void driver_bound(struct device *dev) if (dev->bus) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_BOUND_DRIVER, dev); + + kobject_uevent(&dev->kobj, KOBJ_BIND); } static int driver_sysfs_add(struct device *dev) @@ -839,6 +841,8 @@ static void __device_release_driver(struct device *dev, struct device *parent) blocking_notifier_call_chain(&dev->bus->p->bus_notifier, BUS_NOTIFY_UNBOUND_DRIVER, dev); + + kobject_uevent(&dev->kobj, KOBJ_UNBIND); } } diff --git a/include/linux/kobject.h b/include/linux/kobject.h index e6284591599e..07292df4776e 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -57,6 +57,8 @@ enum kobject_action { KOBJ_MOVE, KOBJ_ONLINE, KOBJ_OFFLINE, + KOBJ_BIND, + KOBJ_UNBIND, KOBJ_MAX }; diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 9a2b811966eb..4682e8545b5c 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -50,6 +50,8 @@ static const char *kobject_actions[] = { [KOBJ_MOVE] = "move", [KOBJ_ONLINE] = "online", [KOBJ_OFFLINE] = "offline", + [KOBJ_BIND] = "bind", + [KOBJ_UNBIND] = "unbind", }; /** -- 2.11.0.483.g087da7b7c-goog