Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-cor…
Browse files Browse the repository at this point in the history
…e-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (28 commits)
  driver core: device_rename's new_name can be const
  sysfs: Remove owner field from sysfs struct attribute
  powerpc/pci: Remove owner field from attribute initialization in PCI bridge init
  regulator: Remove owner field from attribute initialization in regulator core driver
  leds: Remove owner field from attribute initialization in bd2802 driver
  scsi: Remove owner field from attribute initialization in ARCMSR driver
  scsi: Remove owner field from attribute initialization in LPFC driver
  cgroupfs: create /sys/fs/cgroup to mount cgroupfs on
  Driver core: Add BUS_NOTIFY_BIND_DRIVER
  driver core: fix memory leak on one error path in bus_register()
  debugfs: no longer needs to depend on SYSFS
  sysfs: Fix one more signature discrepancy between sysfs implementation and docs.
  sysfs: fix discrepancies between implementation and documentation
  dcdbas: remove a redundant smi_data_buf_free in dcdbas_exit
  dmi-id: fix a memory leak in dmi_id_init error path
  sysfs: sysfs_chmod_file's attr can be const
  firmware: Update hotplug script
  Driver core: move platform device creation helpers to .init.text (if MODULE=n)
  Driver core: reduce duplicated code for platform_device creation
  Driver core: use kmemdup in platform_device_add_resources
  ...
  • Loading branch information
torvalds committed Aug 6, 2010
2 parents c513b67 + 6937e8f commit ab69bcd
Show file tree
Hide file tree
Showing 26 changed files with 288 additions and 290 deletions.
1 change: 1 addition & 0 deletions Documentation/DocBook/device-drivers.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ X!Edrivers/base/attribute_container.c
<!--
X!Edrivers/base/interface.c
-->
!Iinclude/linux/platform_device.h
!Edrivers/base/platform.c
!Edrivers/base/bus.c
</sect1>
Expand Down
46 changes: 26 additions & 20 deletions Documentation/filesystems/sysfs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sysfs - _The_ filesystem for exporting kernel objects.
Patrick Mochel <[email protected]>
Mike Murphy <[email protected]>

Revised: 22 February 2009
Revised: 15 July 2010
Original: 10 January 2003


Expand Down Expand Up @@ -124,7 +124,7 @@ show and store methods of the attribute owners.

struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *, char *);
ssize_t (*store)(struct kobject *, struct attribute *, const char *);
ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
};

[ Subsystems should have already defined a struct kobj_type as a
Expand All @@ -139,18 +139,22 @@ calls the associated methods.

To illustrate:

#define to_dev(obj) container_of(obj, struct device, kobj)
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
#define to_dev(d) container_of(d, struct device, kobj)

static ssize_t
dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
struct device_attribute * dev_attr = to_dev_attr(attr);
struct device * dev = to_dev(kobj);
ssize_t ret = 0;
struct device_attribute *dev_attr = to_dev_attr(attr);
struct device *dev = to_dev(kobj);
ssize_t ret = -EIO;

if (dev_attr->show)
ret = dev_attr->show(dev, buf);
ret = dev_attr->show(dev, dev_attr, buf);
if (ret >= (ssize_t)PAGE_SIZE) {
print_symbol("dev_attr_show: %s returned bad count\n",
(unsigned long)dev_attr->show);
}
return ret;
}

Expand All @@ -163,10 +167,9 @@ To read or write attributes, show() or store() methods must be
specified when declaring the attribute. The method types should be as
simple as those defined for device attributes:

ssize_t (*show)(struct device * dev, struct device_attribute * attr,
char * buf);
ssize_t (*store)(struct device * dev, struct device_attribute * attr,
const char * buf);
ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);

IOW, they should take only an object, an attribute, and a buffer as parameters.

Expand Down Expand Up @@ -209,8 +212,8 @@ Other notes:

- show() should always use snprintf().

- store() should return the number of bytes used from the buffer. This
can be done using strlen().
- store() should return the number of bytes used from the buffer. If the
entire buffer has been used, just return the count argument.

- show() or store() can always return errors. If a bad value comes
through, be sure to return an error.
Expand All @@ -223,15 +226,18 @@ Other notes:

A very simple (and naive) implementation of a device attribute is:

static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
static ssize_t show_name(struct device *dev, struct device_attribute *attr,
char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", dev->name);
}

static ssize_t store_name(struct device * dev, const char * buf)
static ssize_t store_name(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
sscanf(buf, "%20s", dev->name);
return strnlen(buf, PAGE_SIZE);
snprintf(dev->name, sizeof(dev->name), "%.*s",
(int)min(count, sizeof(dev->name) - 1), buf);
return count;
}

static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
Expand Down Expand Up @@ -327,7 +333,7 @@ Structure:
struct bus_attribute {
struct attribute attr;
ssize_t (*show)(struct bus_type *, char * buf);
ssize_t (*store)(struct bus_type *, const char * buf);
ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
};

Declaring:
Expand Down
17 changes: 9 additions & 8 deletions Documentation/firmware_class/hotplug-script
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

HOTPLUG_FW_DIR=/usr/lib/hotplug/firmware/

echo 1 > /sys/$DEVPATH/loading
cat $HOTPLUG_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
echo 0 > /sys/$DEVPATH/loading

# To cancel the load in case of error:
#
# echo -1 > /sys/$DEVPATH/loading
#
if [ "$SUBSYSTEM" == "firmware" -a "$ACTION" == "add" ]; then
if [ -f $HOTPLUG_FW_DIR/$FIRMWARE ]; then
echo 1 > /sys/$DEVPATH/loading
cat $HOTPLUG_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
echo 0 > /sys/$DEVPATH/loading
else
echo -1 > /sys/$DEVPATH/loading
fi
fi
1 change: 0 additions & 1 deletion arch/powerpc/sysdev/mv64x60_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static struct bin_attribute mv64x60_hs_reg_attr = { /* Hotswap register */
.attr = {
.name = "hs_reg",
.mode = S_IRUGO | S_IWUSR,
.owner = THIS_MODULE,
},
.size = MV64X60_VAL_LEN_MAX,
.read = mv64x60_hs_reg_read,
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,8 @@ int bus_register(struct bus_type *bus)
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
kset_unregister(&bus->p->subsys);
kfree(bus->p);
out:
kfree(bus->p);
bus->p = NULL;
return retval;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ EXPORT_SYMBOL_GPL(device_destroy);
* on the same device to ensure that new_name is valid and
* won't conflict with other devices.
*/
int device_rename(struct device *dev, char *new_name)
int device_rename(struct device *dev, const char *new_name)
{
char *old_class_name = NULL;
char *new_class_name = NULL;
Expand Down
4 changes: 4 additions & 0 deletions drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static int driver_sysfs_add(struct device *dev)
{
int ret;

if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_BIND_DRIVER, dev);

ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
kobject_name(&dev->kobj));
if (ret == 0) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

struct dma_coherent_mem {
void *virt_base;
u32 device_base;
dma_addr_t device_base;
int size;
int flags;
unsigned long *bitmap;
Expand Down
Loading

0 comments on commit ab69bcd

Please sign in to comment.