Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc690d8e authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (61 commits)
  sysfs: add parameter "struct bin_attribute *" in .read/.write methods for sysfs binary attributes
  sysfs: make directory dentries and inodes reclaimable
  sysfs: implement sysfs_get_dentry()
  sysfs: move sysfs_drop_dentry() to dir.c and make it static
  sysfs: restructure add/remove paths and fix inode update
  sysfs: use sysfs_mutex to protect the sysfs_dirent tree
  sysfs: consolidate sysfs spinlocks
  sysfs: make kobj point to sysfs_dirent instead of dentry
  sysfs: implement sysfs_find_dirent() and sysfs_get_dirent()
  sysfs: implement SYSFS_FLAG_REMOVED flag
  sysfs: rename sysfs_dirent->s_type to s_flags and make room for flags
  sysfs: make sysfs_drop_dentry() access inodes using ilookup()
  sysfs: Fix oops in sysfs_drop_dentry on x86_64
  sysfs: use singly-linked list for sysfs_dirent tree
  sysfs: slim down sysfs_dirent->s_active
  sysfs: move s_active functions to fs/sysfs/dir.c
  sysfs: fix root sysfs_dirent -> root dentry association
  sysfs: use iget_locked() instead of new_inode()
  sysfs: reorganize sysfs_new_indoe() and sysfs_create()
  sysfs: fix parent refcounting during rename and move
  ...
parents 57399ec9 91a69029
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ static CLASS_DEVICE_ATTR(loading, 0644,
			 firmware_loading_show, firmware_loading_store);

