LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Cc: Kay Sievers <kay.sievers@novell.com>,
Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 25/28] Driver core: add device_type to struct device
Date: Wed, 7 Feb 2007 16:30:13 -0800 [thread overview]
Message-ID: <11708947024054-git-send-email-greg@kroah.com> (raw)
In-Reply-To: <11708946993815-git-send-email-greg@kroah.com>
From: Kay Sievers <kay.sievers@novell.com>
This allows us to add type specific attributes, uevent vars and
release funtions.
A subsystem can carry different types of devices like the "block"
subsys has disks and partitions. Both types create a different set
of attributes, but belong to the same subsystem.
This corresponds to the low level objects:
kobject -> device (object/device data)
kobj_type -> device_type (type of object/device we are embedded in)
kset -> class/bus (list of objects/devices of a subsystem)
Signed-off-by: Kay Sievers <kay.sievers@novell.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/base/core.c | 57 ++++++++++++++++++++++++++++-------------
drivers/usb/input/hid-lgff.c | 4 +-
include/linux/device.h | 8 ++++++
3 files changed, 49 insertions(+), 20 deletions(-)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7a5336f..34ac187 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -95,6 +95,8 @@ static void device_release(struct kobject * kobj)
if (dev->release)
dev->release(dev);
+ else if (dev->type && dev->type->release)
+ dev->type->release(dev);
else if (dev->class && dev->class->dev_release)
dev->class->dev_release(dev);
else {
@@ -206,19 +208,25 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
if (dev->bus && dev->bus->uevent) {
/* have the bus specific function add its stuff */
retval = dev->bus->uevent(dev, envp, num_envp, buffer, buffer_size);
- if (retval) {
- pr_debug ("%s - uevent() returned %d\n",
+ if (retval)
+ pr_debug ("%s: bus uevent() returned %d\n",
__FUNCTION__, retval);
- }
}
if (dev->class && dev->class->dev_uevent) {
/* have the class specific function add its stuff */
retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size);
- if (retval) {
- pr_debug("%s - dev_uevent() returned %d\n",
- __FUNCTION__, retval);
- }
+ if (retval)
+ pr_debug("%s: class uevent() returned %d\n",
+ __FUNCTION__, retval);
+ }
+
+ if (dev->type && dev->type->uevent) {
+ /* have the device type specific fuction add its stuff */
+ retval = dev->type->uevent(dev, envp, num_envp, buffer, buffer_size);
+ if (retval)
+ pr_debug("%s: dev_type uevent() returned %d\n",
+ __FUNCTION__, retval);
}
return retval;
@@ -269,37 +277,50 @@ static void device_remove_groups(struct device *dev)
static int device_add_attrs(struct device *dev)
{
struct class *class = dev->class;
+ struct device_type *type = dev->type;
int error = 0;
int i;
- if (!class)
- return 0;
-
- if (class->dev_attrs) {
+ if (class && class->dev_attrs) {
for (i = 0; attr_name(class->dev_attrs[i]); i++) {
error = device_create_file(dev, &class->dev_attrs[i]);
if (error)
break;
}
+ if (error)
+ while (--i >= 0)
+ device_remove_file(dev, &class->dev_attrs[i]);
}
- if (error)
- while (--i >= 0)
- device_remove_file(dev, &class->dev_attrs[i]);
+
+ if (type && type->attrs) {
+ for (i = 0; attr_name(type->attrs[i]); i++) {
+ error = device_create_file(dev, &type->attrs[i]);
+ if (error)
+ break;
+ }
+ if (error)
+ while (--i >= 0)
+ device_remove_file(dev, &type->attrs[i]);
+ }
+
return error;
}
static void device_remove_attrs(struct device *dev)
{
struct class *class = dev->class;
+ struct device_type *type = dev->type;
int i;
- if (!class)
- return;
-
- if (class->dev_attrs) {
+ if (class && class->dev_attrs) {
for (i = 0; attr_name(class->dev_attrs[i]); i++)
device_remove_file(dev, &class->dev_attrs[i]);
}
+
+ if (type && type->attrs) {
+ for (i = 0; attr_name(type->attrs[i]); i++)
+ device_remove_file(dev, &type->attrs[i]);
+ }
}
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index e474662..4f4fc3b 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -32,7 +32,7 @@
#include <linux/hid.h>
#include "usbhid.h"
-struct device_type {
+struct dev_type {
u16 idVendor;
u16 idProduct;
const signed short *ff;
@@ -48,7 +48,7 @@ static const signed short ff_joystick[] = {
-1
};
-static const struct device_type devices[] = {
+static const struct dev_type devices[] = {
{ 0x046d, 0xc211, ff_rumble },
{ 0x046d, 0xc219, ff_rumble },
{ 0x046d, 0xc283, ff_joystick },
diff --git a/include/linux/device.h b/include/linux/device.h
index da72219..e1e164f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -328,6 +328,13 @@ extern struct class_device *class_device_create(struct class *cls,
__attribute__((format(printf,5,6)));
extern void class_device_destroy(struct class *cls, dev_t devt);
+struct device_type {
+ struct device_attribute *attrs;
+ int (*uevent)(struct device *dev, char **envp, int num_envp,
+ char *buffer, int buffer_size);
+ void (*release)(struct device *dev);
+};
+
/* interface for exporting device attributes */
struct device_attribute {
struct attribute attr;
@@ -356,6 +363,7 @@ struct device {
struct kobject kobj;
char bus_id[BUS_ID_SIZE]; /* position on parent bus */
+ struct device_type *type;
unsigned is_registered:1;
struct device_attribute uevent_attr;
struct device_attribute *devt_attr;
--
1.4.4.4
next prev parent reply other threads:[~2007-02-08 0:36 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-08 0:29 [GIT PATCH] Driver core patches for 2.6.20 Greg KH
2007-02-08 0:29 ` [PATCH 1/28] Kobject: make kobject apis more robust in handling NULL pointers Greg KH
2007-02-08 0:29 ` [PATCH 2/28] Driver core: convert pcmcia code to use struct device Greg KH
2007-02-08 0:29 ` [PATCH 3/28] Driver core: convert SPI " Greg KH
2007-02-08 0:29 ` [PATCH 4/28] Network: convert network devices to use struct device instead of class_device Greg KH
2007-02-08 0:29 ` [PATCH 5/28] driver core: Remove device_is_registered() in device_move() Greg KH
2007-02-08 0:29 ` [PATCH 6/28] driver core: Allow device_move(dev, NULL) Greg KH
2007-02-08 0:29 ` [PATCH 7/28] MODULES: add the module name for built in kernel drivers Greg KH
2007-02-08 0:29 ` [PATCH 8/28] Modules: only add drivers/ direcory if needed Greg KH
2007-02-08 0:29 ` [PATCH 9/28] PCI: add the sysfs driver name to all modules Greg KH
2007-02-08 0:29 ` [PATCH 10/28] SERIO: " Greg KH
2007-02-08 0:29 ` [PATCH 11/28] USB: " Greg KH
2007-02-08 0:30 ` [PATCH 12/28] /sys/modules/*/holders Greg KH
2007-02-08 0:30 ` [PATCH 13/28] driver core fixes: make_class_name() retval checks Greg KH
2007-02-08 0:30 ` [PATCH 14/28] driver core fixes: device_register() retval check in platform.c Greg KH
2007-02-08 0:30 ` [PATCH 15/28] driver core: Don't stop probing on ->probe errors Greg KH
2007-02-08 0:30 ` [PATCH 16/28] driver core: Change function call order in device_bind_driver() Greg KH
2007-02-08 0:30 ` [PATCH 17/28] Driver core: fix race in sysfs between sysfs_remove_file() and read()/write() Greg KH
2007-02-08 0:30 ` [PATCH 18/28] sysfs: suppress lockdep warnings Greg KH
2007-02-08 0:30 ` [PATCH 19/28] sysfs: kobject_put cleanup Greg KH
2007-02-08 0:30 ` [PATCH 20/28] kobject: " Greg KH
2007-02-08 0:30 ` [PATCH 21/28] sysfs: error handling in sysfs, fill_read_buffer() Greg KH
2007-02-08 0:30 ` [PATCH 22/28] HOWTO: Add a reference to Harbison and Steele Greg KH
2007-02-08 0:30 ` [PATCH 23/28] SYSFS: Fix missing include of list.h in sysfs.h Greg KH
2007-02-08 0:30 ` [PATCH 24/28] Driver core: add uevent vars for devices of a class Greg KH
2007-02-08 0:30 ` Greg KH [this message]
2007-02-08 0:30 ` [PATCH 26/28] Driver core: allow to delay the uevent at device creation time Greg KH
2007-02-08 0:30 ` [PATCH 27/28] Driver Core: Increase the default timeout value of the firmware subsystem Greg KH
2007-02-08 0:30 ` [PATCH 28/28] sysfs: Shadow directory support Greg KH
2007-02-08 17:20 ` [PATCH 10/28] SERIO: add the sysfs driver name to all modules Dmitry Torokhov
2007-02-08 18:51 ` Greg KH
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=11708947024054-git-send-email-greg@kroah.com \
--to=greg@kroah.com \
--cc=gregkh@suse.de \
--cc=kay.sievers@novell.com \
--cc=linux-kernel@vger.kernel.org \
--subject='Re: [PATCH 25/28] Driver core: add device_type to struct device' \
/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
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).