static ssize_t firmware_data_read(struct kobject *kobj,
				  struct bin_attribute *bin_attr,
				  char *buffer, loff_t offset, size_t count)
{
	struct class_device *class_dev = to_class_dev(kobj);
@@ -88,6 +89,7 @@ static ssize_t firmware_data_read(struct kobject *kobj,
	return count;
}
static ssize_t firmware_data_write(struct kobject *kobj,
				   struct bin_attribute *bin_attr,
				   char *buffer, loff_t offset, size_t count)
{
	struct class_device *class_dev = to_class_dev(kobj);
+166 −0
Original line number Diff line number Diff line
Rules on how to access information in the Linux kernel sysfs

The kernel exported sysfs exports internal kernel implementation-details
and depends on internal kernel structures and layout. It is agreed upon
by the kernel developers that the Linux kernel does not provide a stable
internal API. As sysfs is a direct export of kernel internal
structures, the sysfs interface can not provide a stable interface eighter,
it may always change along with internal kernel changes.

To minimize the risk of breaking users of sysfs, which are in most cases
low-level userspace applications, with a new kernel release, the users
of sysfs must follow some rules to use an as abstract-as-possible way to
access this filesystem. The current udev and HAL programs already
implement this and users are encouraged to plug, if possible, into the
abstractions these programs provide instead of accessing sysfs
directly.

But if you really do want or need to access sysfs directly, please follow
the following rules and then your programs should work with future
versions of the sysfs interface.

- Do not use libsysfs
  It makes assumptions about sysfs which are not true. Its API does not
  offer any abstraction, it exposes all the kernel driver-core
  implementation details in its own API. Therefore it is not better than
  reading directories and opening the files yourself.
  Also, it is not actively maintained, in the sense of reflecting the
  current kernel-development. The goal of providing a stable interface
  to sysfs has failed, it causes more problems, than it solves. It
  violates many of the rules in this document.

- sysfs is always at /sys
  Parsing /proc/mounts is a waste of time. Other mount points are a
  system configuration bug you should not try to solve. For test cases,
  possibly support a SYSFS_PATH environment variable to overwrite the
  applications behavior, but never try to search for sysfs. Never try
  to mount it, if you are not an early boot script.

- devices are only "devices"
  There is no such thing like class-, bus-, physical devices,
  interfaces, and such that you can rely on in userspace. Everything is
  just simply a "device". Class-, bus-, physical, ... types are just
  kernel implementation details, which should not be expected by
  applications that look for devices in sysfs.

  The properties of a device are:
    o devpath (/devices/pci0000:00/0000:00:1d.1/usb2/2-2/2-2:1.0)
      - identical to the DEVPATH value in the event sent from the kernel
        at device creation and removal
      - the unique key to the device at that point in time
      - the kernels path to the device-directory without the leading
        /sys, and always starting with with a slash
      - all elements of a devpath must be real directories. Symlinks
        pointing to /sys/devices must always be resolved to their real
        target, and the target path must be used to access the device.
        That way the devpath to the device matches the devpath of the
        kernel used at event time.
      - using or exposing symlink values as elements in a devpath string
        is a bug in the application

    o kernel name (sda, tty, 0000:00:1f.2, ...)
      - a directory name, identical to the last element of the devpath
      - applications need to handle spaces and characters like '!' in
        the name

    o subsystem (block, tty, pci, ...)
      - simple string, never a path or a link
      - retrieved by reading the "subsystem"-link and using only the
        last element of the target path

    o driver (tg3, ata_piix, uhci_hcd)
      - a simple string, which may contain spaces, never a path or a
        link
      - it is retrieved by reading the "driver"-link and using only the
        last element of the target path
      - devices which do not have "driver"-link, just do not have a
        driver; copying the driver value in a child device context, is a
        bug in the application

    o attributes
      - the files in the device directory or files below a subdirectories
        of the same device directory
      - accessing attributes reached by a symlink pointing to another device,
        like the "device"-link, is a bug in the application

  Everything else is just a kernel driver-core implementation detail,
  that should not be assumed to be stable across kernel releases.

- Properties of parent devices never belong into a child device.
  Always look at the parent devices themselves for determining device
  context properties. If the device 'eth0' or 'sda' does not have a
  "driver"-link, then this device does not have a driver. Its value is empty.
  Never copy any property of the parent-device into a child-device. Parent
  device-properties may change dynamically without any notice to the
  child device.

- Hierarchy in a single device-tree
  There is only one valid place in sysfs where hierarchy can be examined
  and this is below: /sys/devices.
  It is planned, that all device directories will end up in the tree
  below this directory.

- Classification by subsystem
  There are currently three places for classification of devices:
  /sys/block, /sys/class and /sys/bus. It is planned that these will
  not contain any device-directories themselves, but only flat lists of
  symlinks pointing to the unified /sys/devices tree.
  All three places have completely different rules on how to access
  device information. It is planned to merge all three
  classification-directories into one place at /sys/subsystem,
  following the layout of the bus-directories. All buses and
  classes, including the converted block-subsystem, will show up
  there.
  The devices belonging to a subsystem will create a symlink in the
  "devices" directory at /sys/subsystem/<name>/devices.

  If /sys/subsystem exists, /sys/bus, /sys/class and /sys/block can be
  ignored. If it does not exist, you have always to scan all three
  places, as the kernel is free to move a subsystem from one place to
  the other, as long as the devices are still reachable by the same
  subsystem name.

  Assuming /sys/class/<subsystem> and /sys/bus/<subsystem>, or
  /sys/block and /sys/class/block are not interchangeable, is a bug in
  the application.

- Block
  The converted block-subsystem at /sys/class/block, or
  /sys/subsystem/block will contain the links for disks and partitions
  at the same level, never in a hierarchy. Assuming the block-subsytem to
  contain only disks and not partition-devices in the same flat list is
  a bug in the application.

- "device"-link and <subsystem>:<kernel name>-links
  Never depend on the "device"-link. The "device"-link is a workaround
  for the old layout, where class-devices are not created in
  /sys/devices/ like the bus-devices. If the link-resolving of a
  device-directory does not end in /sys/devices/, you can use the
  "device"-link to find the parent devices in /sys/devices/. That is the
  single valid use of the "device"-link, it must never appear in any
  path as an element. Assuming the existence of the "device"-link for
  a device in /sys/devices/ is a bug in the application.
  Accessing /sys/class/net/eth0/device is a bug in the application.

  Never depend on the class-specific links back to the /sys/class
  directory.  These links are also a workaround for the design mistake
  that class-devices are not created in /sys/devices. If a device
  directory does not contain directories for child devices, these links
  may be used to find the child devices in /sys/class. That is the single
  valid use of these links, they must never appear in any path as an
  element. Assuming the existence of these links for devices which are
  real child device directories in the /sys/devices tree, is a bug in
  the application.

  It is planned to remove all these links when when all class-device
  directories live in /sys/devices.

- Position of devices along device chain can change.
  Never depend on a specific parent device position in the devpath,
  or the chain of parent devices. The kernel is free to insert devices into
  the chain. You must always request the parent device you are looking for
  by its subsystem value. You need to walk up the chain until you find
  the device that matches the expected subsystem. Depending on a specific
  position of a parent device, or exposing relative paths, using "../" to
  access the chain of parents, is a bug in the application.
+8 −3
Original line number Diff line number Diff line
@@ -60,6 +60,9 @@ struct locomo {
	unsigned int irq;
	spinlock_t lock;
	void __iomem *base;
#ifdef CONFIG_PM
	void *saved_state;
#endif
};

struct locomo_dev_info {
@@ -565,7 +568,7 @@ static int locomo_suspend(struct platform_device *dev, pm_message_t state)
	if (!save)
		return -ENOMEM;

	dev->dev.power.saved_state = (void *) save;
	lchip->saved_state = save;

	spin_lock_irqsave(&lchip->lock, flags);

@@ -606,7 +609,7 @@ static int locomo_resume(struct platform_device *dev)
	unsigned long r;
	unsigned long flags;

	save = (struct locomo_save_data *) dev->dev.power.saved_state;
	save = lchip->saved_state;
	if (!save)
		return 0;

@@ -628,6 +631,8 @@ static int locomo_resume(struct platform_device *dev)
	locomo_writel(0x1, lchip->base + LOCOMO_KEYBOARD + LOCOMO_KCMD);

	spin_unlock_irqrestore(&lchip->lock, flags);

	lchip->saved_state = NULL;
	kfree(save);

	return 0;
+8 −5
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@ struct sa1111 {
	int		irq;
	spinlock_t	lock;
	void __iomem	*base;
#ifdef CONFIG_PM
	void		*saved_state;
#endif
};

/*
@@ -822,7 +825,7 @@ static int sa1111_suspend(struct platform_device *dev, pm_message_t state)
	save = kmalloc(sizeof(struct sa1111_save_data), GFP_KERNEL);
	if (!save)
		return -ENOMEM;
	dev->dev.power.saved_state = save;
	sachip->saved_state = save;

	spin_lock_irqsave(&sachip->lock, flags);

@@ -878,7 +881,7 @@ static int sa1111_resume(struct platform_device *dev)
	unsigned long flags, id;
	void __iomem *base;

	save = (struct sa1111_save_data *)dev->dev.power.saved_state;
	save = sachip->saved_state;
	if (!save)
		return 0;

@@ -923,7 +926,7 @@ static int sa1111_resume(struct platform_device *dev)

	spin_unlock_irqrestore(&sachip->lock, flags);

	dev->dev.power.saved_state = NULL;
	sachip->saved_state = NULL;
	kfree(save);

	return 0;
@@ -958,8 +961,8 @@ static int sa1111_remove(struct platform_device *pdev)
		platform_set_drvdata(pdev, NULL);

#ifdef CONFIG_PM
		kfree(pdev->dev.power.saved_state);
		pdev->dev.power.saved_state = NULL;
		kfree(sachip->saved_state);
		sachip->saved_state = NULL;
#endif
	}

+4 −11
Original line number Diff line number Diff line
@@ -185,28 +185,21 @@ static int __devinit neponset_probe(struct platform_device *dev)
/*
 * LDM power management.
 */
static unsigned int neponset_saved_state;

static int neponset_suspend(struct platform_device *dev, pm_message_t state)
{
	/*
	 * Save state.
	 */
	if (!dev->dev.power.saved_state)
		dev->dev.power.saved_state = kmalloc(sizeof(unsigned int), GFP_KERNEL);
	if (!dev->dev.power.saved_state)
		return -ENOMEM;

	*(unsigned int *)dev->dev.power.saved_state = NCR_0;
	neponset_saved_state = NCR_0;

	return 0;
}

static int neponset_resume(struct platform_device *dev)
{
	if (dev->dev.power.saved_state) {
		NCR_0 = *(unsigned int *)dev->dev.power.saved_state;
		kfree(dev->dev.power.saved_state);
		dev->dev.power.saved_state = NULL;
	}
	NCR_0 = neponset_saved_state;

	return 0;
}
Loading