2008-01-25 07:13:18

by Greg KH

[permalink] [raw]
Subject: [GIT PATCH] driver core patches against 2.6.24

Due to the low level nature of these patches, and because they touch so
many different parts of the kernel, a number of the subsystem
maintainers have asked me to get them in first to make merging other
trees easier.

Here are a pretty large number of kobject, documentation, and driver
core patches against your 2.6.24 git tree.

They can be broken down into these major areas:
- Documentation updates (language translations and fixes, as
well as kobject and kset documenatation updates.)
- major kset/kobject/ktype rework and fixes. This cleans up the
kset and kobject and ktype relationship and architecture,
making sense of things now, and good documenation and samples
are provided for others to use. Also the attributes for
kobjects are much easier to handle now. This cleaned up a LOT
of code all through the kernel, making kobjects easier to use
if you want to.
- struct bus_type has been reworked to now handle the lifetime
rules properly, as the kobject is properly dynamic.
- struct driver has also been reworked, and now the lifetime
issues are resolved.
- the block subsystem has been converted to use struct device
now, and not "raw" kobjects. This patch has been in the -mm
tree for over a year now, and finally all the issues are
worked out with it. Older distros now properly work with new
kernels, and no userspace updates are needed at all.
- nozomi driver is added. This has also been in -mm for a long
time, and many people have asked for it to go in. It is now
in good enough shape to do so.
- lots of class_device conversions to use struct device instead.
The tree is almost all cleaned up now, only SCSI and IB is the
remaining code to fix up...


Please pull from:
master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6.git/

All of these patches have been in the -mm tree for a number of months.

Patches will be sent as a follow-on to this message to lkml for people
to see.

thanks,

greg k-h

------------

Documentation/kobject.txt | 489 +++--
Documentation/pnp.txt | 4 +-
Documentation/s390/cds.txt | 2 +-
Documentation/vm/slabinfo.c | 2 +-
Documentation/vm/slub.txt | 2 +-
Documentation/zh_CN/CodingStyle | 701 +++++++
Documentation/zh_CN/HOWTO | 10 +-
Documentation/zh_CN/SubmittingDrivers | 168 ++
Documentation/zh_CN/SubmittingPatches | 416 ++++
Documentation/zh_CN/oops-tracing.txt | 212 +++
Documentation/zh_CN/sparse.txt | 100 +
Documentation/zh_CN/stable_kernel_rules.txt | 66 +
.../zh_CN/volatile-considered-harmful.txt | 113 ++
arch/arm/kernel/time.c | 4 +-
arch/arm/mach-integrator/integrator_ap.c | 2 +-
arch/arm/mach-omap1/pm.c | 23 +-
arch/arm/mach-pxa/cm-x270.c | 2 +-
arch/arm/mach-pxa/lpd270.c | 2 +-
arch/arm/mach-pxa/lubbock.c | 2 +-
arch/arm/mach-pxa/mainstone.c | 2 +-
arch/arm/mach-s3c2410/s3c2410.c | 2 +-
arch/arm/mach-s3c2412/s3c2412.c | 2 +-
arch/arm/mach-s3c2440/mach-osiris.c | 2 +-
arch/arm/mach-s3c2443/s3c2443.c | 2 +-
arch/arm/mach-sa1100/irq.c | 2 +-
arch/arm/oprofile/common.c | 2 +-
arch/arm/plat-omap/gpio.c | 2 +-
arch/arm/plat-s3c24xx/dma.c | 2 +-
arch/arm/plat-s3c24xx/s3c244x.c | 4 +-
arch/avr32/kernel/time.c | 2 +-
arch/cris/arch-v32/drivers/iop_fw_load.c | 11 +
arch/ia64/kernel/topology.c | 26 +-
arch/mips/kernel/i8259.c | 2 +-
arch/powerpc/platforms/cell/spu_base.c | 2 +-
arch/powerpc/platforms/powermac/pic.c | 2 +-
arch/powerpc/platforms/pseries/power.c | 32 +-
arch/powerpc/sysdev/ipic.c | 2 +-
arch/powerpc/sysdev/mpic.c | 2 +-
arch/powerpc/sysdev/qe_lib/qe_ic.c | 2 +-
arch/ppc/syslib/ipic.c | 2 +-
arch/ppc/syslib/open_pic.c | 2 +-
arch/ppc/syslib/open_pic2.c | 2 +-
arch/s390/hypfs/inode.c | 13 +-
arch/s390/kernel/ipl.c | 147 +-
arch/s390/kernel/time.c | 2 +-
arch/sh/drivers/dma/dma-sysfs.c | 2 +-
arch/sh/kernel/cpu/sh4/sq.c | 13 +-
arch/sh/kernel/time.c | 2 +-
arch/x86/kernel/apic_32.c | 2 +-
arch/x86/kernel/apic_64.c | 2 +-
arch/x86/kernel/cpu/intel_cacheinfo.c | 24 +-
arch/x86/kernel/cpu/mcheck/mce_64.c | 2 +-
arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 30 +-
arch/x86/kernel/cpuid.c | 6 +-
arch/x86/kernel/i8237.c | 2 +-
arch/x86/kernel/i8259_32.c | 2 +-
arch/x86/kernel/i8259_64.c | 2 +-
arch/x86/kernel/io_apic_32.c | 2 +-
arch/x86/kernel/io_apic_64.c | 2 +-
arch/x86/kernel/msr.c | 6 +-
arch/x86/kernel/nmi_32.c | 2 +-
arch/x86/kernel/nmi_64.c | 2 +-
arch/x86/oprofile/nmi_int.c | 2 +-
block/elevator.c | 8 +-
block/genhd.c | 419 ++---
block/ll_rw_blk.c | 11 +-
drivers/acpi/bus.c | 11 +-
drivers/acpi/pci_link.c | 2 +-
drivers/acpi/system.c | 13 +-
drivers/base/Makefile | 3 +
drivers/base/attribute_container.c | 9 +-
drivers/base/base.h | 64 +-
drivers/base/bus.c | 501 +++---
drivers/base/class.c | 319 +++-
drivers/base/core.c | 582 +++---
drivers/base/cpu.c | 2 +-
drivers/base/dd.c | 164 +-
drivers/base/driver.c | 216 ++-
drivers/base/firmware.c | 26 +-
drivers/base/hypervisor.c | 12 +-
drivers/base/init.c | 10 +-
drivers/base/memory.c | 2 +-
drivers/base/module.c | 94 +
drivers/base/node.c | 2 +-
drivers/base/platform.c | 239 ++--
drivers/base/power/Makefile | 1 -
drivers/base/power/main.c | 502 ++++--
drivers/base/power/power.h | 19 +-
drivers/base/power/shutdown.c | 48 -
drivers/base/sys.c | 49 +-
drivers/block/aoe/aoeblk.c | 51 +-
drivers/block/aoe/aoechr.c | 7 +-
drivers/block/nbd.c | 15 +-
drivers/block/paride/pg.c | 6 +-
drivers/block/paride/pt.c | 12 +-
drivers/block/pktcdvd.c | 27 +-
drivers/char/Kconfig | 10 +
drivers/char/Makefile | 1 +
drivers/char/hvc_console.c | 80 +-
drivers/char/hvcs.c | 78 +-
drivers/char/nozomi.c | 1993 ++++++++++++++++++++
drivers/cpufreq/cpufreq.c | 12 +-
drivers/cpuidle/sysfs.c | 21 +-
drivers/dma/dmaengine.c | 43 +-
drivers/edac/edac_device_sysfs.c | 49 +-
drivers/edac/edac_mc_sysfs.c | 40 +-
drivers/edac/edac_module.c | 2 +-
drivers/edac/edac_pci_sysfs.c | 35 +-
drivers/firmware/edd.c | 25 +-
drivers/firmware/efivars.c | 130 +-
drivers/i2c/chips/isp1301_omap.c | 6 -
drivers/ide/ide-probe.c | 2 +-
drivers/ide/ide-tape.c | 14 +-
drivers/ieee1394/nodemgr.c | 314 ++--
drivers/infiniband/core/sysfs.c | 39 +-
drivers/infiniband/hw/ehca/ehca_main.c | 13 +-
drivers/infiniband/hw/ipath/ipath_driver.c | 17 +-
drivers/infiniband/hw/ipath/ipath_kernel.h | 3 +-
drivers/infiniband/hw/ipath/ipath_sysfs.c | 30 +-
drivers/isdn/capi/capi.c | 6 +-
drivers/isdn/gigaset/gigaset.h | 6 -
drivers/kvm/kvm_main.c | 2 +-
drivers/macintosh/adb.c | 2 +-
drivers/macintosh/via-pmu.c | 2 +-
drivers/md/dm.c | 4 +-
drivers/md/md.c | 31 +-
drivers/mfd/ucb1x00-assabet.c | 17 +-
drivers/mfd/ucb1x00-core.c | 14 +-
drivers/mfd/ucb1x00.h | 4 +-
drivers/misc/ibmasm/command.c | 12 +-
drivers/misc/ibmasm/ibmasm.h | 10 +-
drivers/misc/tifm_7xx1.c | 4 +-
drivers/misc/tifm_core.c | 24 +-
drivers/mtd/mtdchar.c | 12 +-
drivers/net/ibmveth.c | 12 +-
drivers/net/iseries_veth.c | 19 +-
drivers/net/wan/cosa.c | 5 +-
drivers/parisc/pdc_stable.c | 194 +-
drivers/pci/hotplug/acpiphp_ibm.c | 4 +-
drivers/pci/hotplug/pci_hotplug_core.c | 39 +-
drivers/pci/hotplug/rpadlpar_sysfs.c | 113 +-
drivers/pci/pci-driver.c | 59 +-
drivers/pci/probe.c | 11 +-
drivers/pcmcia/ds.c | 3 +-
drivers/power/apm_power.c | 116 +-
drivers/power/power_supply_core.c | 74 +-
drivers/rtc/interface.c | 22 +-
drivers/s390/net/netiucv.c | 16 +-
drivers/s390/scsi/zfcp_ccw.c | 14 +-
drivers/s390/scsi/zfcp_ext.h | 3 +-
drivers/s390/scsi/zfcp_sysfs_driver.c | 27 +-
drivers/scsi/hosts.c | 24 +-
drivers/scsi/libsas/sas_scsi_host.c | 2 +-
drivers/serial/icom.c | 24 +-
drivers/serial/icom.h | 2 +-
drivers/spi/spi.c | 26 +-
drivers/uio/uio.c | 95 +-
drivers/usb/core/driver.c | 8 +-
fs/block_dev.c | 8 +-
fs/char_dev.c | 6 +-
fs/coda/psdev.c | 8 +-
fs/configfs/mount.c | 13 +-
fs/debugfs/inode.c | 13 +-
fs/dlm/lockspace.c | 50 +-
fs/ecryptfs/main.c | 129 +--
fs/fuse/inode.c | 26 +-
fs/gfs2/locking/dlm/sysfs.c | 38 +-
fs/gfs2/sys.c | 29 +-
fs/namespace.c | 11 +-
fs/ocfs2/cluster/masklog.c | 4 +-
fs/ocfs2/cluster/sys.c | 83 +-
fs/partitions/check.c | 327 ++---
fs/sysfs/dir.c | 2 +-
fs/sysfs/file.c | 67 +-
fs/sysfs/symlink.c | 88 +-
include/acpi/acpi_bus.h | 2 +-
include/linux/device.h | 360 ++--
include/linux/dmaengine.h | 3 +-
include/linux/fs.h | 2 +-
include/linux/genhd.h | 37 +-
include/linux/kobject.h | 184 +--
include/linux/kref.h | 1 +
include/linux/module.h | 19 +-
include/linux/pci_hotplug.h | 2 +-
include/linux/pktcdvd.h | 2 +-
include/linux/platform_device.h | 2 +-
include/linux/sched.h | 9 +-
include/linux/sysdev.h | 1 +
include/linux/tifm.h | 2 +-
include/linux/uio_driver.h | 6 +-
include/rdma/ib_verbs.h | 2 +-
init/Kconfig | 1 +
init/do_mounts.c | 108 +-
kernel/ksysfs.c | 82 +-
kernel/module.c | 128 +--
kernel/params.c | 44 +-
kernel/power/disk.c | 20 +-
kernel/power/main.c | 23 +-
kernel/power/power.h | 4 +-
kernel/rtmutex-tester.c | 2 +-
kernel/time/clocksource.c | 2 +-
kernel/time/timekeeping.c | 2 +-
kernel/user.c | 107 +-
lib/kobject.c | 734 +++++---
lib/kobject_uevent.c | 38 +-
lib/kref.c | 15 +-
mm/slub.c | 23 +-
net/bridge/br_if.c | 12 +-
net/bridge/br_private.h | 2 +-
net/bridge/br_sysfs_br.c | 14 +-
net/bridge/br_sysfs_if.c | 2 +-
samples/Kconfig | 10 +
samples/Makefile | 2 +-
samples/kobject/Makefile | 1 +
samples/kobject/kobject-example.c | 137 ++
samples/kobject/kset-example.c | 278 +++
security/inode.c | 11 +-
217 files changed, 8870 insertions(+), 4631 deletions(-)
create mode 100644 Documentation/zh_CN/CodingStyle
create mode 100644 Documentation/zh_CN/SubmittingDrivers
create mode 100644 Documentation/zh_CN/SubmittingPatches
create mode 100644 Documentation/zh_CN/oops-tracing.txt
create mode 100644 Documentation/zh_CN/sparse.txt
create mode 100644 Documentation/zh_CN/stable_kernel_rules.txt
create mode 100644 Documentation/zh_CN/volatile-considered-harmful.txt
create mode 100644 drivers/base/module.c
delete mode 100644 drivers/base/power/shutdown.c
create mode 100644 drivers/char/nozomi.c
create mode 100644 samples/kobject/Makefile
create mode 100644 samples/kobject/kobject-example.c
create mode 100644 samples/kobject/kset-example.c

---------------

Alan Stern (2):
Driver core: fix race in __device_release_driver
Kobject: drop child->parent ref at unregistration

Bryan Wu (1):
Chinese: add translation of volatile-considered-harmful.txt

Cornelia Huck (4):
driver core: Introduce default attribute groups.
netiucv: Use device_driver default attribute groups.
zfcp: Use device_driver default attribute groups.
Driver core: Cleanup get_device_parent() in device_add() and device_move()

Dave Young (7):
Chinese: add translation of oops-tracing.txt
Driver Core: add class iteration api
ieee1394: use class iteration api
power supply : use class iteration api
rtc: use class iteration api
scsi: use class iteration api
spi: use class iteration api

Denis Cheng (1):
Driver core: use LIST_HEAD instead of call to INIT_LIST_HEAD in __init

Emil Medve (1):
driver core: Make the dev_*() family of macros in device.h complete

Evgeniy Polyakov (1):
kref: add kref_set()

Frank Seidel (1):
nozomi driver

Greg Kroah-Hartman (140):
kobject: remove incorrect comment in kobject_rename
ecryptfs: clean up attribute mess
kobject: convert ibmasm to use kref, not kobject
kobject: convert hvc_console to use kref, not kobject
kobject: convert hvcs to use kref, not kobject
kobject: convert icom to use kref, not kobject
kobject: fix up kobject_set_name to use kvasprintf
kobject: make kobject_cleanup be static
kobject: add kobject_init_ng function
kobject: add kobject_add_ng function
kobject: add kobject_init_and_add function
kobject: remove struct kobj_type from struct kset
kobject: remove kobj_set_kset_s as no one is using it anymore
kset: add kset_create_and_add function
kobject: add kobject_create_and_add function
kobject: get rid of kobject_add_dir
kobject: get rid of kobject_kset_add_dir
kobject: convert fuse to use kobject_create
kobject: convert securityfs to use kobject_create
kobject: convert debugfs to use kobject_create
kobject: convert configfs to use kobject_create
kset: convert ecryptfs to use kset_create
kobject: convert main fs kobject to use kobject_create
kset: convert gfs2 to use kset_create
kset: convert gfs2 dlm to use kset_create
kset: convert dlm to use kset_create
kset: convert pci hotplug to use kset_create_and_add
kset: remove decl_subsys_name
kset: convert kernel_subsys to use kset_create
kset: convert drivers/base/bus.c to use kset_create
kset: convert drivers/base/class.c to use kset_create
kset: convert drivers/base/firmware.c to use kset_create
kset: convert /sys/devices to use kset_create
kobject: convert /sys/hypervisor to use kobject_create
kobject: convert s390 hypervisor to use kobject_create
kset: convert /sys/devices/system to use kset_create
kset: convert slub to use kset_create
kset: move /sys/slab to /sys/kernel/slab
kset: convert /sys/module to use kset_create
kset: convert /sys/power to use kset_create
kset: convert struct bus_device->devices to use kset_create
kset: convert struct bus_device->drivers to use kset_create
ecryptfs: remove version_str file from sysfs
efivars: make new_var and del_var binary sysfs files
kobject: convert efivars to kobj_attr interface
firmware: export firmware_kset so that people can use that instead of the braindead firmware_register interface
kset: convert efivars to use kset_create for the efi subsystem.
kset: convert efivars to use kset_create for the vars sub-subsystem.
kobject: convert arm/mach-omap1/pm.c to kobj_attr interface
kobject: convert pseries/power.c to kobj_attr interface
kobject: convert s390 ipl.c to kobj_attr interface
kset: convert s390 ipl.c to use kset_create
kobject: convert parisc/pdc_stable to kobj_attr interface
kset: convert parisc/pdc_stable.c to use kset_create
kset: convert edd to use kset_create
kobject: convert /sys/firmware/acpi/ to use kobject_create
firmware: remove firmware_(un)register()
firmware: change firmware_kset to firmware_kobj
kset: convert ocfs2 to use kset_create
kset: convert block_subsys to use kset_create
kset: remove decl_subsys macro
kobject: convert kernel_kset to be a kobject
kobject: remove subsystem_(un)register functions
kobject: clean up rpadlpar horrid sysfs abuse
kobject: convert ecryptfs to use kobject_create
kobject: convert efivars to use kobject_create
kobject: convert parisc/pdc_stable to use kobject_create
driver core: clean up shutdown.c
driver core: clean up device_shutdown
driver core: make /sys/power a kobject
kobject: grab the kset reference in kobject_add, not kobject_init
kobject: clean up debugging messages
UIO: fix kobject usage
Kobject: change net/bridge to use kobject_create_and_add
Kobject: change GFS2 to use kobject_init_and_add
Kobject: change drivers/infiniband to use kobject_init_and_add
Kobject: change drivers/firmware/edd.c to use kobject_init_and_add
Kobject: change drivers/firmware/efivars.c to use kobject_init_and_add
Kobject: change drivers/cpufreq/cpufreq.c to use kobject_init_and_add
Kobject: change drivers/edac to use kobject_init_and_add
Kobject: change drivers/cpuidle/sysfs.c to use kobject_init_and_add
Kobject: change drivers/pci/hotplug/pci_hotplug_core.c to use kobject_init_and_add
Kobject: change drivers/base/sys.c to use kobject_init_and_add
Kobject: change arch/x86/kernel/cpu/intel_cacheinfo.c to use kobject_init_and_add
Kobject: change drivers/acpi/system.c to use kobject_create_and_add
Kobject: change drivers/block/pktcdvd.c to use kobject_init_and_add
Kobject: change arch/sh/kernel/cpu/sh4/sq.c to use kobject_init_and_add
Kobject: change drivers/net/ibmveth.c to use kobject_init_and_add
Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add
Kobject: change arch/ia64/kernel/topology.c to use kobject_init_and_add
Kobject: change drivers/md/md.c to use kobject_init_and_add
Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_create_and_add
Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_init_and_add
Kobject: the cris iop_fw_load.c code is broken
Kobject: convert drivers/base/class.c to use kobject_init/add_ng()
Kobject: convert drivers/base/core.c to use kobject_init/add_ng()
Kobject: convert drivers/net/iseries_veth.c to use kobject_init/add_ng()
Kobject: convert fs/char_dev.c to use kobject_init/add_ng()
Kobject: convert kernel/params.c to use kobject_init/add_ng()
Kobject: convert kernel/user.c to use kobject_init/add_ng()
Kobject: convert mm/slub.c to use kobject_init/add_ng()
Kobject: convert net/bridge/br_if.c to use kobject_init/add_ng()
driver core: remove owner field from struct bus_type
driver core: add way to get to bus kset
driver core: add way to get to bus device klist
driver core: remove fields from struct bus_type
USB: use proper call to driver_create_file
PCMCIA: use proper call to driver_create_file
PCI: use proper call to driver_create_file
PCI: remove foolish code from pci-driver.c
Infiniband: make ipath driver use default driver groups.
Driver: add driver_add_kobj for looney iseries_veth driver
Driver core: move the driver specific module code into the driver core
Driver core: move the static kobject out of struct driver
Driver core: clean up debugging messages
Kobject: change drivers/base/bus to use kobject_init_and_add
Kobject: convert block/elevator.c to use kobject_init/add_ng()
Kobject: convert block/ll_rw_blk.c to use kobject_init/add_ng()
Kobject: convert drivers/md/md.c to use kobject_init/add_ng()
Kobject: convert kernel/module.c to use kobject_init/add_ng()
Kobject: remove kobject_add() as no one uses it anymore
Kobject: rename kobject_add_ng() to kobject_add()
Kobject: remove kobject_init() as no one uses it anymore
Kobject: rename kobject_init_ng() to kobject_init()
Kobject: remove kobject_register()
Kset: remove kset_add function
Modules: remove unneeded release function
Kobject: convert arch/* from kobject_unregister() to kobject_put()
Kobject: convert drivers/* from kobject_unregister() to kobject_put()
Kobject: convert fs/* from kobject_unregister() to kobject_put()
Kobject: convert remaining kobject_unregister() to kobject_put()
Kobject: remove kobject_unregister() as no one uses it anymore
kobject: remove old, outdated documentation.
kobject: update the kobject/kset documentation
kobject: add sample code for how to use kobjects in a simple manner.
kobject: add sample code for how to use ksets/ktypes/kobjects
Driver core: fix coding style issues in device.h
Kobject: fix coding style issues in kobject.h
Kobject: fix coding style issues in kobject c files
Driver core: coding style fixes

Jan Engelhardt (1):
UIO: constify function pointer tables

Jean Delvare (1):
sysfs: Fix a copy-n-paste typo in comment

Jiri Slaby (1):
sysfs: remove SPIN_LOCK_UNLOCKED

Kay Sievers (11):
coda: convert struct class_device to struct device
sysfs: create optimal relative symlink targets
Driver Core: add kobj_attribute handling
Driver Core: switch all dynamic ksets to kobj_sysfs_ops
fix struct user_info export's sysfs interaction
Driver Core: kill subsys_attribute and default sysfs ops
Driver core: fix class glue dir cleanup logic
sysfs: fix /sys/module/*/holders after sysfs logic change
Driver core: convert block from raw kobjects to core devices
Kobject: auto-cleanup on final unref
Driver core: change sysdev classes to use dynamic kobject names

Li Yang (5):
Chinese: Add the known_regression URI to the HOWTO
Chinese: rephrase English introduction in HOWTO
Chinese: Change man-pages maintainer address in HOWOTO
Chinese: add translation of SubmittingDrivers
Chinese: add translation of sparse.txt

Rafael J. Wysocki (1):
PM: Acquire device locks on suspend

Randy Dunlap (2):
sysfs: make SYSFS_DEPRECATED depend on SYSFS
driver core: fix build with SYSFS=n

Robert P. J. Day (1):
Documentation: Replace obsolete "driverfs" with "sysfs".

Stephen Rothwell (1):
Driver Core: constify the name passed to platform_device_register_simple

Tony Jones (11):
aoechr: Convert from class_device to device
DMA: Convert from class_device to device for DMA engine
IDE: Convert from class_device to device for ide-tape
ISDN: Convert from class_device to device for ISDN capi
adb: Convert from class_device to device
MCP_UCB1200: Convert from class_device to device
mtd: Convert from class_device to device for MTD/mtdchar
paride: Convert from class_device to device for block/paride
pktcdvd: Convert from class_device to device for block/pktcdvd
tifm: Convert from class_device to device for TI flash media
cosa: Convert from class_device to device for cosa sync driver

TripleX Chung (2):
Chinese: add translation of SubmittingPatches
Chinese: add translation of stable_kernel_rules.txt

Zhang Le (1):
Chinese: add translation of Codingstyle


2008-01-25 07:13:50

by Greg KH

[permalink] [raw]
Subject: [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO

From: Li Yang <[email protected]>

Update translation for commit be3884943674f8ee7656b1d8b71c087ec900c836.

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/HOWTO | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index 48fc67b..c8660da 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -218,6 +218,8 @@ kernel.org网站的pub/linux/kernel/v2.6/目录下找到它。它的开发遵循
时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。
- 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是
6个星期。
+ - 以下地址跟踪了在每个-rc发布中发现的退步列表:
+ http://kernelnewbies.org/known_regressions

关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说:
“没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定
--
1.5.3.8

2008-01-25 07:14:09

by Greg KH

[permalink] [raw]
Subject: [PATCH 002/196] Chinese: rephrase English introduction in HOWTO

From: Li Yang <[email protected]>

Rephrase the introduction as suggested by Jesper Juhl.

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/HOWTO | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index c8660da..79d1c3c 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -1,10 +1,10 @@
Chinese translated version of Documentation/HOWTO

If you have any comment or update to the content, please contact the
-original document maintainer directly. However, if you have problem
+original document maintainer directly. However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
-help. Contact the Chinese maintainer, if this translation is outdated
-or there is problem with translation.
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.

Maintainer: Greg Kroah-Hartman <[email protected]>
Chinese maintainer: Li Yang <[email protected]>
--
1.5.3.8

2008-01-25 07:14:30

by Greg KH

[permalink] [raw]
Subject: [PATCH 004/196] Chinese: add translation of SubmittingPatches

From: TripleX Chung <[email protected]>

Signed-off-by: TripleX Chung <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/SubmittingPatches | 416 +++++++++++++++++++++++++++++++++
1 files changed, 416 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/SubmittingPatches

diff --git a/Documentation/zh_CN/SubmittingPatches b/Documentation/zh_CN/SubmittingPatches
new file mode 100644
index 0000000..985c92e
--- /dev/null
+++ b/Documentation/zh_CN/SubmittingPatches
@@ -0,0 +1,416 @@
+Chinese translated version of Documentation/SubmittingPatches
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: TripleX Chung <[email protected]>
+---------------------------------------------------------------------
+Documentation/SubmittingPatches 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+中文版维护者: 钟宇 TripleX Chung <[email protected]>
+中文版翻译者: 钟宇 TripleX Chung <[email protected]>
+中文版校译者: 李阳 Li Yang <[email protected]>
+ 王聪 Wang Cong <[email protected]>
+
+以下为正文
+---------------------------------------------------------------------
+
+ 如何让你的改动进入内核
+ 或者
+ 获得亲爱的 Linus Torvalds 的关注和处理
+----------------------------------
+
+对于想要将改动提交到 Linux 内核的个人或者公司来说,如果不熟悉“规矩”,
+提交的流程会让人畏惧。本文档收集了一系列建议,这些建议可以大大的提高你
+的改动被接受的机会。
+阅读 Documentation/SubmitChecklist 来获得在提交代码前需要检查的项目的列
+表。如果你在提交一个驱动程序,那么同时阅读一下
+Documentation/SubmittingDrivers 。
+
+
+--------------------------
+第一节 - 创建并发送你的改动
+--------------------------
+
+1) "diff -up"
+-----------
+
+使用 "diff -up" 或者 "diff -uprN" 来创建补丁。
+
+所有内核的改动,都是以补丁的形式呈现的,补丁由 diff(1) 生成。创建补丁的
+时候,要确认它是以 "unified diff" 格式创建的,这种格式由 diff(1) 的 '-u'
+参数生成。而且,请使用 '-p' 参数,那样会显示每个改动所在的C函数,使得
+产生的补丁容易读得多。补丁应该基于内核源代码树的根目录,而不是里边的任
+何子目录。
+为一个单独的文件创建补丁,一般来说这样做就够了:
+
+ SRCTREE= linux-2.6
+ MYFILE= drivers/net/mydriver.c
+
+ cd $SRCTREE
+ cp $MYFILE $MYFILE.orig
+ vi $MYFILE # make your change
+ cd ..
+ diff -up $SRCTREE/$MYFILE{.orig,} > /tmp/patch
+
+为多个文件创建补丁,你可以解开一个没有修改过的内核源代码树,然后和你自
+己的代码树之间做 diff 。例如:
+
+ MYSRC= /devel/linux-2.6
+
+ tar xvfz linux-2.6.12.tar.gz
+ mv linux-2.6.12 linux-2.6.12-vanilla
+ diff -uprN -X linux-2.6.12-vanilla/Documentation/dontdiff \
+ linux-2.6.12-vanilla $MYSRC > /tmp/patch
+
+"dontdiff" 是内核在编译的时候产生的文件的列表,列表中的文件在 diff(1)
+产生的补丁里会被跳过。"dontdiff" 文件被包含在2.6.12和之后版本的内核源代
+码树中。对于更早的内核版本,你可以从
+<http://www.xenotime.net/linux/doc/dontdiff> 获取它。
+确定你的补丁里没有包含任何不属于这次补丁提交的额外文件。记得在用diff(1)
+生成补丁之后,审阅一次补丁,以确保准确。
+如果你的改动很散乱,你应该研究一下如何将补丁分割成独立的部分,将改动分
+割成一系列合乎逻辑的步骤。这样更容易让其他内核开发者审核,如果你想你的
+补丁被接受,这是很重要的。下面这些脚本能够帮助你做这件事情:
+Quilt:
+http://savannah.nongnu.org/projects/quilt
+
+Andrew Morton 的补丁脚本:
+http://www.zip.com.au/~akpm/linux/patches/
+作为这些脚本的替代,quilt 是值得推荐的补丁管理工具(看上面的链接)。
+
+2)描述你的改动。
+描述你的改动包含的技术细节。
+
+要多具体就写多具体。最糟糕的描述可能是像下面这些语句:“更新了某驱动程
+序”,“修正了某驱动程序的bug”,或者“这个补丁包含了某子系统的修改,请
+使用。”
+
+如果你的描述开始变长,这表示你也许需要拆分你的补丁了,请看第3小节,
+继续。
+
+3)拆分你的改动
+
+将改动拆分,逻辑类似的放到同一个补丁文件里。
+
+例如,如果你的改动里同时有bug修正和性能优化,那么把这些改动才分到两个或
+者更多的补丁文件中。如果你的改动包含对API的修改,并且修改了驱动程序来适
+应这些新的API,那么把这些修改分成两个补丁。
+
+另一方面,如果你将一个单独的改动做成多个补丁文件,那么将它们合并成一个
+单独的补丁文件。这样一个逻辑上单独的改动只被包含在一个补丁文件里。
+
+如果有一个补丁依赖另外一个补丁来完成它的改动,那没问题。简单的在你的补
+丁描述里指出“这个补丁依赖某补丁”就好了。
+
+如果你不能将补丁浓缩成更少的文件,那么每次大约发送出15个,然后等待审查
+和整合。
+
+4)选择 e-mail 的收件人
+
+看一遍 MAINTAINERS 文件和源代码,看看你所的改动所在的内核子系统有没有指
+定的维护者。如果有,给他们发e-mail。
+
+如果没有找到维护者,或者维护者没有反馈,将你的补丁发送到内核开发者主邮
+件列表 [email protected]。大部分的内核开发者都跟踪这个邮件列
+表,可以评价你的改动。
+
+每次不要发送超过15个补丁到 vger 邮件列表!!!
+
+Linus Torvalds 是决定改动能否进入 Linux 内核的最终裁决者。他的 e-mail
+地址是 <[email protected]> 。他收到的 e-mail 很多,所以一般
+的说,最好别给他发 e-mail。
+
+那些修正bug,“显而易见”的修改或者是类似的只需要很少讨论的补丁可以直接
+发送或者CC给Linus。那些需要讨论或者没有很清楚的好处的补丁,一般先发送到
+linux-kernel邮件列表。只有当补丁被讨论得差不多了,才提交给Linus。
+
+5)选择CC( e-mail 抄送)列表
+
+除非你有理由不这样做,否则CC [email protected]
+
+除了 Linus 之外,其他内核开发者也需要注意到你的改动,这样他们才能评论你
+的改动并提供代码审查和建议。linux-kernel 是 Linux 内核开发者主邮件列表
+。其它的邮件列表为特定的子系统提供服务,比如 USB,framebuffer 设备,虚
+拟文件系统,SCSI 子系统,等等。查看 MAINTAINERS 文件来获得和你的改动有
+关的邮件列表。
+
+Majordomo lists of VGER.KERNEL.ORG at:
+ <http://vger.kernel.org/vger-lists.html>
+
+如果改动影响了用户空间和内核之间的接口,请给 MAN-PAGES 的维护者(列在
+MAITAINERS 文件里的)发送一个手册页(man-pages)补丁,或者至少通知一下改
+变,让一些信息有途径进入手册页。
+
+即使在第四步的时候,维护者没有作出回应,也要确认在修改他们的代码的时候
+,一直将维护者拷贝到CC列表中。
+
+对于小的补丁,你也许会CC到 Adrian Bunk 管理的搜集琐碎补丁的邮件列表
+(Trivial Patch Monkey)[email protected],那里专门收集琐碎的补丁。下面这样
+的补丁会被看作“琐碎的”补丁:
+ 文档的拼写修正。
+ 修正会影响到 grep(1) 的拼写。
+ 警告信息修正(频繁的打印无用的警告是不好的。)
+ 编译错误修正(代码逻辑的确是对的,只是编译有问题。)
+ 运行时修正(只要真的修正了错误。)
+ 移除使用了被废弃的函数/宏的代码(例如 check_region。)
+ 联系方式和文档修正。
+ 用可移植的代码替换不可移植的代码(即使在体系结构相关的代码中,既然有
+ 人拷贝,只要它是琐碎的)
+ 任何文件的作者/维护者对该文件的改动(例如 patch monkey 在重传模式下)
+
+URL: <http://www.kernel.org/pub/linux/kernel/people/bunk/trivial/>
+
+(译注,关于“琐碎补丁”的一些说明:因为原文的这一部分写得比较简单,所以不得不
+违例写一下译注。"trivial"这个英文单词的本意是“琐碎的,不重要的。”但是在这里
+有稍微有一些变化,例如对一些明显的NULL指针的修正,属于运行时修正,会被归类
+到琐碎补丁里。虽然NULL指针的修正很重要,但是这样的修正往往很小而且很容易得到
+检验,所以也被归入琐碎补丁。琐碎补丁更精确的归类应该是
+“simple, localized & easy to verify”,也就是说简单的,局部的和易于检验的。
[email protected]邮件列表的目的是针对这样的补丁,为提交者提供一个中心,来
+降低提交的门槛。)
+
+6)没有 MIME 编码,没有链接,没有压缩,没有附件,只有纯文本。
+
+Linus 和其他的内核开发者需要阅读和评论你提交的改动。对于内核开发者来说
+,可以“引用”你的改动很重要,使用一般的 e-mail 工具,他们就可以在你的
+代码的任何位置添加评论。
+
+因为这个原因,所有的提交的补丁都是 e-mail 中“内嵌”的。
+警告:如果你使用剪切-粘贴你的补丁,小心你的编辑器的自动换行功能破坏你的
+补丁。
+
+不要将补丁作为 MIME 编码的附件,不管是否压缩。很多流行的 e-mail 软件不
+是任何时候都将 MIME 编码的附件当作纯文本发送的,这会使得别人无法在你的
+代码中加评论。另外,MIME 编码的附件会让 Linus 多花一点时间来处理,这就
+降低了你的改动被接受的可能性。
+
+警告:一些邮件软件,比如 Mozilla 会将你的信息以如下格式发送:
+---- 邮件头 ----
+Content-Type: text/plain; charset=us-ascii; format=flowed
+---- 邮件头 ----
+问题在于 “format=flowed” 会让接收端的某些邮件软件将邮件中的制表符替换
+成空格以及做一些类似的替换。这样,你发送的时候看起来没问题的补丁就被破
+坏了。
+
+要修正这个问题,只需要将你的 mozilla 的 defaults/pref/mailnews.js 文件
+里的
+pref("mailnews.send_plaintext_flowed", false); // RFC 2646=======
+修改成
+pref("mailnews.display.disable_format_flowed_support", true);
+就可以了。
+
+7) e-mail 的大小
+
+给 Linus 发送补丁的时候,永远按照第6小节说的做。
+
+大的改动对邮件列表不合适,对某些维护者也不合适。如果你的补丁,在不压缩
+的情况下,超过了40kB,那么你最好将补丁放在一个能通过 internet 访问的服
+务器上,然后用指向你的补丁的 URL 替代。
+
+8) 指出你的内核版本
+
+在标题和在补丁的描述中,指出补丁对应的内核的版本,是很重要的。
+
+如果补丁不能干净的在最新版本的内核上打上,Linus 是不会接受它的。
+
+9) 不要气馁,继续提交。
+
+当你提交了改动以后,耐心地等待。如果 Linus 喜欢你的改动并且同意它,那么
+它将在下一个内核发布版本中出现。
+
+然而,如果你的改动没有出现在下一个版本的内核中,可能有若干原因。减少那
+些原因,修正错误,重新提交更新后的改动,是你自己的工作。
+
+Linus不给出任何评论就“丢弃”你的补丁是常见的事情。在系统中这样的事情很
+平常。如果他没有接受你的补丁,也许是由于以下原本:
+* 你的补丁不能在最新版本的内核上干净的打上。
+* 你的补丁在 linux-kernel 邮件列表中没有得到充分的讨论。
+* 风格问题(参照第2小节)
+* 邮件格式问题(重读本节)
+* 你的改动有技术问题。
+* 他收到了成吨的 e-mail,而你的在混乱中丢失了。
+* 你让人为难。
+
+有疑问的时候,在 linux-kernel 邮件列表上请求评论。
+
+10) 在标题上加上 PATCH 的字样
+
+Linus 和 linux-kernel 邮件列表的 e-mail 流量都很高,一个通常的约定是标
+题行以 [PATCH] 开头。这样可以让 Linus 和其他内核开发人员可以从 e-mail
+的讨论中很轻易的将补丁分辨出来。
+
+11)为你的工作签名
+
+为了加强对谁做了何事的追踪,尤其是对那些透过好几层的维护者的补丁,我们
+建议在发送出去的补丁上加一个 “sign-off” 的过程。
+
+"sign-off" 是在补丁的注释的最后的简单的一行文字,认证你编写了它或者其他
+人有权力将它作为开放源代码的补丁传递。规则很简单:如果你能认证如下信息
+:
+ 开发者来源证书 1.1
+ 对于本项目的贡献,我认证如下信息:
+ (a)这些贡献是完全或者部分的由我创建,我有权利以文件中指出
+ 的开放源代码许可证提交它;或者
+ (b)这些贡献基于以前的工作,据我所知,这些以前的工作受恰当的开放
+ 源代码许可证保护,而且,根据许可证,我有权提交修改后的贡献,
+ 无论是完全还是部分由我创造,这些贡献都使用同一个开放源代码许可证
+ (除非我被允许用其它的许可证),正如文件中指出的;或者
+ (c)这些贡献由认证(a),(b)或者(c)的人直接提供给我,而
+ 且我没有修改它。
+ (d)我理解并同意这个项目和贡献是公开的,贡献的记录(包括我
+ 一起提交的个人记录,包括 sign-off )被永久维护并且可以和这个项目
+ 或者开放源代码的许可证同步地再发行。
+ 那么加入这样一行:
+ Signed-off-by: Random J Developer <[email protected]>
+
+使用你的真名(抱歉,不能使用假名或者匿名。)
+
+有人在最后加上标签。现在这些东西会被忽略,但是你可以这样做,来标记公司
+内部的过程,或者只是指出关于 sign-off 的一些特殊细节。
+
+12)标准补丁格式
+
+标准的补丁,标题行是:
+ Subject: [PATCH 001/123] 子系统:一句话概述
+
+标准补丁的信体存在如下部分:
+
+ - 一个 "from" 行指出补丁作者。
+
+ - 一个空行
+
+ - 说明的主体,这些说明文字会被拷贝到描述该补丁的永久改动记录里。
+
+ - 一个由"---"构成的标记行
+
+ - 不合适放到改动记录里的额外的注解。
+
+ - 补丁本身(diff 输出)
+
+标题行的格式,使得对标题行按字母序排序非常的容易 - 很多 e-mail 客户端都
+可以支持 - 因为序列号是用零填充的,所以按数字排序和按字母排序是一样的。
+
+e-mail 标题中的“子系统”标识哪个内核子系统将被打补丁。
+
+e-mail 标题中的“一句话概述”扼要的描述 e-mail 中的补丁。“一句话概述”
+不应该是一个文件名。对于一个补丁系列(“补丁系列”指一系列的多个相关补
+丁),不要对每个补丁都使用同样的“一句话概述”。
+
+记住 e-mail 的“一句话概述”会成为该补丁的全局唯一标识。它会蔓延到 git
+的改动记录里。然后“一句话概述”会被用在开发者的讨论里,用来指代这个补
+丁。用户将希望通过 google 来搜索"一句话概述"来找到那些讨论这个补丁的文
+章。
+
+一些标题的例子:
+
+ Subject: [patch 2/5] ext2: improve scalability of bitmap searching
+ Subject: [PATCHv2 001/207] x86: fix eflags tracking
+
+"from" 行是信体里的最上面一行,具有如下格式:
+ From: Original Author <[email protected]>
+
+"from" 行指明在永久改动日志里,谁会被确认为作者。如果没有 "from" 行,那
+么邮件头里的 "From: " 行会被用来决定改动日志中的作者。
+
+说明的主题将会被提交到永久的源代码改动日志里,因此对那些早已经不记得和
+这个补丁相关的讨论细节的有能力的读者来说,是有意义的。
+
+"---" 标记行对于补丁处理工具要找到哪里是改动日志信息的结束,是不可缺少
+的。
+
+对于 "---" 标记之后的额外注解,一个好的用途就是用来写 diffstat,用来显
+示修改了什么文件和每个文件都增加和删除了多少行。diffstat 对于比较大的补
+丁特别有用。其余那些只是和时刻或者开发者相关的注解,不合适放到永久的改
+动日志里的,也应该放这里。
+使用 diffstat的选项 "-p 1 -w 70" 这样文件名就会从内核源代码树的目录开始
+,不会占用太宽的空间(很容易适合80列的宽度,也许会有一些缩进。)
+
+在后面的参考资料中能看到适当的补丁格式的更多细节。
+
+-------------------------------
+第二节 提示,建议和诀窍
+-------------------------------
+
+本节包含很多和提交到内核的代码有关的通常的"规则"。事情永远有例外...但是
+你必须真的有好的理由这样做。你可以把本节叫做Linus的计算机科学入门课。
+
+1) 读 Document/CodingStyle
+
+Nuff 说过,如果你的代码和这个偏离太多,那么它有可能会被拒绝,没有更多的
+审查,没有更多的评价。
+
+2) #ifdef 是丑陋的
+混杂了 ifdef 的代码难以阅读和维护。别这样做。作为替代,将你的 ifdef 放
+在头文件里,有条件地定义 "static inline" 函数,或者宏,在代码里用这些东
+西。让编译器把那些"空操作"优化掉。
+
+一个简单的例子,不好的代码:
+
+ dev = alloc_etherdev (sizeof(struct funky_private));
+ if (!dev)
+ return -ENODEV;
+ #ifdef CONFIG_NET_FUNKINESS
+ init_funky_net(dev);
+ #endif
+
+清理后的例子:
+
+(头文件里)
+ #ifndef CONFIG_NET_FUNKINESS
+ static inline void init_funky_net (struct net_device *d) {}
+ #endif
+
+(代码文件里)
+ dev = alloc_etherdev (sizeof(struct funky_private));
+ if (!dev)
+ return -ENODEV;
+ init_funky_net(dev);
+
+3) 'static inline' 比宏好
+
+Static inline 函数相比宏来说,是好得多的选择。Static inline 函数提供了
+类型安全,没有长度限制,没有格式限制,在 gcc 下开销和宏一样小。
+
+宏只在 static inline 函数不是最优的时候[在 fast paths 里有很少的独立的
+案例],或者不可能用 static inline 函数的时候[例如字符串分配]。
+应该用 'static inline' 而不是 'static __inline__', 'extern inline' 和
+'extern __inline__' 。
+
+4) 不要过度设计
+
+不要试图预计模糊的未来事情,这些事情也许有用也许没有用:"让事情尽可能的
+简单,而不是更简单"。
+
+----------------
+第三节 参考文献
+----------------
+
+Andrew Morton, "The perfect patch" (tpp).
+ <http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt>
+
+Jeff Garzik, "Linux kernel patch submission format".
+ <http://linux.yyz.us/patch-format.html>
+
+Greg Kroah-Hartman, "How to piss off a kernel subsystem maintainer".
+ <http://www.kroah.com/log/2005/03/31/>
+ <http://www.kroah.com/log/2005/07/08/>
+ <http://www.kroah.com/log/2005/10/19/>
+ <http://www.kroah.com/log/2006/01/11/>
+
+NO!!!! No more huge patch bombs to [email protected] people!
+ <http://marc.theaimsgroup.com/?l=linux-kernel&m=112112749912944&w=2>
+
+Kernel Documentation/CodingStyle:
+ <http://sosdg.org/~coywolf/lxr/source/Documentation/CodingStyle>
+
+Linus Torvalds's mail on the canonical patch format:
+ <http://lkml.org/lkml/2005/4/7/183>
+--
--
1.5.3.8

2008-01-25 07:14:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 005/196] Chinese: add translation of SubmittingDrivers

From: Li Yang <[email protected]>

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/SubmittingDrivers | 168 +++++++++++++++++++++++++++++++++
1 files changed, 168 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/SubmittingDrivers

diff --git a/Documentation/zh_CN/SubmittingDrivers b/Documentation/zh_CN/SubmittingDrivers
new file mode 100644
index 0000000..5f4815c
--- /dev/null
+++ b/Documentation/zh_CN/SubmittingDrivers
@@ -0,0 +1,168 @@
+Chinese translated version of Documentation/SubmittingDrivers
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: Li Yang <[email protected]>
+---------------------------------------------------------------------
+Documentation/SubmittingDrivers 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+中文版维护者: 李阳 Li Yang <[email protected]>
+中文版翻译者: 李阳 Li Yang <[email protected]>
+中文版校译者: 陈琦 Maggie Chen <[email protected]>
+ 王聪 Wang Cong <[email protected]>
+ 张巍 Zhang Wei <[email protected]>
+
+以下为正文
+---------------------------------------------------------------------
+
+如何向 Linux 内核提交驱动程序
+-----------------------------
+
+这篇文档将会解释如何向不同的内核源码树提交设备驱动程序。请注意,如果你感
+兴趣的是显卡驱动程序,你也许应该访问 XFree86 项目(http://www.xfree86.org/)
+和/或 X.org 项目 (http://x.org)。
+
+另请参阅 Documentation/SubmittingPatches 文档。
+
+
+分配设备号
+----------
+
+块设备和字符设备的主设备号与从设备号是由 Linux 命名编号分配权威 LANANA(
+现在是 Torben Mathiasen)负责分配。申请的网址是 http://www.lanana.org/。
+即使不准备提交到主流内核的设备驱动也需要在这里分配设备号。有关详细信息,
+请参阅 Documentation/devices.txt。
+
+如果你使用的不是已经分配的设备号,那么当你提交设备驱动的时候,它将会被强
+制分配一个新的设备号,即便这个设备号和你之前发给客户的截然不同。
+
+设备驱动的提交对象
+------------------
+
+Linux 2.0:
+ 此内核源码树不接受新的驱动程序。
+
+Linux 2.2:
+ 此内核源码树不接受新的驱动程序。
+
+Linux 2.4:
+ 如果所属的代码领域在内核的 MAINTAINERS 文件中列有一个总维护者,
+ 那么请将驱动程序提交给他。如果此维护者没有回应或者你找不到恰当的
+ 维护者,那么请联系 Willy Tarreau <[email protected]>。
+
+Linux 2.6:
+ 除了遵循和 2.4 版内核同样的规则外,你还需要在 linux-kernel 邮件
+ 列表上跟踪最新的 API 变化。向 Linux 2.6 内核提交驱动的顶级联系人
+ 是 Andrew Morton <[email protected]>。
+
+决定设备驱动能否被接受的条件
+----------------------------
+
+许可: 代码必须使用 GNU 通用公开许可证 (GPL) 提交给 Linux,但是
+ 我们并不要求 GPL 是唯一的许可。你或许会希望同时使用多种
+ 许可证发布,如果希望驱动程序可以被其他开源社区(比如BSD)
+ 使用。请参考 include/linux/module.h 文件中所列出的可被
+ 接受共存的许可。
+
+版权: 版权所有者必须同意使用 GPL 许可。最好提交者和版权所有者
+ 是相同个人或实体。否则,必需列出授权使用 GPL 的版权所有
+ 人或实体,以备验证之需。
+
+接口: 如果你的驱动程序使用现成的接口并且和其他同类的驱动程序行
+ 为相似,而不是去发明无谓的新接口,那么它将会更容易被接受。
+ 如果你需要一个 Linux 和 NT 的通用驱动接口,那么请在用
+ 户空间实现它。
+
+代码: 请使用 Documentation/CodingStyle 中所描述的 Linux 代码风
+ 格。如果你的某些代码段(例如那些与 Windows 驱动程序包共
+ 享的代码段)需要使用其他格式,而你却只希望维护一份代码,
+ 那么请将它们很好地区分出来,并且注明原因。
+
+可移植性: 请注意,指针并不永远是 32 位的,不是所有的计算机都使用小
+ 尾模式 (little endian) 存储数据,不是所有的人都拥有浮点
+ 单元,不要随便在你的驱动程序里嵌入 x86 汇编指令。只能在
+ x86 上运行的驱动程序一般是不受欢迎的。虽然你可能只有 x86
+ 硬件,很难测试驱动程序在其他平台上是否可用,但是确保代码
+ 可以被轻松地移植却是很简单的。
+
+清晰度: 做到所有人都能修补这个驱动程序将会很有好处,因为这样你将
+ 会直接收到修复的补丁而不是 bug 报告。如果你提交一个试图
+ 隐藏硬件工作机理的驱动程序,那么它将会被扔进废纸篓。
+
+电源管理: 因为 Linux 正在被很多移动设备和桌面系统使用,所以你的驱
+ 动程序也很有可能被使用在这些设备上。它应该支持最基本的电
+ 源管理,即在需要的情况下实现系统级休眠和唤醒要用到的
+ .suspend 和 .resume 函数。你应该检查你的驱动程序是否能正
+ 确地处理休眠与唤醒,如果实在无法确认,请至少把 .suspend
+ 函数定义成返回 -ENOSYS(功能未实现)错误。你还应该尝试确
+ 保你的驱动在什么都不干的情况下将耗电降到最低。要获得驱动
+ 程序测试的指导,请参阅
+ Documentation/power/drivers-testing.txt。有关驱动程序电
+ 源管理问题相对全面的概述,请参阅
+ Documentation/power/devices.txt。
+
+管理: 如果一个驱动程序的作者还在进行有效的维护,那么通常除了那
+ 些明显正确且不需要任何检查的补丁以外,其他所有的补丁都会
+ 被转发给作者。如果你希望成为驱动程序的联系人和更新者,最
+ 好在代码注释中写明并且在 MAINTAINERS 文件中加入这个驱动
+ 程序的条目。
+
+不影响设备驱动能否被接受的条件
+------------------------------
+
+供应商: 由硬件供应商来维护驱动程序通常是一件好事。不过,如果源码
+ 树里已经有其他人提供了可稳定工作的驱动程序,那么请不要期
+ 望“我是供应商”会成为内核改用你的驱动程序的理由。理想的情
+ 况是:供应商与现有驱动程序的作者合作,构建一个统一完美的
+ 驱动程序。
+
+作者: 驱动程序是由大的 Linux 公司研发还是由你个人编写,并不影
+ 响其是否能被内核接受。没有人对内核源码树享有特权。只要你
+ 充分了解内核社区,你就会发现这一点。
+
+
+资源列表
+--------
+
+Linux 内核主源码树:
+ ftp.??.kernel.org:/pub/linux/kernel/...
+ ?? == 你的国家代码,例如 "cn"、"us"、"uk"、"fr" 等等
+
+Linux 内核邮件列表:
+ [email protected]
+ [可通过向[email protected]发邮件来订阅]
+
+Linux 设备驱动程序,第三版(探讨 2.6.10 版内核):
+ http://lwn.net/Kernel/LDD3/ (免费版)
+
+LWN.net:
+ 每周内核开发活动摘要 - http://lwn.net/
+ 2.6 版中 API 的变更:
+ http://lwn.net/Articles/2.6-kernel-api/
+ 将旧版内核的驱动程序移植到 2.6 版:
+ http://lwn.net/Articles/driver-porting/
+
+KernelTrap:
+ Linux 内核的最新动态以及开发者访谈
+ http://kerneltrap.org/
+
+内核新手(KernelNewbies):
+ 为新的内核开发者提供文档和帮助
+ http://kernelnewbies.org/
+
+Linux USB项目:
+ http://www.linux-usb.org/
+
+写内核驱动的“不要”(Arjan van de Ven著):
+ http://www.fenrus.org/how-to-not-write-a-device-driver-paper.pdf
+
+内核清洁工 (Kernel Janitor):
+ http://janitor.kernelnewbies.org/
--
1.5.3.8

2008-01-25 07:15:09

by Greg KH

[permalink] [raw]
Subject: [PATCH 006/196] Chinese: add translation of oops-tracing.txt

From: Dave Young <[email protected]>

Signed-off-by: Dave Young <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/oops-tracing.txt | 212 ++++++++++++++++++++++++++++++++++
1 files changed, 212 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/oops-tracing.txt

diff --git a/Documentation/zh_CN/oops-tracing.txt b/Documentation/zh_CN/oops-tracing.txt
new file mode 100644
index 0000000..9312608
--- /dev/null
+++ b/Documentation/zh_CN/oops-tracing.txt
@@ -0,0 +1,212 @@
+Chinese translated version of Documentation/oops-tracing.txt
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: Dave Young <[email protected]>
+---------------------------------------------------------------------
+Documentation/oops-tracing.txt 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+中文版维护者: 杨瑞 Dave Young <[email protected]>
+中文版翻译者: 杨瑞 Dave Young <[email protected]>
+中文版校译者: 李阳 Li Yang <[email protected]>
+ 王聪 Wang Cong <[email protected]>
+
+以下为正文
+---------------------------------------------------------------------
+
+注意: ksymoops 在2.6中是没有用的。 请以原有格式使用Oops(来自dmesg,等等)。
+忽略任何这样那样关于“解码Oops”或者“通过ksymoops运行”的文档。 如果你贴出运行过
+ksymoops的来自2.6的Oops,人们只会让你重贴一次。
+
+快速总结
+-------------
+
+发现Oops并发送给看似相关的内核领域的维护者。别太担心对不上号。如果你不确定就发给
+和你所做的事情相关的代码的负责人。 如果可重现试着描述怎样重构。 那甚至比oops更有
+价值。
+
+如果你对于发送给谁一无所知, 发给[email protected]。感谢你帮助Linux
+尽可能地稳定。
+
+Oops在哪里?
+----------------------
+
+通常Oops文本由klogd从内核缓冲区里读取并传给syslogd,由syslogd写到syslog文件中,
+典型地是/var/log/messages(依赖于/etc/syslog.conf)。有时klogd崩溃了,这种情况下你
+能够运行dmesg > file来从内核缓冲区中读取数据并保存下来。 否则你可以
+cat /proc/kmsg > file, 然而你必须介入中止传输, kmsg是一个“永不结束的文件”。如
+果机器崩溃坏到你不能输入命令或者磁盘不可用那么你有三种选择:-
+
+(1) 手抄屏幕上的文本待机器重启后再输入计算机。 麻烦但如果没有针对崩溃的准备,
+这是仅有的选择。 另外,你可以用数码相机把屏幕拍下来-不太好,但比没有强。 如果信
+息滚动到了终端的上面,你会发现以高分辩率启动(比如,vga=791)会让你读到更多的文
+本。(注意:这需要vesafb,所以对‘早期’的oops没有帮助)
+
+(2)用串口终端启动(请参看Documentation/serial-console.txt),运行一个null
+modem到另一台机器并用你喜欢的通讯工具获取输出。Minicom工作地很好。
+
+(3)使用Kdump(请参看Documentation/kdump/kdump.txt),
+使用在Documentation/kdump/gdbmacros.txt中定义的dmesg gdb宏,从旧的内存中提取内核
+环形缓冲区。
+
+完整信息
+----------------
+
+注意:以下来自于Linus的邮件适用于2.4内核。 我因为历史原因保留了它,并且因为其中
+一些信息仍然适用。 特别注意的是,请忽略任何ksymoops的引用。
+
+From: Linus Torvalds <[email protected]>
+
+怎样跟踪Oops.. [原发到linux-kernel的一封邮件]
+
+主要的窍门是有五年和这些烦人的oops消息打交道的经验;-)
+
+实际上,你有办法使它更简单。我有两个不同的方法:
+
+ gdb /usr/src/linux/vmlinux
+ gdb> disassemble <offending_function>
+
+那是发现问题的简单办法,至少如果bug报告做的好的情况下(象这个一样-运行ksymoops
+得到oops发生的函数及函数内的偏移)。
+
+哦,如果报告发生的内核以相同的编译器和相似的配置编译它会有帮助的。
+
+另一件要做的事是反汇编bug报告的“Code”部分:ksymoops也会用正确的工具来做这件事,
+但如果没有那些工具你可以写一个傻程序:
+
+ char str[] = "\xXX\xXX\xXX...";
+ main(){}
+
+并用gcc -g编译它然后执行“disassemble str”(XX部分是由Oops报告的值-你可以仅剪切
+粘贴并用“\x”替换空格-我就是这么做的,因为我懒得写程序自动做这一切)。
+
+另外,你可以用scripts/decodecode这个shell脚本。它的使用方法是:
+decodecode < oops.txt
+
+“Code”之后的十六进制字节可能(在某些架构上)有一些当前指令之前的指令字节以及
+当前和之后的指令字节
+
+Code: f9 0f 8d f9 00 00 00 8d 42 0c e8 dd 26 11 c7 a1 60 ea 2b f9 8b 50 08 a1
+64 ea 2b f9 8d 34 82 8b 1e 85 db 74 6d 8b 15 60 ea 2b f9 <8b> 43 04 39 42 54
+7e 04 40 89 42 54 8b 43 04 3b 05 00 f6 52 c0
+
+最后,如果你想知道代码来自哪里,你可以:
+
+ cd /usr/src/linux
+ make fs/buffer.s # 或任何产生BUG的文件
+
+然后你会比gdb反汇编更清楚的知道发生了什么。
+
+现在,问题是把你所拥有的所有数据结合起来:C源码(关于它应该怎样的一般知识),
+汇编代码及其反汇编得到的代码(另外还有从“oops”消息得到的寄存器状态-对了解毁坏的
+指针有用,而且当你有了汇编代码你也能拿其它的寄存器和任何它们对应的C表达式做匹配
+)。
+
+实际上,你仅需看看哪里不匹配(这个例子是“Code”反汇编和编译器生成的代码不匹配)。
+然后你须要找出为什么不匹配。通常很简单-你看到代码使用了空指针然后你看代码想知道
+空指针是怎么出现的,还有检查它是否合法..
+
+现在,如果明白这是一项耗时的工作而且需要一丁点儿的专心,没错。这就是我为什么大多
+只是忽略那些没有符号表信息的崩溃报告的原因:简单的说太难查找了(我有一些
+程序用于在内核代码段中搜索特定的模式,而且有时我也已经能找出那些崩溃的地方,但是
+仅仅是找出正确的序列也确实需要相当扎实的内核知识)
+
+_有时_会发生这种情况,我仅看到崩溃中的反汇编代码序列, 然后我马上就明白问题出在
+哪里。这时我才意识到自己干这个工作已经太长时间了;-)
+
+ Linus
+
+
+---------------------------------------------------------------------------
+关于Oops跟踪的注解:
+
+为了帮助Linus和其它内核开发者,klogd纳入了大量的支持来处理保护错误。为了拥有对
+地址解析的完整支持至少应该使用1.3-pl3的sysklogd包。
+
+当保护错误发生时,klogd守护进程自动把内核日志信息中的重要地址翻译成它们相应的符
+号。
+
+klogd执行两种类型的地址解析。首先是静态翻译其次是动态翻译。静态翻译和ksymoops
+一样使用System.map文件。为了做静态翻译klogd守护进程必须在初始化时能找到system
+map文件。关于klogd怎样搜索map文件请参看klogd手册页。
+
+动态地址翻译在使用内核可装载模块时很重要。 因为内核模块的内存是从内核动态内存池
+里分配的,所以不管是模块开始位置还是模块中函数和符号的位置都不是固定的。
+
+内核支持允许程序决定装载哪些模块和它们在内存中位置的系统调用。使用这些系统调用
+klogd守护进程生成一张符号表用于调试发生在可装载模块中的保护错误。
+
+至少klogd会提供产生保护错误的模块名。还可有额外的符号信息供可装载模块开发者选择
+以从模块中输出符号信息。
+
+因为内核模块环境可能是动态的,所以必须有一种机制当模块环境发生改变时来通知klogd
+守护进程。 有一些可用的命令行选项允许klogd向当前执行中的守护进程发送信号,告知符
+号信息应该被刷新了。 更多信息请参看klogd手册页。
+
+sysklogd发布时包含一个补丁修改了modules-2.0.0包,无论何时一个模块装载或者卸载都
+会自动向klogd发送信号。打上这个补丁提供了必要的对调试发生于内核可装载模块的保护
+错误的无缝支持。
+
+以下是被klogd处理过的发生在可装载模块中的一个保护错误例子:
+---------------------------------------------------------------------------
+Aug 29 09:51:01 blizard kernel: Unable to handle kernel paging request at virtual address f15e97cc
+Aug 29 09:51:01 blizard kernel: current->tss.cr3 = 0062d000, %cr3 = 0062d000
+Aug 29 09:51:01 blizard kernel: *pde = 00000000
+Aug 29 09:51:01 blizard kernel: Oops: 0002
+Aug 29 09:51:01 blizard kernel: CPU: 0
+Aug 29 09:51:01 blizard kernel: EIP: 0010:[oops:_oops+16/3868]
+Aug 29 09:51:01 blizard kernel: EFLAGS: 00010212
+Aug 29 09:51:01 blizard kernel: eax: 315e97cc ebx: 003a6f80 ecx: 001be77b edx: 00237c0c
+Aug 29 09:51:01 blizard kernel: esi: 00000000 edi: bffffdb3 ebp: 00589f90 esp: 00589f8c
+Aug 29 09:51:01 blizard kernel: ds: 0018 es: 0018 fs: 002b gs: 002b ss: 0018
+Aug 29 09:51:01 blizard kernel: Process oops_test (pid: 3374, process nr: 21, stackpage=00589000)
+Aug 29 09:51:01 blizard kernel: Stack: 315e97cc 00589f98 0100b0b4 bffffed4 0012e38e 00240c64 003a6f80 00000001
+Aug 29 09:51:01 blizard kernel: 00000000 00237810 bfffff00 0010a7fa 00000003 00000001 00000000 bfffff00
+Aug 29 09:51:01 blizard kernel: bffffdb3 bffffed4 ffffffda 0000002b 0007002b 0000002b 0000002b 00000036
+Aug 29 09:51:01 blizard kernel: Call Trace: [oops:_oops_ioctl+48/80] [_sys_ioctl+254/272] [_system_call+82/128]
+Aug 29 09:51:01 blizard kernel: Code: c7 00 05 00 00 00 eb 08 90 90 90 90 90 90 90 90 89 ec 5d c3
+---------------------------------------------------------------------------
+
+Dr. G.W. Wettstein Oncology Research Div. Computing Facility
+Roger Maris Cancer Center INTERNET: [email protected]
+820 4th St. N.
+Fargo, ND 58122
+Phone: 701-234-7556
+
+
+---------------------------------------------------------------------------
+受污染的内核
+
+一些oops报告在程序记数器之后包含字符串'Tainted: '。这表明内核已经被一些东西给污
+染了。 该字符串之后紧跟着一系列的位置敏感的字符,每个代表一个特定的污染值。
+
+ 1:'G'如果所有装载的模块都有GPL或相容的许可证,'P'如果装载了任何的专有模块。
+没有模块MODULE_LICENSE或者带有insmod认为是与GPL不相容的的MODULE_LICENSE的模块被
+认定是专有的。
+
+ 2:'F'如果有任何通过“insmod -f”被强制装载的模块,' '如果所有模块都被正常装载。
+
+ 3:'S'如果oops发生在SMP内核中,运行于没有证明安全运行多处理器的硬件。 当前这种
+情况仅限于几种不支持SMP的速龙处理器。
+
+ 4:'R'如果模块通过“insmod -f”被强制装载,' '如果所有模块都被正常装载。
+
+ 5:'M'如果任何处理器报告了机器检查异常,' '如果没有发生机器检查异常。
+
+ 6:'B'如果页释放函数发现了一个错误的页引用或者一些非预期的页标志。
+
+ 7:'U'如果用户或者用户应用程序特别请求设置污染标志,否则' '。
+
+ 8:'D'如果内核刚刚死掉,比如有OOPS或者BUG。
+
+使用'Tainted: '字符串的主要原因是要告诉内核调试者,这是否是一个干净的内核亦或发
+生了任何的不正常的事。污染是永久的:即使出错的模块已经被卸载了,污染值仍然存在,
+以表明内核不再值得信任。
--
1.5.3.8

2008-01-25 07:15:37

by Greg KH

[permalink] [raw]
Subject: [PATCH 007/196] Chinese: add translation of stable_kernel_rules.txt

From: TripleX Chung <[email protected]>

Signed-off-by: TripleX Chung <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/stable_kernel_rules.txt | 66 +++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/stable_kernel_rules.txt

diff --git a/Documentation/zh_CN/stable_kernel_rules.txt b/Documentation/zh_CN/stable_kernel_rules.txt
new file mode 100644
index 0000000..b5b9b0a
--- /dev/null
+++ b/Documentation/zh_CN/stable_kernel_rules.txt
@@ -0,0 +1,66 @@
+Chinese translated version of Documentation/stable_kernel_rules.txt
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: TripleX Chung <[email protected]>
+---------------------------------------------------------------------
+Documentation/stable_kernel_rules.txt 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+
+中文版维护者: 钟宇 TripleX Chung <[email protected]>
+中文版翻译者: 钟宇 TripleX Chung <[email protected]>
+中文版校译者: 李阳 Li Yang <[email protected]>
+ Kangkai Yin <[email protected]>
+
+以下为正文
+---------------------------------------------------------------------
+
+关于Linux 2.6稳定版发布,所有你想知道的事情。
+
+关于哪些类型的补丁可以被接收进入稳定版代码树,哪些不可以的规则:
+
+ - 必须是显而易见的正确,并且经过测试的。
+ - 连同上下文,不能大于100行。
+ - 必须只修正一件事情。
+ - 必须修正了一个给大家带来麻烦的真正的bug(不是“这也许是一个问题...”
+ 那样的东西)。
+ - 必须修正带来如下后果的问题:编译错误(对被标记为CONFIG_BROKEN的例外),
+ 内核崩溃,挂起,数据损坏,真正的安全问题,或者一些类似“哦,这不
+ 好”的问题。简短的说,就是一些致命的问题。
+ - 没有“理论上的竞争条件”,除非能给出竞争条件如何被利用的解释。
+ - 不能存在任何的“琐碎的”修正(拼写修正,去掉多余空格之类的)。
+ - 必须被相关子系统的维护者接受。
+ - 必须遵循Documentation/SubmittingPatches里的规则。
+
+向稳定版代码树提交补丁的过程:
+
+ - 在确认了补丁符合以上的规则后,将补丁发送到[email protected]
+ - 如果补丁被接受到队列里,发送者会收到一个ACK回复,如果没有被接受,收
+ 到的是NAK回复。回复需要几天的时间,这取决于开发者的时间安排。
+ - 被接受的补丁会被加到稳定版本队列里,等待其他开发者的审查。
+ - 安全方面的补丁不要发到这个列表,应该发送到[email protected]
+
+审查周期:
+
+ - 当稳定版的维护者决定开始一个审查周期,补丁将被发送到审查委员会,以
+ 及被补丁影响的领域的维护者(除非提交者就是该领域的维护者)并且抄送
+ 到linux-kernel邮件列表。
+ - 审查委员会有48小时的时间,用来决定给该补丁回复ACK还是NAK。
+ - 如果委员会中有成员拒绝这个补丁,或者linux-kernel列表上有人反对这个
+ 补丁,并提出维护者和审查委员会之前没有意识到的问题,补丁会从队列中
+ 丢弃。
+ - 在审查周期结束的时候,那些得到ACK回应的补丁将会被加入到最新的稳定版
+ 发布中,一个新的稳定版发布就此产生。
+ - 安全性补丁将从内核安全小组那里直接接收到稳定版代码树中,而不是通过
+ 通常的审查周期。请联系内核安全小组以获得关于这个过程的更多细节。
+
+审查委员会:
+ - 由一些自愿承担这项任务的内核开发者,和几个非志愿的组成。
--
1.5.3.8

2008-01-25 07:15:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 008/196] Chinese: add translation of volatile-considered-harmful.txt

From: Bryan Wu <[email protected]>

Signed-off-by: Bryan Wu <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
.../zh_CN/volatile-considered-harmful.txt | 113 ++++++++++++++++++++
1 files changed, 113 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/volatile-considered-harmful.txt

diff --git a/Documentation/zh_CN/volatile-considered-harmful.txt b/Documentation/zh_CN/volatile-considered-harmful.txt
new file mode 100644
index 0000000..ba8149d
--- /dev/null
+++ b/Documentation/zh_CN/volatile-considered-harmful.txt
@@ -0,0 +1,113 @@
+Chinese translated version of Documentation/volatile-considered-harmful.txt
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Maintainer: Jonathan Corbet <[email protected]>
+Chinese maintainer: Bryan Wu <[email protected]>
+---------------------------------------------------------------------
+Documentation/volatile-considered-harmful.txt 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+英文版维护者: Jonathan Corbet <[email protected]>
+中文版维护者: 伍鹏 Bryan Wu <[email protected]>
+中文版翻译者: 伍鹏 Bryan Wu <[email protected]>
+中文版校译者: 张汉辉 Eugene Teo <[email protected]>
+ 杨瑞 Dave Young <[email protected]>
+以下为正文
+---------------------------------------------------------------------
+
+为什么不应该使用“volatile”类型
+------------------------------
+
+C程序员通常认为volatile表示某个变量可以在当前执行的线程之外被改变;因此,在内核
+中用到共享数据结构时,常常会有C程序员喜欢使用volatile这类变量。换句话说,他们经
+常会把volatile类型看成某种简易的原子变量,当然它们不是。在内核中使用volatile几
+乎总是错误的;本文档将解释为什么这样。
+
+理解volatile的关键是知道它的目的是用来消除优化,实际上很少有人真正需要这样的应
+用。在内核中,程序员必须防止意外的并发访问破坏共享的数据结构,这其实是一个完全
+不同的任务。用来防止意外并发访问的保护措施,可以更加高效的避免大多数优化相关的
+问题。
+
+像volatile一样,内核提供了很多原语来保证并发访问时的数据安全(自旋锁, 互斥量,内
+存屏障等等),同样可以防止意外的优化。如果可以正确使用这些内核原语,那么就没有
+必要再使用volatile。如果仍然必须使用volatile,那么几乎可以肯定在代码的某处有一
+个bug。在正确设计的内核代码中,volatile能带来的仅仅是使事情变慢。
+
+思考一下这段典型的内核代码:
+
+ spin_lock(&the_lock);
+ do_something_on(&shared_data);
+ do_something_else_with(&shared_data);
+ spin_unlock(&the_lock);
+
+如果所有的代码都遵循加锁规则,当持有the_lock的时候,不可能意外的改变shared_data的
+值。任何可能访问该数据的其他代码都会在这个锁上等待。自旋锁原语跟内存屏障一样—— 它
+们显式的用来书写成这样 —— 意味着数据访问不会跨越它们而被优化。所以本来编译器认为
+它知道在shared_data里面将有什么,但是因为spin_lock()调用跟内存屏障一样,会强制编
+译器忘记它所知道的一切。那么在访问这些数据时不会有优化的问题。
+
+如果shared_data被声名为volatile,锁操作将仍然是必须的。就算我们知道没有其他人正在
+使用它,编译器也将被阻止优化对临界区内shared_data的访问。在锁有效的同时,
+shared_data不是volatile的。在处理共享数据的时候,适当的锁操作可以不再需要
+volatile —— 并且是有潜在危害的。
+
+volatile的存储类型最初是为那些内存映射的I/O寄存器而定义。在内核里,寄存器访问也应
+该被锁保护,但是人们也不希望编译器“优化”临界区内的寄存器访问。内核里I/O的内存访问
+是通过访问函数完成的;不赞成通过指针对I/O内存的直接访问,并且不是在所有体系架构上
+都能工作。那些访问函数正是为了防止意外优化而写的,因此,再说一次,volatile类型不
+是必需的。
+
+另一种引起用户可能使用volatile的情况是当处理器正忙着等待一个变量的值。正确执行一
+个忙等待的方法是:
+
+ while (my_variable != what_i_want)
+ cpu_relax();
+
+cpu_relax()调用会降低CPU的能量消耗或者让位于超线程双处理器;它也作为内存屏障一样出
+现,所以,再一次,volatile不是必需的。当然,忙等待一开始就是一种反常规的做法。
+
+在内核中,一些稀少的情况下volatile仍然是有意义的:
+
+ - 在一些体系架构的系统上,允许直接的I/0内存访问,那么前面提到的访问函数可以使用
+ volatile。基本上,每一个访问函数调用它自己都是一个小的临界区域并且保证了按照
+ 程序员期望的那样发生访问操作。
+
+ - 某些会改变内存的内联汇编代码虽然没有什么其他明显的附作用,但是有被GCC删除的可
+ 能性。在汇编声明中加上volatile关键字可以防止这种删除操作。
+
+ - Jiffies变量是一种特殊情况,虽然每次引用它的时候都可以有不同的值,但读jiffies
+ 变量时不需要任何特殊的加锁保护。所以jiffies变量可以使用volatile,但是不赞成
+ 其他跟jiffies相同类型变量使用volatile。Jiffies被认为是一种“愚蠢的遗留物"
+ (Linus的话)因为解决这个问题比保持现状要麻烦的多。
+
+ - 由于某些I/0设备可能会修改连续一致的内存,所以有时,指向连续一致内存的数据结构
+ 的指针需要正确的使用volatile。网络适配器使用的环状缓存区正是这类情形的一个例
+ 子,其中适配器用改变指针来表示哪些描述符已经处理过了。
+
+对于大多代码,上述几种可以使用volatile的情况都不适用。所以,使用volatile是一种
+bug并且需要对这样的代码额外仔细检查。那些试图使用volatile的开发人员需要退一步想想
+他们真正想实现的是什么。
+
+非常欢迎删除volatile变量的补丁 - 只要证明这些补丁完整的考虑了并发问题。
+
+注释
+----
+
+[1] http://lwn.net/Articles/233481/
+[2] http://lwn.net/Articles/233482/
+
+致谢
+----
+
+最初由Randy Dunlap推动并作初步研究
+由Jonathan Corbet撰写
+参考Satyam Sharma,Johannes Stezenbach,Jesper Juhl,Heikki Orsila,
+H. Peter Anvin,Philipp Hahn和Stefan Richter的意见改善了本档。
--
1.5.3.8

2008-01-25 07:16:18

by Greg KH

[permalink] [raw]
Subject: [PATCH 009/196] Chinese: add translation of sparse.txt

From: Li Yang <[email protected]>

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/sparse.txt | 100 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 100 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/sparse.txt

diff --git a/Documentation/zh_CN/sparse.txt b/Documentation/zh_CN/sparse.txt
new file mode 100644
index 0000000..75992a6
--- /dev/null
+++ b/Documentation/zh_CN/sparse.txt
@@ -0,0 +1,100 @@
+Chinese translated version of Documentation/sparse.txt
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: Li Yang <[email protected]>
+---------------------------------------------------------------------
+Documentation/sparse.txt 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+中文版维护者: 李阳 Li Yang <[email protected]>
+中文版翻译者: 李阳 Li Yang <[email protected]>
+
+
+以下为正文
+---------------------------------------------------------------------
+
+Copyright 2004 Linus Torvalds
+Copyright 2004 Pavel Machek <[email protected]>
+Copyright 2006 Bob Copeland <[email protected]>
+
+使用 sparse 工具做类型检查
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+"__bitwise" 是一种类型属性,所以你应该这样使用它:
+
+ typedef int __bitwise pm_request_t;
+
+ enum pm_request {
+ PM_SUSPEND = (__force pm_request_t) 1,
+ PM_RESUME = (__force pm_request_t) 2
+ };
+
+这样会使 PM_SUSPEND 和 PM_RESUME 成为位方式(bitwise)整数(使用"__force"
+是因为 sparse 会抱怨改变位方式的类型转换,但是这里我们确实需要强制进行转
+换)。而且因为所有枚举值都使用了相同的类型,这里的"enum pm_request"也将
+会使用那个类型做为底层实现。
+
+而且使用 gcc 编译的时候,所有的 __bitwise/__force 都会消失,最后在 gcc
+看来它们只不过是普通的整数。
+
+坦白来说,你并不需要使用枚举类型。上面那些实际都可以浓缩成一个特殊的"int
+__bitwise"类型。
+
+所以更简单的办法只要这样做:
+
+ typedef int __bitwise pm_request_t;
+
+ #define PM_SUSPEND ((__force pm_request_t) 1)
+ #define PM_RESUME ((__force pm_request_t) 2)
+
+现在你就有了严格的类型检查所需要的所有基础架构。
+
+一个小提醒:常数整数"0"是特殊的。你可以直接把常数零当作位方式整数使用而
+不用担心 sparse 会抱怨。这是因为"bitwise"(恰如其名)是用来确保不同位方
+式类型不会被弄混(小尾模式,大尾模式,cpu尾模式,或者其他),对他们来说
+常数"0"确实是特殊的。
+
+获取 sparse 工具
+~~~~~~~~~~~~~~~~
+
+你可以从 Sparse 的主页获取最新的发布版本:
+
+ http://www.kernel.org/pub/linux/kernel/people/josh/sparse/
+
+或者,你也可以使用 git 克隆最新的 sparse 开发版本:
+
+ git://git.kernel.org/pub/scm/linux/kernel/git/josh/sparse.git
+
+DaveJ 把每小时自动生成的 git 源码树 tar 包放在以下地址:
+
+ http://www.codemonkey.org.uk/projects/git-snapshots/sparse/
+
+一旦你下载了源码,只要以普通用户身份运行:
+
+ make
+ make install
+
+它将会被自动安装到你的 ~/bin 目录下。
+
+使用 sparse 工具
+~~~~~~~~~~~~~~~~
+
+用"make C=1"命令来编译内核,会对所有重新编译的 C 文件使用 sparse 工具。
+或者使用"make C=2"命令,无论文件是否被重新编译都会对其使用 sparse 工具。
+如果你已经编译了内核,用后一种方式可以很快地检查整个源码树。
+
+make 的可选变量 CHECKFLAGS 可以用来向 sparse 工具传递参数。编译系统会自
+动向 sparse 工具传递 -Wbitwise 参数。你可以定义 __CHECK_ENDIAN__ 来进行
+大小尾检查。
+
+ make C=2 CHECKFLAGS="-D__CHECK_ENDIAN__"
+
+这些检查默认都是被关闭的,因为他们通常会产生大量的警告。
--
1.5.3.8

2008-01-25 07:16:41

by Greg KH

[permalink] [raw]
Subject: [PATCH 010/196] Chinese: add translation of Codingstyle

From: Zhang Le <[email protected]>

Signed-off-by: Zhang Le <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/CodingStyle | 701 +++++++++++++++++++++++++++++++++++++++
1 files changed, 701 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/CodingStyle

diff --git a/Documentation/zh_CN/CodingStyle b/Documentation/zh_CN/CodingStyle
new file mode 100644
index 0000000..ecd9307
--- /dev/null
+++ b/Documentation/zh_CN/CodingStyle
@@ -0,0 +1,701 @@
+Chinese translated version of Documentation/CodingStyle
+
+If you have any comment or update to the content, please post to LKML directly.
+However, if you have problem communicating in English you can also ask the
+Chinese maintainer for help. Contact the Chinese maintainer, if this
+translation is outdated or there is problem with translation.
+
+Chinese maintainer: Zhang Le <[email protected]>
+---------------------------------------------------------------------
+Documentation/CodingStyle的中文翻译
+
+如果想评论或更新本文的内容,请直接发信到LKML。如果你使用英文交流有困难的话,也可
+以向中文版维护者求助。如果本翻译更新不及时或者翻译存在问题,请联系中文版维护者。
+
+中文版维护者: 张乐 Zhang Le <[email protected]>
+中文版翻译者: 张乐 Zhang Le <[email protected]>
+中文版校译者: 王聪 Wang Cong <[email protected]>
+ wheelz <[email protected]>
+ 管旭东 Xudong Guan <[email protected]>
+ Li Zefan <[email protected]>
+ Wang Chen <[email protected]>
+以下为正文
+---------------------------------------------------------------------
+
+ Linux内核代码风格
+
+这是一个简短的文档,描述了linux内核的首选代码风格。代码风格是因人而异的,而且我
+不愿意把我的观点强加给任何人,不过这里所讲述的是我必须要维护的代码所遵守的风格,
+并且我也希望绝大多数其他代码也能遵守这个风格。请在写代码时至少考虑一下本文所述的
+风格。
+
+首先,我建议你打印一份GNU代码规范,然后不要读它。烧了它,这是一个具有重大象征性
+意义的动作。
+
+不管怎样,现在我们开始:
+
+
+ 第一章:缩进
+
+制表符是8个字符,所以缩进也是8个字符。有些异端运动试图将缩进变为4(乃至2)个字符
+深,这几乎相当于尝试将圆周率的值定义为3。
+
+理由:缩进的全部意义就在于清楚的定义一个控制块起止于何处。尤其是当你盯着你的屏幕
+连续看了20小时之后,你将会发现大一点的缩进会使你更容易分辨缩进。
+
+现在,有些人会抱怨8个字符的缩进会使代码向右边移动的太远,在80个字符的终端屏幕上
+就很难读这样的代码。这个问题的答案是,如果你需要3级以上的缩进,不管用何种方式你
+的代码已经有问题了,应该修正你的程序。
+
+简而言之,8个字符的缩进可以让代码更容易阅读,还有一个好处是当你的函数嵌套太深的
+时候可以给你警告。留心这个警告。
+
+在switch语句中消除多级缩进的首选的方式是让“switch”和从属于它的“case”标签对齐于同
+一列,而不要“两次缩进”“case”标签。比如:
+
+ switch (suffix) {
+ case 'G':
+ case 'g':
+ mem <<= 30;
+ break;
+ case 'M':
+ case 'm':
+ mem <<= 20;
+ break;
+ case 'K':
+ case 'k':
+ mem <<= 10;
+ /* fall through */
+ default:
+ break;
+ }
+
+
+不要把多个语句放在一行里,除非你有什么东西要隐藏:
+
+ if (condition) do_this;
+ do_something_everytime;
+
+也不要在一行里放多个赋值语句。内核代码风格超级简单。就是避免可能导致别人误读的表
+达式。
+
+除了注释、文档和Kconfig之外,不要使用空格来缩进,前面的例子是例外,是有意为之。
+
+选用一个好的编辑器,不要在行尾留空格。
+
+
+ 第二章:把长的行和字符串打散
+
+代码风格的意义就在于使用平常使用的工具来维持代码的可读性和可维护性。
+
+每一行的长度的限制是80列,我们强烈建议您遵守这个惯例。
+
+长于80列的语句要打散成有意义的片段。每个片段要明显短于原来的语句,而且放置的位置
+也明显的靠右。同样的规则也适用于有很长参数列表的函数头。长字符串也要打散成较短的
+字符串。唯一的例外是超过80列可以大幅度提高可读性并且不会隐藏信息的情况。
+
+void fun(int a, int b, int c)
+{
+ if (condition)
+ printk(KERN_WARNING "Warning this is a long printk with "
+ "3 parameters a: %u b: %u "
+ "c: %u \n", a, b, c);
+ else
+ next_statement;
+}
+
+ 第三章:大括号和空格的放置
+
+C语言风格中另外一个常见问题是大括号的放置。和缩进大小不同,选择或弃用某种放置策
+略并没有多少技术上的原因,不过首选的方式,就像Kernighan和Ritchie展示给我们的,是
+把起始大括号放在行尾,而把结束大括号放在行首,所以:
+
+ if (x is true) {
+ we do y
+ }
+
+这适用于所有的非函数语句块(if、switch、for、while、do)。比如:
+
+ switch (action) {
+ case KOBJ_ADD:
+ return "add";
+ case KOBJ_REMOVE:
+ return "remove";
+ case KOBJ_CHANGE:
+ return "change";
+ default:
+ return NULL;
+ }
+
+不过,有一个例外,那就是函数:函数的起始大括号放置于下一行的开头,所以:
+
+ int function(int x)
+ {
+ body of function
+ }
+
+全世界的异端可能会抱怨这个不一致性是……呃……不一致的,不过所有思维健全的人都知道(
+a)K&R是_正确的_,并且(b)K&R是正确的。此外,不管怎样函数都是特殊的(在C语言中
+,函数是不能嵌套的)。
+
+注意结束大括号独自占据一行,除非它后面跟着同一个语句的剩余部分,也就是do语句中的
+“while”或者if语句中的“else”,像这样:
+
+ do {
+ body of do-loop
+ } while (condition);
+
+和
+
+ if (x == y) {
+ ..
+ } else if (x > y) {
+ ...
+ } else {
+ ....
+ }
+
+理由:K&R。
+
+也请注意这种大括号的放置方式也能使空(或者差不多空的)行的数量最小化,同时不失可
+读性。因此,由于你的屏幕上的新行是不可再生资源(想想25行的终端屏幕),你将会有更
+多的空行来放置注释。
+
+当只有一个单独的语句的时候,不用加不必要的大括号。
+
+if (condition)
+ action();
+
+这点不适用于本身为某个条件语句的一个分支的单独语句。这时需要在两个分支里都使用大
+括号。
+
+if (condition) {
+ do_this();
+ do_that();
+} else {
+ otherwise();
+}
+
+ 3.1:空格
+
+Linux内核的空格使用方式(主要)取决于它是用于函数还是关键字。(大多数)关键字后
+要加一个空格。值得注意的例外是sizeof、typeof、alignof和__attribute__,这些关键字
+某些程度上看起来更像函数(它们在Linux里也常常伴随小括号而使用,尽管在C语言里这样
+的小括号不是必需的,就像“struct fileinfo info”声明过后的“sizeof info”)。
+
+所以在这些关键字之后放一个空格:
+ if, switch, case, for, do, while
+但是不要在sizeof、typeof、alignof或者__attribute__这些关键字之后放空格。例如,
+ s = sizeof(struct file);
+
+不要在小括号里的表达式两侧加空格。这是一个反例:
+
+ s = sizeof( struct file );
+
+当声明指针类型或者返回指针类型的函数时,“*”的首选使用方式是使之靠近变量名或者函
+数名,而不是靠近类型名。例子:
+
+ char *linux_banner;
+ unsigned long long memparse(char *ptr, char **retptr);
+ char *match_strdup(substring_t *s);
+
+在大多数二元和三元操作符两侧使用一个空格,例如下面所有这些操作符:
+
+ = + - < > * / % | & ^ <= >= == != ? :
+
+但是一元操作符后不要加空格:
+ & * + - ~ ! sizeof typeof alignof __attribute__ defined
+
+后缀自加和自减一元操作符前不加空格:
+ ++ --
+
+前缀自加和自减一元操作符后不加空格:
+ ++ --
+
+“.”和“->”结构体成员操作符前后不加空格。
+
+不要在行尾留空白。有些可以自动缩进的编辑器会在新行的行首加入适量的空白,然后你
+就可以直接在那一行输入代码。不过假如你最后没有在那一行输入代码,有些编辑器就不
+会移除已经加入的空白,就像你故意留下一个只有空白的行。包含行尾空白的行就这样产
+生了。
+
+当git发现补丁包含了行尾空白的时候会警告你,并且可以应你的要求去掉行尾空白;不过
+如果你是正在打一系列补丁,这样做会导致后面的补丁失败,因为你改变了补丁的上下文。
+
+
+ 第四章:命名
+
+C是一个简朴的语言,你的命名也应该这样。和Modula-2和Pascal程序员不同,C程序员不使
+用类似ThisVariableIsATemporaryCounter这样华丽的名字。C程序员会称那个变量为“tmp”
+,这样写起来会更容易,而且至少不会令其难于理解。
+
+不过,虽然混用大小写的名字是不提倡使用的,但是全局变量还是需要一个具描述性的名字
+。称一个全局函数为“foo”是一个难以饶恕的错误。
+
+全局变量(只有当你真正需要它们的时候再用它)需要有一个具描述性的名字,就像全局函
+数。如果你有一个可以计算活动用户数量的函数,你应该叫它“count_active_users()”或者
+类似的名字,你不应该叫它“cntuser()”。
+
+在函数名中包含函数类型(所谓的匈牙利命名法)是脑子出了问题——编译器知道那些类型而
+且能够检查那些类型,这样做只能把程序员弄糊涂了。难怪微软总是制造出有问题的程序。
+
+本地变量名应该简短,而且能够表达相关的含义。如果你有一些随机的整数型的循环计数器
+,它应该被称为“i”。叫它“loop_counter”并无益处,如果它没有被误解的可能的话。类似
+的,“tmp”可以用来称呼任意类型的临时变量。
+
+如果你怕混淆了你的本地变量名,你就遇到另一个问题了,叫做函数增长荷尔蒙失衡综合症
+。请看第六章(函数)。
+
+
+ 第五章:Typedef
+
+不要使用类似“vps_t”之类的东西。
+
+对结构体和指针使用typedef是一个错误。当你在代码里看到:
+
+ vps_t a;
+
+这代表什么意思呢?
+
+相反,如果是这样
+
+ struct virtual_container *a;
+
+你就知道“a”是什么了。
+
+很多人认为typedef“能提高可读性”。实际不是这样的。它们只在下列情况下有用:
+
+ (a) 完全不透明的对象(这种情况下要主动使用typedef来隐藏这个对象实际上是什么)。
+
+ 例如:“pte_t”等不透明对象,你只能用合适的访问函数来访问它们。
+
+ 注意!不透明性和“访问函数”本身是不好的。我们使用pte_t等类型的原因在于真的是
+ 完全没有任何共用的可访问信息。
+
+ (b) 清楚的整数类型,如此,这层抽象就可以帮助消除到底是“int”还是“long”的混淆。
+
+ u8/u16/u32是完全没有问题的typedef,不过它们更符合类别(d)而不是这里。
+
+ 再次注意!要这样做,必须事出有因。如果某个变量是“unsigned long“,那么没有必要
+
+ typedef unsigned long myflags_t;
+
+ 不过如果有一个明确的原因,比如它在某种情况下可能会是一个“unsigned int”而在
+ 其他情况下可能为“unsigned long”,那么就不要犹豫,请务必使用typedef。
+
+ (c) 当你使用sparse按字面的创建一个新类型来做类型检查的时候。
+
+ (d) 和标准C99类型相同的类型,在某些例外的情况下。
+
+ 虽然让眼睛和脑筋来适应新的标准类型比如“uint32_t”不需要花很多时间,可是有些
+ 人仍然拒绝使用它们。
+
+ 因此,Linux特有的等同于标准类型的“u8/u16/u32/u64”类型和它们的有符号类型是被
+ 允许的——尽管在你自己的新代码中,它们不是强制要求要使用的。
+
+ 当编辑已经使用了某个类型集的已有代码时,你应该遵循那些代码中已经做出的选择。
+
+ (e) 可以在用户空间安全使用的类型。
+
+ 在某些用户空间可见的结构体里,我们不能要求C99类型而且不能用上面提到的“u32”
+ 类型。因此,我们在与用户空间共享的所有结构体中使用__u32和类似的类型。
+
+可能还有其他的情况,不过基本的规则是永远不要使用typedef,除非你可以明确的应用上
+述某个规则中的一个。
+
+总的来说,如果一个指针或者一个结构体里的元素可以合理的被直接访问到,那么它们就不
+应该是一个typedef。
+
+
+ 第六章:函数
+
+函数应该简短而漂亮,并且只完成一件事情。函数应该可以一屏或者两屏显示完(我们都知
+道ISO/ANSI屏幕大小是80x24),只做一件事情,而且把它做好。
+
+一个函数的最大长度是和该函数的复杂度和缩进级数成反比的。所以,如果你有一个理论上
+很简单的只有一个很长(但是简单)的case语句的函数,而且你需要在每个case里做很多很
+小的事情,这样的函数尽管很长,但也是可以的。
+
+不过,如果你有一个复杂的函数,而且你怀疑一个天分不是很高的高中一年级学生可能甚至
+搞不清楚这个函数的目的,你应该严格的遵守前面提到的长度限制。使用辅助函数,并为之
+取个具描述性的名字(如果你觉得它们的性能很重要的话,可以让编译器内联它们,这样的
+效果往往会比你写一个复杂函数的效果要好。)
+
+函数的另外一个衡量标准是本地变量的数量。此数量不应超过5-10个,否则你的函数就有
+问题了。重新考虑一下你的函数,把它分拆成更小的函数。人的大脑一般可以轻松的同时跟
+踪7个不同的事物,如果再增多的话,就会糊涂了。即便你聪颖过人,你也可能会记不清你2
+个星期前做过的事情。
+
+在源文件里,使用空行隔开不同的函数。如果该函数需要被导出,它的EXPORT*宏应该紧贴
+在它的结束大括号之下。比如:
+
+int system_is_up(void)
+{
+ return system_state == SYSTEM_RUNNING;
+}
+EXPORT_SYMBOL(system_is_up);
+
+在函数原型中,包含函数名和它们的数据类型。虽然C语言里没有这样的要求,在Linux里这
+是提倡的做法,因为这样可以很简单的给读者提供更多的有价值的信息。
+
+
+ 第七章:集中的函数退出途径
+
+虽然被某些人声称已经过时,但是goto语句的等价物还是经常被编译器所使用,具体形式是
+无条件跳转指令。
+
+当一个函数从多个位置退出并且需要做一些通用的清理工作的时候,goto的好处就显现出来
+了。
+
+理由是:
+
+- 无条件语句容易理解和跟踪
+- 嵌套程度减小
+- 可以避免由于修改时忘记更新某个单独的退出点而导致的错误
+- 减轻了编译器的工作,无需删除冗余代码;)
+
+int fun(int a)
+{
+ int result = 0;
+ char *buffer = kmalloc(SIZE);
+
+ if (buffer == NULL)
+ return -ENOMEM;
+
+ if (condition1) {
+ while (loop1) {
+ ...
+ }
+ result = 1;
+ goto out;
+ }
+ ...
+out:
+ kfree(buffer);
+ return result;
+}
+
+ 第八章:注释
+
+注释是好的,不过有过度注释的危险。永远不要在注释里解释你的代码是如何运作的:更好
+的做法是让别人一看你的代码就可以明白,解释写的很差的代码是浪费时间。
+
+一般的,你想要你的注释告诉别人你的代码做了什么,而不是怎么做的。也请你不要把注释
+放在一个函数体内部:如果函数复杂到你需要独立的注释其中的一部分,你很可能需要回到
+第六章看一看。你可以做一些小注释来注明或警告某些很聪明(或者槽糕)的做法,但不要
+加太多。你应该做的,是把注释放在函数的头部,告诉人们它做了什么,也可以加上它做这
+些事情的原因。
+
+当注释内核API函数时,请使用kernel-doc格式。请看
+Documentation/kernel-doc-nano-HOWTO.txt和scripts/kernel-doc以获得详细信息。
+
+Linux的注释风格是C89“/* ... */”风格。不要使用C99风格“// ...”注释。
+
+长(多行)的首选注释风格是:
+
+ /*
+ * This is the preferred style for multi-line
+ * comments in the Linux kernel source code.
+ * Please use it consistently.
+ *
+ * Description: A column of asterisks on the left side,
+ * with beginning and ending almost-blank lines.
+ */
+
+注释数据也是很重要的,不管是基本类型还是衍生类型。为了方便实现这一点,每一行应只
+声明一个数据(不要使用逗号来一次声明多个数据)。这样你就有空间来为每个数据写一段
+小注释来解释它们的用途了。
+
+
+ 第九章:你已经把事情弄糟了
+
+这没什么,我们都是这样。可能你的使用了很长时间Unix的朋友已经告诉你“GNU emacs”能
+自动帮你格式化C源代码,而且你也注意到了,确实是这样,不过它所使用的默认值和我们
+想要的相去甚远(实际上,甚至比随机打的还要差——无数个猴子在GNU emacs里打字永远不
+会创造出一个好程序)(译注:请参考Infinite Monkey Theorem)
+
+所以你要么放弃GNU emacs,要么改变它让它使用更合理的设定。要采用后一个方案,你可
+以把下面这段粘贴到你的.emacs文件里。
+
+(defun linux-c-mode ()
+ "C mode with adjusted defaults for use with the Linux kernel."
+ (interactive)
+ (c-mode)
+ (c-set-style "K&R")
+ (setq tab-width 8)
+ (setq indent-tabs-mode t)
+ (setq c-basic-offset 8))
+
+这样就定义了M-x linux-c-mode命令。当你hack一个模块的时候,如果你把字符串
+-*- linux-c -*-放在头两行的某个位置,这个模式将会被自动调用。如果你希望在你修改
+/usr/src/linux里的文件时魔术般自动打开linux-c-mode的话,你也可能需要添加
+
+(setq auto-mode-alist (cons '("/usr/src/linux.*/.*\\.[ch]$" . linux-c-mode)
+ auto-mode-alist))
+
+到你的.emacs文件里。
+
+不过就算你尝试让emacs正确的格式化代码失败了,也并不意味着你失去了一切:还可以用“
+indent”。
+
+不过,GNU indent也有和GNU emacs一样有问题的设定,所以你需要给它一些命令选项。不
+过,这还不算太糟糕,因为就算是GNU indent的作者也认同K&R的权威性(GNU的人并不是坏
+人,他们只是在这个问题上被严重的误导了),所以你只要给indent指定选项“-kr -i8”
+(代表“K&R,8个字符缩进”),或者使用“scripts/Lindent”,这样就可以以最时髦的方式
+缩进源代码。
+
+“indent”有很多选项,特别是重新格式化注释的时候,你可能需要看一下它的手册页。不过
+记住:“indent”不能修正坏的编程习惯。
+
+
+ 第十章:Kconfig配置文件
+
+对于遍布源码树的所有Kconfig*配置文件来说,它们缩进方式与C代码相比有所不同。紧挨
+在“config”定义下面的行缩进一个制表符,帮助信息则再多缩进2个空格。比如:
+
+config AUDIT
+ bool "Auditing support"
+ depends on NET
+ help
+ Enable auditing infrastructure that can be used with another
+ kernel subsystem, such as SELinux (which requires this for
+ logging of avc messages output). Does not do system-call
+ auditing without CONFIG_AUDITSYSCALL.
+
+仍然被认为不够稳定的功能应该被定义为依赖于“EXPERIMENTAL”:
+
+config SLUB
+ depends on EXPERIMENTAL && !ARCH_USES_SLAB_PAGE_STRUCT
+ bool "SLUB (Unqueued Allocator)"
+ ...
+
+而那些危险的功能(比如某些文件系统的写支持)应该在它们的提示字符串里显著的声明这
+一点:
+
+config ADFS_FS_RW
+ bool "ADFS write support (DANGEROUS)"
+ depends on ADFS_FS
+ ...
+
+要查看配置文件的完整文档,请看Documentation/kbuild/kconfig-language.txt。
+
+
+ 第十一章:数据结构
+
+如果一个数据结构,在创建和销毁它的单线执行环境之外可见,那么它必须要有一个引用计
+数器。内核里没有垃圾收集(并且内核之外的垃圾收集慢且效率低下),这意味着你绝对需
+要记录你对这种数据结构的使用情况。
+
+引用计数意味着你能够避免上锁,并且允许多个用户并行访问这个数据结构——而不需要担心
+这个数据结构仅仅因为暂时不被使用就消失了,那些用户可能不过是沉睡了一阵或者做了一
+些其他事情而已。
+
+注意上锁不能取代引用计数。上锁是为了保持数据结构的一致性,而引用计数是一个内存管
+理技巧。通常二者都需要,不要把两个搞混了。
+
+很多数据结构实际上有2级引用计数,它们通常有不同“类”的用户。子类计数器统计子类用
+户的数量,每当子类计数器减至零时,全局计数器减一。
+
+这种“多级引用计数”的例子可以在内存管理(“struct mm_struct”:mm_users和mm_count)
+和文件系统(“struct super_block”:s_count和s_active)中找到。
+
+记住:如果另一个执行线索可以找到你的数据结构,但是这个数据结构没有引用计数器,这
+里几乎肯定是一个bug。
+
+
+ 第十二章:宏,枚举和RTL
+
+用于定义常量的宏的名字及枚举里的标签需要大写。
+
+#define CONSTANT 0x12345
+
+在定义几个相关的常量时,最好用枚举。
+
+宏的名字请用大写字母,不过形如函数的宏的名字可以用小写字母。
+
+一般的,如果能写成内联函数就不要写成像函数的宏。
+
+含有多个语句的宏应该被包含在一个do-while代码块里:
+
+#define macrofun(a, b, c) \
+ do { \
+ if (a == 5) \
+ do_this(b, c); \
+ } while (0)
+
+使用宏的时候应避免的事情:
+
+1) 影响控制流程的宏:
+
+#define FOO(x) \
+ do { \
+ if (blah(x) < 0) \
+ return -EBUGGERED; \
+ } while(0)
+
+非常不好。它看起来像一个函数,不过却能导致“调用”它的函数退出;不要打乱读者大脑里
+的语法分析器。
+
+2) 依赖于一个固定名字的本地变量的宏:
+
+#define FOO(val) bar(index, val)
+
+可能看起来像是个不错的东西,不过它非常容易把读代码的人搞糊涂,而且容易导致看起来
+不相关的改动带来错误。
+
+3) 作为左值的带参数的宏: FOO(x) = y;如果有人把FOO变成一个内联函数的话,这种用
+法就会出错了。
+
+4) 忘记了优先级:使用表达式定义常量的宏必须将表达式置于一对小括号之内。带参数的
+宏也要注意此类问题。
+
+#define CONSTANT 0x4000
+#define CONSTEXP (CONSTANT | 3)
+
+cpp手册对宏的讲解很详细。Gcc internals手册也详细讲解了RTL(译注:register
+transfer language),内核里的汇编语言经常用到它。
+
+
+ 第十三章:打印内核消息
+
+内核开发者应该是受过良好教育的。请一定注意内核信息的拼写,以给人以好的印象。不要
+用不规范的单词比如“dont”,而要用“do not”或者“don't”。保证这些信息简单、明了、无
+歧义。
+
+内核信息不必以句号(译注:英文句号,即点)结束。
+
+在小括号里打印数字(%d)没有任何价值,应该避免这样做。
+
+<linux/device.h>里有一些驱动模型诊断宏,你应该使用它们,以确保信息对应于正确的
+设备和驱动,并且被标记了正确的消息级别。这些宏有:dev_err(), dev_warn(),
+dev_info()等等。对于那些不和某个特定设备相关连的信息,<linux/kernel.h>定义了
+pr_debug()和pr_info()。
+
+写出好的调试信息可以是一个很大的挑战;当你写出来之后,这些信息在远程除错的时候
+就会成为极大的帮助。当DEBUG符号没有被定义的时候,这些信息不应该被编译进内核里
+(也就是说,默认地,它们不应该被包含在内)。如果你使用dev_dbg()或者pr_debug(),
+就能自动达到这个效果。很多子系统拥有Kconfig选项来启用-DDEBUG。还有一个相关的惯例
+是使用VERBOSE_DEBUG来添加dev_vdbg()消息到那些已经由DEBUG启用的消息之上。
+
+
+ 第十四章:分配内存
+
+内核提供了下面的一般用途的内存分配函数:kmalloc(),kzalloc(),kcalloc()和
+vmalloc()。请参考API文档以获取有关它们的详细信息。
+
+传递结构体大小的首选形式是这样的:
+
+ p = kmalloc(sizeof(*p), ...);
+
+另外一种传递方式中,sizeof的操作数是结构体的名字,这样会降低可读性,并且可能会引
+入bug。有可能指针变量类型被改变时,而对应的传递给内存分配函数的sizeof的结果不变。
+
+强制转换一个void指针返回值是多余的。C语言本身保证了从void指针到其他任何指针类型
+的转换是没有问题的。
+
+
+ 第十五章:内联弊病
+
+有一个常见的误解是内联函数是gcc提供的可以让代码运行更快的一个选项。虽然使用内联
+函数有时候是恰当的(比如作为一种替代宏的方式,请看第十二章),不过很多情况下不是
+这样。inline关键字的过度使用会使内核变大,从而使整个系统运行速度变慢。因为大内核
+会占用更多的指令高速缓存(译注:一级缓存通常是指令缓存和数据缓存分开的)而且会导
+致pagecache的可用内存减少。想象一下,一次pagecache未命中就会导致一次磁盘寻址,将
+耗时5毫秒。5毫秒的时间内CPU能执行很多很多指令。
+
+一个基本的原则是如果一个函数有3行以上,就不要把它变成内联函数。这个原则的一个例
+外是,如果你知道某个参数是一个编译时常量,而且因为这个常量你确定编译器在编译时能
+优化掉你的函数的大部分代码,那仍然可以给它加上inline关键字。kmalloc()内联函数就
+是一个很好的例子。
+
+人们经常主张给static的而且只用了一次的函数加上inline,如此不会有任何损失,因为没
+有什么好权衡的。虽然从技术上说这是正确的,但是实际上这种情况下即使不加inline gcc
+也可以自动使其内联。而且其他用户可能会要求移除inline,由此而来的争论会抵消inline
+自身的潜在价值,得不偿失。
+
+
+ 第十六章:函数返回值及命名
+
+函数可以返回很多种不同类型的值,最常见的一种是表明函数执行成功或者失败的值。这样
+的一个值可以表示为一个错误代码整数(-Exxx=失败,0=成功)或者一个“成功”布尔值(
+0=失败,非0=成功)。
+
+混合使用这两种表达方式是难于发现的bug的来源。如果C语言本身严格区分整形和布尔型变
+量,那么编译器就能够帮我们发现这些错误……不过C语言不区分。为了避免产生这种bug,请
+遵循下面的惯例:
+
+ 如果函数的名字是一个动作或者强制性的命令,那么这个函数应该返回错误代码整
+ 数。如果是一个判断,那么函数应该返回一个“成功”布尔值。
+
+比如,“add work”是一个命令,所以add_work()函数在成功时返回0,在失败时返回-EBUSY。
+类似的,因为“PCI device present”是一个判断,所以pci_dev_present()函数在成功找到
+一个匹配的设备时应该返回1,如果找不到时应该返回0。
+
+所有导出(译注:EXPORT)的函数都必须遵守这个惯例,所有的公共函数也都应该如此。私
+有(static)函数不需要如此,但是我们也推荐这样做。
+
+返回值是实际计算结果而不是计算是否成功的标志的函数不受此惯例的限制。一般的,他们
+通过返回一些正常值范围之外的结果来表示出错。典型的例子是返回指针的函数,他们使用
+NULL或者ERR_PTR机制来报告错误。
+
+
+ 第十七章:不要重新发明内核宏
+
+头文件include/linux/kernel.h包含了一些宏,你应该使用它们,而不要自己写一些它们的
+变种。比如,如果你需要计算一个数组的长度,使用这个宏
+
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+类似的,如果你要计算某结构体成员的大小,使用
+
+ #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
+
+还有可以做严格的类型检查的min()和max()宏,如果你需要可以使用它们。你可以自己看看
+那个头文件里还定义了什么你可以拿来用的东西,如果有定义的话,你就不应在你的代码里
+自己重新定义。
+
+
+ 第十八章:编辑器模式行和其他需要罗嗦的事情
+
+有一些编辑器可以解释嵌入在源文件里的由一些特殊标记标明的配置信息。比如,emacs
+能够解释被标记成这样的行:
+
+-*- mode: c -*-
+
+或者这样的:
+
+/*
+Local Variables:
+compile-command: "gcc -DMAGIC_DEBUG_FLAG foo.c"
+End:
+*/
+
+Vim能够解释这样的标记:
+
+/* vim:set sw=8 noet */
+
+不要在源代码中包含任何这样的内容。每个人都有他自己的编辑器配置,你的源文件不应
+该覆盖别人的配置。这包括有关缩进和模式配置的标记。人们可以使用他们自己定制的模
+式,或者使用其他可以产生正确的缩进的巧妙方法。
+
+
+
+ 附录 I:参考
+
+The C Programming Language, 第二版, 作者Brian W. Kernighan和Denni
+M. Ritchie. Prentice Hall, Inc., 1988. ISBN 0-13-110362-8 (软皮),
+0-13-110370-9 (硬皮). URL: http://cm.bell-labs.com/cm/cs/cbook/
+
+The Practice of Programming 作者Brian W. Kernighan和Rob Pike. Addison-Wesley,
+Inc., 1999. ISBN 0-201-61586-X. URL: http://cm.bell-labs.com/cm/cs/tpop/
+
+cpp,gcc,gcc internals和indent的GNU手册——和K&R及本文相符合的部分,全部可以在
+http://www.gnu.org/manual/找到
+
+WG14是C语言的国际标准化工作组,URL: http://www.open-std.org/JTC1/SC22/WG14/
+
+Kernel CodingStyle,作者[email protected]发表于OLS 2002:
+http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
+
+--
+最后更新于2007年7月13日。
--
1.5.3.8

2008-01-25 07:17:01

by Greg KH

[permalink] [raw]
Subject: [PATCH 011/196] sysfs: Fix a copy-n-paste typo in comment

From: Jean Delvare <[email protected]>

Signed-off-by: Jean Delvare <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/sysfs/dir.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index f281cc6..4948d9b 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -440,7 +440,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
/**
* sysfs_remove_one - remove sysfs_dirent from parent
* @acxt: addrm context to use
- * @sd: sysfs_dirent to be added
+ * @sd: sysfs_dirent to be removed
*
* Mark @sd removed and drop nlink of parent inode if @sd is a
* directory. @sd is unlinked from the children list.
--
1.5.3.8

2008-01-25 07:17:32

by Greg KH

[permalink] [raw]
Subject: [PATCH 012/196] nozomi driver

From: Frank Seidel <[email protected]>

This is a driver to control the cardbus wireless data card that works on
3g networks.

Greg Kroah-Hartman <[email protected]> did the initial driver cleanup.
Thanks to Arnaud Patard <[email protected]> for help with bugfixing.
Thanks to Alan Cox for a lot of tty fixes.
Thanks to Satyam Sharma <[email protected]> for fixing buildbreakage.
Thanks to Frank Seidel <[email protected]> for a lot of bugfixes and
rewriting to make it a sane Linux driver
Thanks to Jiri Slaby <[email protected]> for a lot bugfixes, cleanups
and rewrites that make it much more readable.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Frank Seidel <[email protected]>
Signed-off-by: Jiri Slaby <[email protected]>
---
drivers/char/Kconfig | 10 +
drivers/char/Makefile | 1 +
drivers/char/nozomi.c | 1993 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 2004 insertions(+), 0 deletions(-)
create mode 100644 drivers/char/nozomi.c

diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 2e3a0d4..4666295 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -373,6 +373,16 @@ config ISTALLION
To compile this driver as a module, choose M here: the
module will be called istallion.

+config NOZOMI
+ tristate "HSDPA Broadband Wireless Data Card - Globe Trotter"
+ depends on PCI && EXPERIMENTAL
+ help
+ If you have a HSDPA driver Broadband Wireless Data Card -
+ Globe Trotter PCMCIA card, say Y here.
+
+ To compile this driver as a module, choose M here, the module
+ will be called nozomi.
+
config A2232
tristate "Commodore A2232 serial support (EXPERIMENTAL)"
depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 07304d5..96fc01e 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_SERIAL167) += serial167.o
obj-$(CONFIG_CYCLADES) += cyclades.o
obj-$(CONFIG_STALLION) += stallion.o
obj-$(CONFIG_ISTALLION) += istallion.o
+obj-$(CONFIG_NOZOMI) += nozomi.o
obj-$(CONFIG_DIGIEPCA) += epca.o
obj-$(CONFIG_SPECIALIX) += specialix.o
obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
new file mode 100644
index 0000000..6076e66
--- /dev/null
+++ b/drivers/char/nozomi.c
@@ -0,0 +1,1993 @@
+/*
+ * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
+ *
+ * Written by: Ulf Jakobsson,
+ * Jan �erfeldt,
+ * Stefan Thomasson,
+ *
+ * Maintained by: Paul Hardwick ([email protected])
+ *
+ * Patches:
+ * Locking code changes for Vodafone by Sphere Systems Ltd,
+ * Andrew Bird ([email protected] )
+ * & Phil Sanderson
+ *
+ * Source has been ported from an implementation made by Filip Aben @ Option
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Copyright (c) 2005,2006 Option Wireless Sweden AB
+ * Copyright (c) 2006 Sphere Systems Ltd
+ * Copyright (c) 2006 Option Wireless n/v
+ * All rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * --------------------------------------------------------------------------
+ */
+
+/*
+ * CHANGELOG
+ * Version 2.1d
+ * 11-November-2007 Jiri Slaby, Frank Seidel
+ * - Big rework of multicard support by Jiri
+ * - Major cleanups (semaphore to mutex, endianess, no major reservation)
+ * - Optimizations
+ *
+ * Version 2.1c
+ * 30-October-2007 Frank Seidel
+ * - Completed multicard support
+ * - Minor cleanups
+ *
+ * Version 2.1b
+ * 07-August-2007 Frank Seidel
+ * - Minor cleanups
+ * - theoretical multicard support
+ *
+ * Version 2.1
+ * 03-July-2006 Paul Hardwick
+ *
+ * - Stability Improvements. Incorporated spinlock wraps patch.
+ * - Updated for newer 2.6.14+ kernels (tty_buffer_request_room)
+ * - using __devexit macro for tty
+ *
+ *
+ * Version 2.0
+ * 08-feb-2006 15:34:10:Ulf
+ *
+ * -Fixed issue when not waking up line disipine layer, could probably result
+ * in better uplink performance for 2.4.
+ *
+ * -Fixed issue with big endian during initalization, now proper toggle flags
+ * are handled between preloader and maincode.
+ *
+ * -Fixed flow control issue.
+ *
+ * -Added support for setting DTR.
+ *
+ * -For 2.4 kernels, removing temporary buffer that's not needed.
+ *
+ * -Reading CTS only for modem port (only port that supports it).
+ *
+ * -Return 0 in write_room instead of netative value, it's not handled in
+ * upper layer.
+ *
+ * --------------------------------------------------------------------------
+ * Version 1.0
+ *
+ * First version of driver, only tested with card of type F32_2.
+ * Works fine with 2.4 and 2.6 kernels.
+ * Driver also support big endian architecture.
+ */
+
+/* Enable this to have a lot of debug printouts */
+#define DEBUG
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/ioport.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/interrupt.h>
+#include <linux/kmod.h>
+#include <linux/init.h>
+#include <linux/kfifo.h>
+#include <linux/uaccess.h>
+#include <asm/byteorder.h>
+
+#include <linux/delay.h>
+
+
+#define VERSION_STRING DRIVER_DESC " 2.1d (build date: " \
+ __DATE__ " " __TIME__ ")"
+
+/* Macros definitions */
+
+/* Default debug printout level */
+#define NOZOMI_DEBUG_LEVEL 0x00
+
+#define P_BUF_SIZE 128
+#define NFO(_err_flag_, args...) \
+do { \
+ char tmp[P_BUF_SIZE]; \
+ snprintf(tmp, sizeof(tmp), ##args); \
+ printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \
+ __FUNCTION__, tmp); \
+} while (0)
+
+#define DBG1(args...) D_(0x01, ##args)
+#define DBG2(args...) D_(0x02, ##args)
+#define DBG3(args...) D_(0x04, ##args)
+#define DBG4(args...) D_(0x08, ##args)
+#define DBG5(args...) D_(0x10, ##args)
+#define DBG6(args...) D_(0x20, ##args)
+#define DBG7(args...) D_(0x40, ##args)
+#define DBG8(args...) D_(0x80, ##args)
+
+#ifdef DEBUG
+/* Do we need this settable at runtime? */
+static int debug = NOZOMI_DEBUG_LEVEL;
+
+#define D(lvl, args...) do {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
+ while (0)
+#define D_(lvl, args...) D(lvl, ##args)
+
+/* These printouts are always printed */
+
+#else
+static int debug;
+#define D_(lvl, args...)
+#endif
+
+/* TODO: rewrite to optimize macros... */
+
+#define TMP_BUF_MAX 256
+
+#define DUMP(buf__,len__) \
+ do { \
+ char tbuf[TMP_BUF_MAX] = {0};\
+ if (len__ > 1) {\
+ snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\
+ if (tbuf[len__-2] == '\r') {\
+ tbuf[len__-2] = 'r';\
+ } \
+ DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\
+ } else {\
+ DBG1("SENDING: '%s' (%d)", tbuf, len__);\
+ } \
+} while (0)
+
+/* Defines */
+#define NOZOMI_NAME "nozomi"
+#define NOZOMI_NAME_TTY "nozomi_tty"
+#define DRIVER_DESC "Nozomi driver"
+
+#define NTTY_TTY_MAXMINORS 256
+#define NTTY_FIFO_BUFFER_SIZE 8192
+
+/* Must be power of 2 */
+#define FIFO_BUFFER_SIZE_UL 8192
+
+/* Size of tmp send buffer to card */
+#define SEND_BUF_MAX 1024
+#define RECEIVE_BUF_MAX 4
+
+
+/* Define all types of vendors and devices to support */
+#define VENDOR1 0x1931 /* Vendor Option */
+#define DEVICE1 0x000c /* HSDPA card */
+
+#define R_IIR 0x0000 /* Interrupt Identity Register */
+#define R_FCR 0x0000 /* Flow Control Register */
+#define R_IER 0x0004 /* Interrupt Enable Register */
+
+#define CONFIG_MAGIC 0xEFEFFEFE
+#define TOGGLE_VALID 0x0000
+
+/* Definition of interrupt tokens */
+#define MDM_DL1 0x0001
+#define MDM_UL1 0x0002
+#define MDM_DL2 0x0004
+#define MDM_UL2 0x0008
+#define DIAG_DL1 0x0010
+#define DIAG_DL2 0x0020
+#define DIAG_UL 0x0040
+#define APP1_DL 0x0080
+#define APP1_UL 0x0100
+#define APP2_DL 0x0200
+#define APP2_UL 0x0400
+#define CTRL_DL 0x0800
+#define CTRL_UL 0x1000
+#define RESET 0x8000
+
+#define MDM_DL (MDM_DL1 | MDM_DL2)
+#define MDM_UL (MDM_UL1 | MDM_UL2)
+#define DIAG_DL (DIAG_DL1 | DIAG_DL2)
+
+/* modem signal definition */
+#define CTRL_DSR 0x0001
+#define CTRL_DCD 0x0002
+#define CTRL_RI 0x0004
+#define CTRL_CTS 0x0008
+
+#define CTRL_DTR 0x0001
+#define CTRL_RTS 0x0002
+
+#define MAX_PORT 4
+#define NOZOMI_MAX_PORTS 5
+#define NOZOMI_MAX_CARDS (NTTY_TTY_MAXMINORS / MAX_PORT)
+
+/* Type definitions */
+
+/*
+ * There are two types of nozomi cards,
+ * one with 2048 memory and with 8192 memory
+ */
+enum card_type {
+ F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
+ F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
+};
+
+/* Two different toggle channels exist */
+enum channel_type {
+ CH_A = 0,
+ CH_B = 1,
+};
+
+/* Port definition for the card regarding flow control */
+enum ctrl_port_type {
+ CTRL_CMD = 0,
+ CTRL_MDM = 1,
+ CTRL_DIAG = 2,
+ CTRL_APP1 = 3,
+ CTRL_APP2 = 4,
+ CTRL_ERROR = -1,
+};
+
+/* Ports that the nozomi has */
+enum port_type {
+ PORT_MDM = 0,
+ PORT_DIAG = 1,
+ PORT_APP1 = 2,
+ PORT_APP2 = 3,
+ PORT_CTRL = 4,
+ PORT_ERROR = -1,
+};
+
+#ifdef __BIG_ENDIAN
+/* Big endian */
+
+struct toggles {
+ unsigned enabled:5; /*
+ * Toggle fields are valid if enabled is 0,
+ * else A-channels must always be used.
+ */
+ unsigned diag_dl:1;
+ unsigned mdm_dl:1;
+ unsigned mdm_ul:1;
+} __attribute__ ((packed));
+
+/* Configuration table to read at startup of card */
+/* Is for now only needed during initialization phase */
+struct config_table {
+ u32 signature;
+ u16 product_information;
+ u16 version;
+ u8 pad3[3];
+ struct toggles toggle;
+ u8 pad1[4];
+ u16 dl_mdm_len1; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_start;
+
+ u16 dl_diag_len1;
+ u16 dl_mdm_len2; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_app1_len;
+
+ u16 dl_diag_len2;
+ u16 dl_ctrl_len;
+ u16 dl_app2_len;
+ u8 pad2[16];
+ u16 ul_mdm_len1;
+ u16 ul_start;
+ u16 ul_diag_len;
+ u16 ul_mdm_len2;
+ u16 ul_app1_len;
+ u16 ul_app2_len;
+ u16 ul_ctrl_len;
+} __attribute__ ((packed));
+
+/* This stores all control downlink flags */
+struct ctrl_dl {
+ u8 port;
+ unsigned reserved:4;
+ unsigned CTS:1;
+ unsigned RI:1;
+ unsigned DCD:1;
+ unsigned DSR:1;
+} __attribute__ ((packed));
+
+/* This stores all control uplink flags */
+struct ctrl_ul {
+ u8 port;
+ unsigned reserved:6;
+ unsigned RTS:1;
+ unsigned DTR:1;
+} __attribute__ ((packed));
+
+#else
+/* Little endian */
+
+/* This represents the toggle information */
+struct toggles {
+ unsigned mdm_ul:1;
+ unsigned mdm_dl:1;
+ unsigned diag_dl:1;
+ unsigned enabled:5; /*
+ * Toggle fields are valid if enabled is 0,
+ * else A-channels must always be used.
+ */
+} __attribute__ ((packed));
+
+/* Configuration table to read at startup of card */
+struct config_table {
+ u32 signature;
+ u16 version;
+ u16 product_information;
+ struct toggles toggle;
+ u8 pad1[7];
+ u16 dl_start;
+ u16 dl_mdm_len1; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_mdm_len2;
+ u16 dl_diag_len1;
+ u16 dl_diag_len2;
+ u16 dl_app1_len;
+ u16 dl_app2_len;
+ u16 dl_ctrl_len;
+ u8 pad2[16];
+ u16 ul_start;
+ u16 ul_mdm_len2;
+ u16 ul_mdm_len1;
+ u16 ul_diag_len;
+ u16 ul_app1_len;
+ u16 ul_app2_len;
+ u16 ul_ctrl_len;
+} __attribute__ ((packed));
+
+/* This stores all control downlink flags */
+struct ctrl_dl {
+ unsigned DSR:1;
+ unsigned DCD:1;
+ unsigned RI:1;
+ unsigned CTS:1;
+ unsigned reserverd:4;
+ u8 port;
+} __attribute__ ((packed));
+
+/* This stores all control uplink flags */
+struct ctrl_ul {
+ unsigned DTR:1;
+ unsigned RTS:1;
+ unsigned reserved:6;
+ u8 port;
+} __attribute__ ((packed));
+#endif
+
+/* This holds all information that is needed regarding a port */
+struct port {
+ u8 update_flow_control;
+ struct ctrl_ul ctrl_ul;
+ struct ctrl_dl ctrl_dl;
+ struct kfifo *fifo_ul;
+ void __iomem *dl_addr[2];
+ u32 dl_size[2];
+ u8 toggle_dl;
+ void __iomem *ul_addr[2];
+ u32 ul_size[2];
+ u8 toggle_ul;
+ u16 token_dl;
+
+ struct tty_struct *tty;
+ int tty_open_count;
+ /* mutex to ensure one access patch to this port */
+ struct mutex tty_sem;
+ wait_queue_head_t tty_wait;
+ struct async_icount tty_icount;
+};
+
+/* Private data one for each card in the system */
+struct nozomi {
+ void __iomem *base_addr;
+ unsigned long flip;
+
+ /* Pointers to registers */
+ void __iomem *reg_iir;
+ void __iomem *reg_fcr;
+ void __iomem *reg_ier;
+
+ u16 last_ier;
+ enum card_type card_type;
+ struct config_table config_table; /* Configuration table */
+ struct pci_dev *pdev;
+ struct port port[NOZOMI_MAX_PORTS];
+ u8 *send_buf;
+
+ spinlock_t spin_mutex; /* secures access to registers and tty */
+
+ unsigned int index_start;
+ u32 open_ttys;
+};
+
+/* This is a data packet that is read or written to/from card */
+struct buffer {
+ u32 size; /* size is the length of the data buffer */
+ u8 *data;
+} __attribute__ ((packed));
+
+/* Global variables */
+static struct pci_device_id nozomi_pci_tbl[] = {
+ {PCI_DEVICE(VENDOR1, DEVICE1)},
+ {},
+};
+
+MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
+
+static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
+static struct tty_driver *ntty_driver;
+
+/*
+ * find card by tty_index
+ */
+static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
+{
+ return tty ? ndevs[tty->index / MAX_PORT] : NULL;
+}
+
+static inline struct port *get_port_by_tty(const struct tty_struct *tty)
+{
+ struct nozomi *ndev = get_dc_by_tty(tty);
+ return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL;
+}
+
+/*
+ * TODO:
+ * -Optimize
+ * -Rewrite cleaner
+ */
+
+static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
+ u32 size_bytes)
+{
+ u32 i = 0;
+ const u32 *ptr = (__force u32 *) mem_addr_start;
+ u16 *buf16;
+
+ if (unlikely(!ptr || !buf))
+ goto out;
+
+ /* shortcut for extremely often used cases */
+ switch (size_bytes) {
+ case 2: /* 2 bytes */
+ buf16 = (u16 *) buf;
+ *buf16 = __le16_to_cpu(readw((void __iomem *)ptr));
+ goto out;
+ break;
+ case 4: /* 4 bytes */
+ *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
+ goto out;
+ break;
+ }
+
+ while (i < size_bytes) {
+ if (size_bytes - i == 2) {
+ /* Handle 2 bytes in the end */
+ buf16 = (u16 *) buf;
+ *(buf16) = __le16_to_cpu(readw((void __iomem *)ptr));
+ i += 2;
+ } else {
+ /* Read 4 bytes */
+ *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
+ i += 4;
+ }
+ buf++;
+ ptr++;
+ }
+out:
+ return;
+}
+
+/*
+ * TODO:
+ * -Optimize
+ * -Rewrite cleaner
+ */
+static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
+ u32 size_bytes)
+{
+ u32 i = 0;
+ u32 *ptr = (__force u32 *) mem_addr_start;
+ u16 *buf16;
+
+ if (unlikely(!ptr || !buf))
+ return 0;
+
+ /* shortcut for extremely often used cases */
+ switch (size_bytes) {
+ case 2: /* 2 bytes */
+ buf16 = (u16 *) buf;
+ writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
+ return 2;
+ break;
+ case 1: /*
+ * also needs to write 4 bytes in this case
+ * so falling through..
+ */
+ case 4: /* 4 bytes */
+ writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
+ return 4;
+ break;
+ }
+
+ while (i < size_bytes) {
+ if (size_bytes - i == 2) {
+ /* 2 bytes */
+ buf16 = (u16 *) buf;
+ writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
+ i += 2;
+ } else {
+ /* 4 bytes */
+ writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
+ i += 4;
+ }
+ buf++;
+ ptr++;
+ }
+ return i;
+}
+
+/* Setup pointers to different channels and also setup buffer sizes. */
+static void setup_memory(struct nozomi *dc)
+{
+ void __iomem *offset = dc->base_addr + dc->config_table.dl_start;
+ /* The length reported is including the length field of 4 bytes,
+ * hence subtract with 4.
+ */
+ const u16 buff_offset = 4;
+
+ /* Modem port dl configuration */
+ dc->port[PORT_MDM].dl_addr[CH_A] = offset;
+ dc->port[PORT_MDM].dl_addr[CH_B] =
+ (offset += dc->config_table.dl_mdm_len1);
+ dc->port[PORT_MDM].dl_size[CH_A] =
+ dc->config_table.dl_mdm_len1 - buff_offset;
+ dc->port[PORT_MDM].dl_size[CH_B] =
+ dc->config_table.dl_mdm_len2 - buff_offset;
+
+ /* Diag port dl configuration */
+ dc->port[PORT_DIAG].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_mdm_len2);
+ dc->port[PORT_DIAG].dl_size[CH_A] =
+ dc->config_table.dl_diag_len1 - buff_offset;
+ dc->port[PORT_DIAG].dl_addr[CH_B] =
+ (offset += dc->config_table.dl_diag_len1);
+ dc->port[PORT_DIAG].dl_size[CH_B] =
+ dc->config_table.dl_diag_len2 - buff_offset;
+
+ /* App1 port dl configuration */
+ dc->port[PORT_APP1].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_diag_len2);
+ dc->port[PORT_APP1].dl_size[CH_A] =
+ dc->config_table.dl_app1_len - buff_offset;
+
+ /* App2 port dl configuration */
+ dc->port[PORT_APP2].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_app1_len);
+ dc->port[PORT_APP2].dl_size[CH_A] =
+ dc->config_table.dl_app2_len - buff_offset;
+
+ /* Ctrl dl configuration */
+ dc->port[PORT_CTRL].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_app2_len);
+ dc->port[PORT_CTRL].dl_size[CH_A] =
+ dc->config_table.dl_ctrl_len - buff_offset;
+
+ offset = dc->base_addr + dc->config_table.ul_start;
+
+ /* Modem Port ul configuration */
+ dc->port[PORT_MDM].ul_addr[CH_A] = offset;
+ dc->port[PORT_MDM].ul_size[CH_A] =
+ dc->config_table.ul_mdm_len1 - buff_offset;
+ dc->port[PORT_MDM].ul_addr[CH_B] =
+ (offset += dc->config_table.ul_mdm_len1);
+ dc->port[PORT_MDM].ul_size[CH_B] =
+ dc->config_table.ul_mdm_len2 - buff_offset;
+
+ /* Diag port ul configuration */
+ dc->port[PORT_DIAG].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_mdm_len2);
+ dc->port[PORT_DIAG].ul_size[CH_A] =
+ dc->config_table.ul_diag_len - buff_offset;
+
+ /* App1 port ul configuration */
+ dc->port[PORT_APP1].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_diag_len);
+ dc->port[PORT_APP1].ul_size[CH_A] =
+ dc->config_table.ul_app1_len - buff_offset;
+
+ /* App2 port ul configuration */
+ dc->port[PORT_APP2].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_app1_len);
+ dc->port[PORT_APP2].ul_size[CH_A] =
+ dc->config_table.ul_app2_len - buff_offset;
+
+ /* Ctrl ul configuration */
+ dc->port[PORT_CTRL].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_app2_len);
+ dc->port[PORT_CTRL].ul_size[CH_A] =
+ dc->config_table.ul_ctrl_len - buff_offset;
+}
+
+/* Dump config table under initalization phase */
+#ifdef DEBUG
+static void dump_table(const struct nozomi *dc)
+{
+ DBG3("signature: 0x%08X", dc->config_table.signature);
+ DBG3("version: 0x%04X", dc->config_table.version);
+ DBG3("product_information: 0x%04X", \
+ dc->config_table.product_information);
+ DBG3("toggle enabled: %d", dc->config_table.toggle.enabled);
+ DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul);
+ DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl);
+ DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl);
+
+ DBG3("dl_start: 0x%04X", dc->config_table.dl_start);
+ DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1,
+ dc->config_table.dl_mdm_len1);
+ DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2,
+ dc->config_table.dl_mdm_len2);
+ DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1,
+ dc->config_table.dl_diag_len1);
+ DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2,
+ dc->config_table.dl_diag_len2);
+ DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len,
+ dc->config_table.dl_app1_len);
+ DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len,
+ dc->config_table.dl_app2_len);
+ DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len,
+ dc->config_table.dl_ctrl_len);
+ DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start,
+ dc->config_table.ul_start);
+ DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1,
+ dc->config_table.ul_mdm_len1);
+ DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2,
+ dc->config_table.ul_mdm_len2);
+ DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len,
+ dc->config_table.ul_diag_len);
+ DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len,
+ dc->config_table.ul_app1_len);
+ DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len,
+ dc->config_table.ul_app2_len);
+ DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len,
+ dc->config_table.ul_ctrl_len);
+}
+#else
+static __inline__ void dump_table(const struct nozomi *dc) { }
+#endif
+
+/*
+ * Read configuration table from card under intalization phase
+ * Returns 1 if ok, else 0
+ */
+static int nozomi_read_config_table(struct nozomi *dc)
+{
+ read_mem32((u32 *) &dc->config_table, dc->base_addr + 0,
+ sizeof(struct config_table));
+
+ if (dc->config_table.signature != CONFIG_MAGIC) {
+ dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n",
+ dc->config_table.signature, CONFIG_MAGIC);
+ return 0;
+ }
+
+ if ((dc->config_table.version == 0)
+ || (dc->config_table.toggle.enabled == TOGGLE_VALID)) {
+ int i;
+ DBG1("Second phase, configuring card");
+
+ setup_memory(dc);
+
+ dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul;
+ dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl;
+ dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl;
+ DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
+ dc->port[PORT_MDM].toggle_ul,
+ dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl);
+
+ dump_table(dc);
+
+ for (i = PORT_MDM; i < MAX_PORT; i++) {
+ dc->port[i].fifo_ul =
+ kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
+ memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
+ memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
+ }
+
+ /* Enable control channel */
+ dc->last_ier = dc->last_ier | CTRL_DL;
+ writew(dc->last_ier, dc->reg_ier);
+
+ dev_info(&dc->pdev->dev, "Initialization OK!\n");
+ return 1;
+ }
+
+ if ((dc->config_table.version > 0)
+ && (dc->config_table.toggle.enabled != TOGGLE_VALID)) {
+ u32 offset = 0;
+ DBG1("First phase: pushing upload buffers, clearing download");
+
+ dev_info(&dc->pdev->dev, "Version of card: %d\n",
+ dc->config_table.version);
+
+ /* Here we should disable all I/O over F32. */
+ setup_memory(dc);
+
+ /*
+ * We should send ALL channel pair tokens back along
+ * with reset token
+ */
+
+ /* push upload modem buffers */
+ write_mem32(dc->port[PORT_MDM].ul_addr[CH_A],
+ (u32 *) &offset, 4);
+ write_mem32(dc->port[PORT_MDM].ul_addr[CH_B],
+ (u32 *) &offset, 4);
+
+ writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr);
+
+ DBG1("First phase done");
+ }
+
+ return 1;
+}
+
+/* Enable uplink interrupts */
+static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier |= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Disable uplink interrupts */
+static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier &= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Enable downlink interrupts */
+static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier |= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Disable downlink interrupts */
+static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier &= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/*
+ * Return 1 - send buffer to card and ack.
+ * Return 0 - don't ack, don't send buffer to card.
+ */
+static int send_data(enum port_type index, struct nozomi *dc)
+{
+ u32 size = 0;
+ struct port *port = &dc->port[index];
+ u8 toggle = port->toggle_ul;
+ void __iomem *addr = port->ul_addr[toggle];
+ u32 ul_size = port->ul_size[toggle];
+ struct tty_struct *tty = port->tty;
+
+ /* Get data from tty and place in buf for now */
+ size = __kfifo_get(port->fifo_ul, dc->send_buf,
+ ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
+
+ if (size == 0) {
+ DBG4("No more data to send, disable link:");
+ return 0;
+ }
+
+ /* DUMP(buf, size); */
+
+ /* Write length + data */
+ write_mem32(addr, (u32 *) &size, 4);
+ write_mem32(addr + 4, (u32 *) dc->send_buf, size);
+
+ if (tty)
+ tty_wakeup(tty);
+
+ return 1;
+}
+
+/* If all data has been read, return 1, else 0 */
+static int receive_data(enum port_type index, struct nozomi *dc)
+{
+ u8 buf[RECEIVE_BUF_MAX] = { 0 };
+ int size;
+ u32 offset = 4;
+ struct port *port = &dc->port[index];
+ void __iomem *addr = port->dl_addr[port->toggle_dl];
+ struct tty_struct *tty = port->tty;
+ int i;
+
+ if (unlikely(!tty)) {
+ DBG1("tty not open for port: %d?", index);
+ return 1;
+ }
+
+ read_mem32((u32 *) &size, addr, 4);
+ /* DBG1( "%d bytes port: %d", size, index); */
+
+ if (test_bit(TTY_THROTTLED, &tty->flags)) {
+ DBG1("No room in tty, don't read data, don't ack interrupt, "
+ "disable interrupt");
+
+ /* disable interrupt in downlink... */
+ disable_transmit_dl(index, dc);
+ return 0;
+ }
+
+ if (unlikely(size == 0)) {
+ dev_err(&dc->pdev->dev, "size == 0?\n");
+ return 1;
+ }
+
+ tty_buffer_request_room(tty, size);
+
+ while (size > 0) {
+ read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
+
+ if (size == 1) {
+ tty_insert_flip_char(tty, buf[0], TTY_NORMAL);
+ size = 0;
+ } else if (size < RECEIVE_BUF_MAX) {
+ size -= tty_insert_flip_string(tty, (char *) buf, size);
+ } else {
+ i = tty_insert_flip_string(tty, \
+ (char *) buf, RECEIVE_BUF_MAX);
+ size -= i;
+ offset += i;
+ }
+ }
+
+ set_bit(index, &dc->flip);
+
+ return 1;
+}
+
+/* Debug for interrupts */
+#ifdef DEBUG
+static char *interrupt2str(u16 interrupt)
+{
+ static char buf[TMP_BUF_MAX];
+ char *p = buf;
+
+ interrupt & MDM_DL1 ? p += snprintf(p, TMP_BUF_MAX, "MDM_DL1 ") : NULL;
+ interrupt & MDM_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_DL2 ") : NULL;
+
+ interrupt & MDM_UL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_UL1 ") : NULL;
+ interrupt & MDM_UL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_UL2 ") : NULL;
+
+ interrupt & DIAG_DL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_DL1 ") : NULL;
+ interrupt & DIAG_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_DL2 ") : NULL;
+
+ interrupt & DIAG_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_UL ") : NULL;
+
+ interrupt & APP1_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP1_DL ") : NULL;
+ interrupt & APP2_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP2_DL ") : NULL;
+
+ interrupt & APP1_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP1_UL ") : NULL;
+ interrupt & APP2_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP2_UL ") : NULL;
+
+ interrupt & CTRL_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "CTRL_DL ") : NULL;
+ interrupt & CTRL_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "CTRL_UL ") : NULL;
+
+ interrupt & RESET ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "RESET ") : NULL;
+
+ return buf;
+}
+#endif
+
+/*
+ * Receive flow control
+ * Return 1 - If ok, else 0
+ */
+static int receive_flow_control(struct nozomi *dc)
+{
+ enum port_type port = PORT_MDM;
+ struct ctrl_dl ctrl_dl;
+ struct ctrl_dl old_ctrl;
+ u16 enable_ier = 0;
+
+ read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2);
+
+ switch (ctrl_dl.port) {
+ case CTRL_CMD:
+ DBG1("The Base Band sends this value as a response to a "
+ "request for IMSI detach sent over the control "
+ "channel uplink (see section 7.6.1).");
+ break;
+ case CTRL_MDM:
+ port = PORT_MDM;
+ enable_ier = MDM_DL;
+ break;
+ case CTRL_DIAG:
+ port = PORT_DIAG;
+ enable_ier = DIAG_DL;
+ break;
+ case CTRL_APP1:
+ port = PORT_APP1;
+ enable_ier = APP1_DL;
+ break;
+ case CTRL_APP2:
+ port = PORT_APP2;
+ enable_ier = APP2_DL;
+ break;
+ default:
+ dev_err(&dc->pdev->dev,
+ "ERROR: flow control received for non-existing port\n");
+ return 0;
+ };
+
+ DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl),
+ *((u16 *)&ctrl_dl));
+
+ old_ctrl = dc->port[port].ctrl_dl;
+ dc->port[port].ctrl_dl = ctrl_dl;
+
+ if (old_ctrl.CTS == 1 && ctrl_dl.CTS == 0) {
+ DBG1("Disable interrupt (0x%04X) on port: %d",
+ enable_ier, port);
+ disable_transmit_ul(port, dc);
+
+ } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
+
+ if (__kfifo_len(dc->port[port].fifo_ul)) {
+ DBG1("Enable interrupt (0x%04X) on port: %d",
+ enable_ier, port);
+ DBG1("Data in buffer [%d], enable transmit! ",
+ __kfifo_len(dc->port[port].fifo_ul));
+ enable_transmit_ul(port, dc);
+ } else {
+ DBG1("No data in buffer...");
+ }
+ }
+
+ if (*(u16 *)&old_ctrl == *(u16 *)&ctrl_dl) {
+ DBG1(" No change in mctrl");
+ return 1;
+ }
+ /* Update statistics */
+ if (old_ctrl.CTS != ctrl_dl.CTS)
+ dc->port[port].tty_icount.cts++;
+ if (old_ctrl.DSR != ctrl_dl.DSR)
+ dc->port[port].tty_icount.dsr++;
+ if (old_ctrl.RI != ctrl_dl.RI)
+ dc->port[port].tty_icount.rng++;
+ if (old_ctrl.DCD != ctrl_dl.DCD)
+ dc->port[port].tty_icount.dcd++;
+
+ wake_up_interruptible(&dc->port[port].tty_wait);
+
+ DBG1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
+ port,
+ dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts,
+ dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr);
+
+ return 1;
+}
+
+static enum ctrl_port_type port2ctrl(enum port_type port,
+ const struct nozomi *dc)
+{
+ switch (port) {
+ case PORT_MDM:
+ return CTRL_MDM;
+ case PORT_DIAG:
+ return CTRL_DIAG;
+ case PORT_APP1:
+ return CTRL_APP1;
+ case PORT_APP2:
+ return CTRL_APP2;
+ default:
+ dev_err(&dc->pdev->dev,
+ "ERROR: send flow control " \
+ "received for non-existing port\n");
+ };
+ return CTRL_ERROR;
+}
+
+/*
+ * Send flow control, can only update one channel at a time
+ * Return 0 - If we have updated all flow control
+ * Return 1 - If we need to update more flow control, ack current enable more
+ */
+static int send_flow_control(struct nozomi *dc)
+{
+ u32 i, more_flow_control_to_be_updated = 0;
+ u16 *ctrl;
+
+ for (i = PORT_MDM; i < MAX_PORT; i++) {
+ if (dc->port[i].update_flow_control) {
+ if (more_flow_control_to_be_updated) {
+ /* We have more flow control to be updated */
+ return 1;
+ }
+ dc->port[i].ctrl_ul.port = port2ctrl(i, dc);
+ ctrl = (u16 *)&dc->port[i].ctrl_ul;
+ write_mem32(dc->port[PORT_CTRL].ul_addr[0], \
+ (u32 *) ctrl, 2);
+ dc->port[i].update_flow_control = 0;
+ more_flow_control_to_be_updated = 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Handle donlink data, ports that are handled are modem and diagnostics
+ * Return 1 - ok
+ * Return 0 - toggle fields are out of sync
+ */
+static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
+ u16 read_iir, u16 mask1, u16 mask2)
+{
+ if (*toggle == 0 && read_iir & mask1) {
+ if (receive_data(port, dc)) {
+ writew(mask1, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+
+ if (read_iir & mask2) {
+ if (receive_data(port, dc)) {
+ writew(mask2, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+ }
+ } else if (*toggle == 1 && read_iir & mask2) {
+ if (receive_data(port, dc)) {
+ writew(mask2, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+
+ if (read_iir & mask1) {
+ if (receive_data(port, dc)) {
+ writew(mask1, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+ }
+ } else {
+ dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n",
+ *toggle);
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * Handle uplink data, this is currently for the modem port
+ * Return 1 - ok
+ * Return 0 - toggle field are out of sync
+ */
+static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
+{
+ u8 *toggle = &(dc->port[port].toggle_ul);
+
+ if (*toggle == 0 && read_iir & MDM_UL1) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL1, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+
+ if (read_iir & MDM_UL2) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL2, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+ }
+
+ } else if (*toggle == 1 && read_iir & MDM_UL2) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL2, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+
+ if (read_iir & MDM_UL1) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL1, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+ }
+ } else {
+ writew(read_iir & MDM_UL, dc->reg_fcr);
+ dev_err(&dc->pdev->dev, "port out of sync!\n");
+ return 0;
+ }
+ return 1;
+}
+
+static irqreturn_t interrupt_handler(int irq, void *dev_id)
+{
+ struct nozomi *dc = dev_id;
+ unsigned int a;
+ u16 read_iir;
+
+ if (!dc)
+ return IRQ_NONE;
+
+ spin_lock(&dc->spin_mutex);
+ read_iir = readw(dc->reg_iir);
+
+ /* Card removed */
+ if (read_iir == (u16)-1)
+ goto none;
+ /*
+ * Just handle interrupt enabled in IER
+ * (by masking with dc->last_ier)
+ */
+ read_iir &= dc->last_ier;
+
+ if (read_iir == 0)
+ goto none;
+
+
+ DBG4("%s irq:0x%04X, prev:0x%04X", interrupt2str(read_iir), read_iir,
+ dc->last_ier);
+
+ if (read_iir & RESET) {
+ if (unlikely(!nozomi_read_config_table(dc))) {
+ dc->last_ier = 0x0;
+ writew(dc->last_ier, dc->reg_ier);
+ dev_err(&dc->pdev->dev, "Could not read status from "
+ "card, we should disable interface\n");
+ } else {
+ writew(RESET, dc->reg_fcr);
+ }
+ /* No more useful info if this was the reset interrupt. */
+ goto exit_handler;
+ }
+ if (read_iir & CTRL_UL) {
+ DBG1("CTRL_UL");
+ dc->last_ier &= ~CTRL_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_flow_control(dc)) {
+ writew(CTRL_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | CTRL_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & CTRL_DL) {
+ receive_flow_control(dc);
+ writew(CTRL_DL, dc->reg_fcr);
+ }
+ if (read_iir & MDM_DL) {
+ if (!handle_data_dl(dc, PORT_MDM,
+ &(dc->port[PORT_MDM].toggle_dl), read_iir,
+ MDM_DL1, MDM_DL2)) {
+ dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & MDM_UL) {
+ if (!handle_data_ul(dc, PORT_MDM, read_iir)) {
+ dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & DIAG_DL) {
+ if (!handle_data_dl(dc, PORT_DIAG,
+ &(dc->port[PORT_DIAG].toggle_dl), read_iir,
+ DIAG_DL1, DIAG_DL2)) {
+ dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & DIAG_UL) {
+ dc->last_ier &= ~DIAG_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_DIAG, dc)) {
+ writew(DIAG_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | DIAG_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & APP1_DL) {
+ if (receive_data(PORT_APP1, dc))
+ writew(APP1_DL, dc->reg_fcr);
+ }
+ if (read_iir & APP1_UL) {
+ dc->last_ier &= ~APP1_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_APP1, dc)) {
+ writew(APP1_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | APP1_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & APP2_DL) {
+ if (receive_data(PORT_APP2, dc))
+ writew(APP2_DL, dc->reg_fcr);
+ }
+ if (read_iir & APP2_UL) {
+ dc->last_ier &= ~APP2_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_APP2, dc)) {
+ writew(APP2_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | APP2_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+
+exit_handler:
+ spin_unlock(&dc->spin_mutex);
+ for (a = 0; a < NOZOMI_MAX_PORTS; a++)
+ if (test_and_clear_bit(a, &dc->flip))
+ tty_flip_buffer_push(dc->port[a].tty);
+ return IRQ_HANDLED;
+none:
+ spin_unlock(&dc->spin_mutex);
+ return IRQ_NONE;
+}
+
+static void nozomi_get_card_type(struct nozomi *dc)
+{
+ int i;
+ u32 size = 0;
+
+ for (i = 0; i < 6; i++)
+ size += pci_resource_len(dc->pdev, i);
+
+ /* Assume card type F32_8 if no match */
+ dc->card_type = size == 2048 ? F32_2 : F32_8;
+
+ dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type);
+}
+
+static void nozomi_setup_private_data(struct nozomi *dc)
+{
+ void __iomem *offset = dc->base_addr + dc->card_type / 2;
+ unsigned int i;
+
+ dc->reg_fcr = (void __iomem *)(offset + R_FCR);
+ dc->reg_iir = (void __iomem *)(offset + R_IIR);
+ dc->reg_ier = (void __iomem *)(offset + R_IER);
+ dc->last_ier = 0;
+ dc->flip = 0;
+
+ dc->port[PORT_MDM].token_dl = MDM_DL;
+ dc->port[PORT_DIAG].token_dl = DIAG_DL;
+ dc->port[PORT_APP1].token_dl = APP1_DL;
+ dc->port[PORT_APP2].token_dl = APP2_DL;
+
+ for (i = 0; i < MAX_PORT; i++)
+ init_waitqueue_head(&dc->port[i].tty_wait);
+}
+
+static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+
+ return sprintf(buf, "%d\n", dc->card_type);
+}
+static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
+
+static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+
+ return sprintf(buf, "%u\n", dc->open_ttys);
+}
+static DEVICE_ATTR(open_ttys, 0444, open_ttys_show, NULL);
+
+static void make_sysfs_files(struct nozomi *dc)
+{
+ if (device_create_file(&dc->pdev->dev, &dev_attr_card_type))
+ dev_err(&dc->pdev->dev,
+ "Could not create sysfs file for card_type\n");
+ if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys))
+ dev_err(&dc->pdev->dev,
+ "Could not create sysfs file for open_ttys\n");
+}
+
+static void remove_sysfs_files(struct nozomi *dc)
+{
+ device_remove_file(&dc->pdev->dev, &dev_attr_card_type);
+ device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys);
+}
+
+/* Allocate memory for one device */
+static int __devinit nozomi_card_init(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ resource_size_t start;
+ int ret;
+ struct nozomi *dc = NULL;
+ int ndev_idx;
+ int i;
+
+ dev_dbg(&pdev->dev, "Init, new card found\n");
+
+ for (ndev_idx = 0; ndev_idx < ARRAY_SIZE(ndevs); ndev_idx++)
+ if (!ndevs[ndev_idx])
+ break;
+
+ if (ndev_idx >= ARRAY_SIZE(ndevs)) {
+ dev_err(&pdev->dev, "no free tty range for this card left\n");
+ ret = -EIO;
+ goto err;
+ }
+
+ dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL);
+ if (unlikely(!dc)) {
+ dev_err(&pdev->dev, "Could not allocate memory\n");
+ ret = -ENOMEM;
+ goto err_free;
+ }
+
+ dc->pdev = pdev;
+
+ /* Find out what card type it is */
+ nozomi_get_card_type(dc);
+
+ ret = pci_enable_device(dc->pdev);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to enable PCI Device\n");
+ goto err_free;
+ }
+
+ start = pci_resource_start(dc->pdev, 0);
+ if (start == 0) {
+ dev_err(&pdev->dev, "No I/O address for card detected\n");
+ ret = -ENODEV;
+ goto err_disable_device;
+ }
+
+ ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
+ if (ret) {
+ dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
+ (int) /* nozomi_private.io_addr */ 0);
+ goto err_disable_device;
+ }
+
+ dc->base_addr = ioremap(start, dc->card_type);
+ if (!dc->base_addr) {
+ dev_err(&pdev->dev, "Unable to map card MMIO\n");
+ ret = -ENODEV;
+ goto err_rel_regs;
+ }
+
+ dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
+ if (!dc->send_buf) {
+ dev_err(&pdev->dev, "Could not allocate send buffer?\n");
+ ret = -ENOMEM;
+ goto err_free_sbuf;
+ }
+
+ spin_lock_init(&dc->spin_mutex);
+
+ nozomi_setup_private_data(dc);
+
+ /* Disable all interrupts */
+ dc->last_ier = 0;
+ writew(dc->last_ier, dc->reg_ier);
+
+ ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED,
+ NOZOMI_NAME, dc);
+ if (unlikely(ret)) {
+ dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
+ goto err_free_sbuf;
+ }
+
+ DBG1("base_addr: %p", dc->base_addr);
+
+ make_sysfs_files(dc);
+
+ dc->index_start = ndev_idx * MAX_PORT;
+ ndevs[ndev_idx] = dc;
+
+ for (i = 0; i < MAX_PORT; i++) {
+ mutex_init(&dc->port[i].tty_sem);
+ dc->port[i].tty_open_count = 0;
+ dc->port[i].tty = NULL;
+ tty_register_device(ntty_driver, dc->index_start + i,
+ &pdev->dev);
+ }
+
+ /* Enable RESET interrupt. */
+ dc->last_ier = RESET;
+ writew(dc->last_ier, dc->reg_ier);
+
+ pci_set_drvdata(pdev, dc);
+
+ return 0;
+
+err_free_sbuf:
+ kfree(dc->send_buf);
+ iounmap(dc->base_addr);
+err_rel_regs:
+ pci_release_regions(pdev);
+err_disable_device:
+ pci_disable_device(pdev);
+err_free:
+ kfree(dc);
+err:
+ return ret;
+}
+
+static void __devexit tty_exit(struct nozomi *dc)
+{
+ unsigned int i;
+
+ DBG1(" ");
+
+ flush_scheduled_work();
+
+ for (i = 0; i < MAX_PORT; ++i)
+ if (dc->port[i].tty && \
+ list_empty(&dc->port[i].tty->hangup_work.entry))
+ tty_hangup(dc->port[i].tty);
+
+ while (dc->open_ttys)
+ msleep(1);
+
+ for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
+ tty_unregister_device(ntty_driver, i);
+}
+
+/* Deallocate memory for one device */
+static void __devexit nozomi_card_exit(struct pci_dev *pdev)
+{
+ int i;
+ struct ctrl_ul ctrl;
+ struct nozomi *dc = pci_get_drvdata(pdev);
+
+ /* Disable all interrupts */
+ dc->last_ier = 0;
+ writew(dc->last_ier, dc->reg_ier);
+
+ tty_exit(dc);
+
+ /* Send 0x0001, command card to resend the reset token. */
+ /* This is to get the reset when the module is reloaded. */
+ ctrl.port = 0x00;
+ ctrl.reserved = 0;
+ ctrl.RTS = 0;
+ ctrl.DTR = 1;
+ DBG1("sending flow control 0x%04X", *((u16 *)&ctrl));
+
+ /* Setup dc->reg addresses to we can use defines here */
+ write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2);
+ writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */
+
+ remove_sysfs_files(dc);
+
+ free_irq(pdev->irq, dc);
+
+ for (i = 0; i < MAX_PORT; i++)
+ if (dc->port[i].fifo_ul)
+ kfifo_free(dc->port[i].fifo_ul);
+
+ kfree(dc->send_buf);
+
+ iounmap(dc->base_addr);
+
+ pci_release_regions(pdev);
+
+ pci_disable_device(pdev);
+
+ ndevs[dc->index_start / MAX_PORT] = NULL;
+
+ kfree(dc);
+}
+
+static void set_rts(const struct tty_struct *tty, int rts)
+{
+ struct port *port = get_port_by_tty(tty);
+
+ port->ctrl_ul.RTS = rts;
+ port->update_flow_control = 1;
+ enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
+}
+
+static void set_dtr(const struct tty_struct *tty, int dtr)
+{
+ struct port *port = get_port_by_tty(tty);
+
+ DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr);
+
+ port->ctrl_ul.DTR = dtr;
+ port->update_flow_control = 1;
+ enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
+}
+
+/*
+ * ----------------------------------------------------------------------------
+ * TTY code
+ * ----------------------------------------------------------------------------
+ */
+
+/* Called when the userspace process opens the tty, /dev/noz*. */
+static int ntty_open(struct tty_struct *tty, struct file *file)
+{
+ struct port *port = get_port_by_tty(tty);
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ if (!port || !dc)
+ return -ENODEV;
+
+ if (mutex_lock_interruptible(&port->tty_sem))
+ return -ERESTARTSYS;
+
+ port->tty_open_count++;
+ dc->open_ttys++;
+
+ /* Enable interrupt downlink for channel */
+ if (port->tty_open_count == 1) {
+ tty->low_latency = 1;
+ tty->driver_data = port;
+ port->tty = tty;
+ DBG1("open: %d", port->token_dl);
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ dc->last_ier = dc->last_ier | port->token_dl;
+ writew(dc->last_ier, dc->reg_ier);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+ }
+
+ mutex_unlock(&port->tty_sem);
+
+ return 0;
+}
+
+/* Called when the userspace process close the tty, /dev/noz*. */
+static void ntty_close(struct tty_struct *tty, struct file *file)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ struct port *port = tty->driver_data;
+ unsigned long flags;
+
+ if (!dc || !port)
+ return;
+
+ if (mutex_lock_interruptible(&port->tty_sem))
+ return;
+
+ if (!port->tty_open_count)
+ goto exit;
+
+ dc->open_ttys--;
+ port->tty_open_count--;
+
+ if (port->tty_open_count == 0) {
+ DBG1("close: %d", port->token_dl);
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ dc->last_ier &= ~(port->token_dl);
+ writew(dc->last_ier, dc->reg_ier);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+ }
+
+exit:
+ mutex_unlock(&port->tty_sem);
+}
+
+/*
+ * called when the userspace process writes to the tty (/dev/noz*).
+ * Data is inserted into a fifo, which is then read and transfered to the modem.
+ */
+static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
+ int count)
+{
+ int rval = -EINVAL;
+ struct nozomi *dc = get_dc_by_tty(tty);
+ struct port *port = tty->driver_data;
+ unsigned long flags;
+
+ /* DBG1( "WRITEx: %d, index = %d", count, index); */
+
+ if (!dc || !port)
+ return -ENODEV;
+
+ if (unlikely(!mutex_trylock(&port->tty_sem))) {
+ /*
+ * must test lock as tty layer wraps calls
+ * to this function with BKL
+ */
+ dev_err(&dc->pdev->dev, "Would have deadlocked - "
+ "return EAGAIN\n");
+ return -EAGAIN;
+ }
+
+ if (unlikely(!port->tty_open_count)) {
+ DBG1(" ");
+ goto exit;
+ }
+
+ rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count);
+
+ /* notify card */
+ if (unlikely(dc == NULL)) {
+ DBG1("No device context?");
+ goto exit;
+ }
+
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ /* CTS is only valid on the modem channel */
+ if (port == &(dc->port[PORT_MDM])) {
+ if (port->ctrl_dl.CTS) {
+ DBG4("Enable interrupt");
+ enable_transmit_ul(tty->index % MAX_PORT, dc);
+ } else {
+ dev_err(&dc->pdev->dev,
+ "CTS not active on modem port?\n");
+ }
+ } else {
+ enable_transmit_ul(tty->index % MAX_PORT, dc);
+ }
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+
+exit:
+ mutex_unlock(&port->tty_sem);
+ return rval;
+}
+
+/*
+ * Calculate how much is left in device
+ * This method is called by the upper tty layer.
+ * #according to sources N_TTY.c it expects a value >= 0 and
+ * does not check for negative values.
+ */
+static int ntty_write_room(struct tty_struct *tty)
+{
+ struct port *port = tty->driver_data;
+ int room = 0;
+ struct nozomi *dc = get_dc_by_tty(tty);
+
+ if (!dc || !port)
+ return 0;
+ if (!mutex_trylock(&port->tty_sem))
+ return 0;
+
+ if (!port->tty_open_count)
+ goto exit;
+
+ room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
+
+exit:
+ mutex_unlock(&port->tty_sem);
+ return room;
+}
+
+/* Gets io control parameters */
+static int ntty_tiocmget(struct tty_struct *tty, struct file *file)
+{
+ struct port *port = tty->driver_data;
+ struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
+ struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
+
+ return (ctrl_ul->RTS ? TIOCM_RTS : 0) |
+ (ctrl_ul->DTR ? TIOCM_DTR : 0) |
+ (ctrl_dl->DCD ? TIOCM_CAR : 0) |
+ (ctrl_dl->RI ? TIOCM_RNG : 0) |
+ (ctrl_dl->DSR ? TIOCM_DSR : 0) |
+ (ctrl_dl->CTS ? TIOCM_CTS : 0);
+}
+
+/* Sets io controls parameters */
+static int ntty_tiocmset(struct tty_struct *tty, struct file *file,
+ unsigned int set, unsigned int clear)
+{
+ if (set & TIOCM_RTS)
+ set_rts(tty, 1);
+ else if (clear & TIOCM_RTS)
+ set_rts(tty, 0);
+
+ if (set & TIOCM_DTR)
+ set_dtr(tty, 1);
+ else if (clear & TIOCM_DTR)
+ set_dtr(tty, 0);
+
+ return 0;
+}
+
+static int ntty_cflags_changed(struct port *port, unsigned long flags,
+ struct async_icount *cprev)
+{
+ struct async_icount cnow = port->tty_icount;
+ int ret;
+
+ ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
+ ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
+ ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
+ ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
+
+ *cprev = cnow;
+
+ return ret;
+}
+
+static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp)
+{
+ struct async_icount cnow = port->tty_icount;
+ struct serial_icounter_struct icount;
+
+ icount.cts = cnow.cts;
+ icount.dsr = cnow.dsr;
+ icount.rng = cnow.rng;
+ icount.dcd = cnow.dcd;
+ icount.rx = cnow.rx;
+ icount.tx = cnow.tx;
+ icount.frame = cnow.frame;
+ icount.overrun = cnow.overrun;
+ icount.parity = cnow.parity;
+ icount.brk = cnow.brk;
+ icount.buf_overrun = cnow.buf_overrun;
+
+ return copy_to_user(argp, &icount, sizeof(icount));
+}
+
+static int ntty_ioctl(struct tty_struct *tty, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct port *port = tty->driver_data;
+ void __user *argp = (void __user *)arg;
+ int rval = -ENOIOCTLCMD;
+
+ DBG1("******** IOCTL, cmd: %d", cmd);
+
+ switch (cmd) {
+ case TIOCMIWAIT: {
+ struct async_icount cprev = port->tty_icount;
+
+ rval = wait_event_interruptible(port->tty_wait,
+ ntty_cflags_changed(port, arg, &cprev));
+ break;
+ } case TIOCGICOUNT:
+ rval = ntty_ioctl_tiocgicount(port, argp);
+ break;
+ default:
+ DBG1("ERR: 0x%08X, %d", cmd, cmd);
+ break;
+ };
+
+ return rval;
+}
+
+/*
+ * Called by the upper tty layer when tty buffers are ready
+ * to receive data again after a call to throttle.
+ */
+static void ntty_unthrottle(struct tty_struct *tty)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ DBG1("UNTHROTTLE");
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ enable_transmit_dl(tty->index % MAX_PORT, dc);
+ set_rts(tty, 1);
+
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+}
+
+/*
+ * Called by the upper tty layer when the tty buffers are almost full.
+ * The driver should stop send more data.
+ */
+static void ntty_throttle(struct tty_struct *tty)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ DBG1("THROTTLE");
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ set_rts(tty, 0);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+}
+
+/* just to discard single character writes */
+static void ntty_put_char(struct tty_struct *tty, unsigned char c)
+{
+ /* FIXME !!! */
+ DBG2("PUT CHAR Function: %c", c);
+}
+
+/* Returns number of chars in buffer, called by tty layer */
+static s32 ntty_chars_in_buffer(struct tty_struct *tty)
+{
+ struct port *port = tty->driver_data;
+ struct nozomi *dc = get_dc_by_tty(tty);
+ s32 rval;
+
+ if (unlikely(!dc || !port)) {
+ rval = -ENODEV;
+ goto exit_in_buffer;
+ }
+
+ if (unlikely(!port->tty_open_count)) {
+ dev_err(&dc->pdev->dev, "No tty open?\n");
+ rval = -ENODEV;
+ goto exit_in_buffer;
+ }
+
+ rval = __kfifo_len(port->fifo_ul);
+
+exit_in_buffer:
+ return rval;
+}
+
+static struct tty_operations tty_ops = {
+ .ioctl = ntty_ioctl,
+ .open = ntty_open,
+ .close = ntty_close,
+ .write = ntty_write,
+ .write_room = ntty_write_room,
+ .unthrottle = ntty_unthrottle,
+ .throttle = ntty_throttle,
+ .chars_in_buffer = ntty_chars_in_buffer,
+ .put_char = ntty_put_char,
+ .tiocmget = ntty_tiocmget,
+ .tiocmset = ntty_tiocmset,
+};
+
+/* Module initialization */
+static struct pci_driver nozomi_driver = {
+ .name = NOZOMI_NAME,
+ .id_table = nozomi_pci_tbl,
+ .probe = nozomi_card_init,
+ .remove = __devexit_p(nozomi_card_exit),
+};
+
+static __init int nozomi_init(void)
+{
+ int ret;
+
+ printk(KERN_INFO "Initializing %s\n", VERSION_STRING);
+
+ ntty_driver = alloc_tty_driver(NTTY_TTY_MAXMINORS);
+ if (!ntty_driver)
+ return -ENOMEM;
+
+ ntty_driver->owner = THIS_MODULE;
+ ntty_driver->driver_name = NOZOMI_NAME_TTY;
+ ntty_driver->name = "noz";
+ ntty_driver->major = 0;
+ ntty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+ ntty_driver->subtype = SERIAL_TYPE_NORMAL;
+ ntty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+ ntty_driver->init_termios = tty_std_termios;
+ ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \
+ HUPCL | CLOCAL;
+ ntty_driver->init_termios.c_ispeed = 115200;
+ ntty_driver->init_termios.c_ospeed = 115200;
+ tty_set_operations(ntty_driver, &tty_ops);
+
+ ret = tty_register_driver(ntty_driver);
+ if (ret) {
+ printk(KERN_ERR "Nozomi: failed to register ntty driver\n");
+ goto free_tty;
+ }
+
+ ret = pci_register_driver(&nozomi_driver);
+ if (ret) {
+ printk(KERN_ERR "Nozomi: can't register pci driver\n");
+ goto unr_tty;
+ }
+
+ return 0;
+unr_tty:
+ tty_unregister_driver(ntty_driver);
+free_tty:
+ put_tty_driver(ntty_driver);
+ return ret;
+}
+
+static __exit void nozomi_exit(void)
+{
+ printk(KERN_INFO "Unloading %s\n", DRIVER_DESC);
+ pci_unregister_driver(&nozomi_driver);
+ tty_unregister_driver(ntty_driver);
+ put_tty_driver(ntty_driver);
+}
+
+module_init(nozomi_init);
+module_exit(nozomi_exit);
+
+module_param(debug, int, S_IRUGO | S_IWUSR);
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION(DRIVER_DESC);
--
1.5.3.8

2008-01-25 07:17:51

by Greg KH

[permalink] [raw]
Subject: [PATCH 013/196] Documentation: Replace obsolete "driverfs" with "sysfs".

From: Robert P. J. Day <[email protected]>

Signed-off-by: Robert P. J. Day <[email protected]>
---
Documentation/pnp.txt | 4 ++--
Documentation/s390/cds.txt | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/pnp.txt b/Documentation/pnp.txt
index 481faf5..a327db6 100644
--- a/Documentation/pnp.txt
+++ b/Documentation/pnp.txt
@@ -17,9 +17,9 @@ The User Interface
------------------
The Linux Plug and Play user interface provides a means to activate PnP devices
for legacy and user level drivers that do not support Linux Plug and Play. The
-user interface is integrated into driverfs.
+user interface is integrated into sysfs.

-In addition to the standard driverfs file the following are created in each
+In addition to the standard sysfs file the following are created in each
device's directory:
id - displays a list of support EISA IDs
options - displays possible resource configurations
diff --git a/Documentation/s390/cds.txt b/Documentation/s390/cds.txt
index 3081927..c4b7b2b 100644
--- a/Documentation/s390/cds.txt
+++ b/Documentation/s390/cds.txt
@@ -133,7 +133,7 @@ During its startup the Linux/390 system checks for peripheral devices. Each
of those devices is uniquely defined by a so called subchannel by the ESA/390
channel subsystem. While the subchannel numbers are system generated, each
subchannel also takes a user defined attribute, the so called device number.
-Both subchannel number and device number cannot exceed 65535. During driverfs
+Both subchannel number and device number cannot exceed 65535. During sysfs
initialisation, the information about control unit type and device types that
imply specific I/O commands (channel command words - CCWs) in order to operate
the device are gathered. Device drivers can retrieve this set of hardware
--
1.5.3.8

2008-01-25 07:18:19

by Greg KH

[permalink] [raw]
Subject: [PATCH 014/196] kobject: remove incorrect comment in kobject_rename

As pointed out by Kay.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 3590f02..9500339 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -334,8 +334,6 @@ int kobject_rename(struct kobject * kobj, const char *new_name)
sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
envp[0] = devpath_string;
envp[1] = NULL;
- /* Note : if we want to send the new name alone, not the full path,
- * we could probably use kobject_name(kobj); */

error = sysfs_rename_dir(kobj, new_name);

--
1.5.3.8

2008-01-25 07:18:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 015/196] PM: Acquire device locks on suspend

From: Rafael J. Wysocki <[email protected]>

This patch reorganizes the way suspend and resume notifications are
sent to drivers. The major changes are that now the PM core acquires
every device semaphore before calling the methods, and calls to
device_add() during suspends will fail, while calls to device_del()
during suspends will block.

It also provides a way to safely remove a suspended device with the
help of the PM core, by using the device_pm_schedule_removal() callback
introduced specifically for this purpose, and updates two drivers (msr
and cpuid) that need to use it.

Signed-off-by: Alan Stern <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/x86/kernel/cpuid.c | 6 +-
arch/x86/kernel/msr.c | 6 +-
drivers/base/core.c | 65 +++++-
drivers/base/power/main.c | 502 +++++++++++++++++++++++++++++---------------
drivers/base/power/power.h | 12 +
include/linux/device.h | 8 +
6 files changed, 413 insertions(+), 186 deletions(-)

diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 05c9936..d387c77 100644
--- a/arch/x86/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
@@ -157,15 +157,15 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,

switch (action) {
case CPU_UP_PREPARE:
- case CPU_UP_PREPARE_FROZEN:
err = cpuid_device_create(cpu);
break;
case CPU_UP_CANCELED:
- case CPU_UP_CANCELED_FROZEN:
case CPU_DEAD:
- case CPU_DEAD_FROZEN:
cpuid_device_destroy(cpu);
break;
+ case CPU_UP_CANCELED_FROZEN:
+ destroy_suspended_device(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
+ break;
}
return err ? NOTIFY_BAD : NOTIFY_OK;
}
diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
index ee6eba4..21f6e3c 100644
--- a/arch/x86/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
@@ -155,15 +155,15 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,

switch (action) {
case CPU_UP_PREPARE:
- case CPU_UP_PREPARE_FROZEN:
err = msr_device_create(cpu);
break;
case CPU_UP_CANCELED:
- case CPU_UP_CANCELED_FROZEN:
case CPU_DEAD:
- case CPU_DEAD_FROZEN:
msr_device_destroy(cpu);
break;
+ case CPU_UP_CANCELED_FROZEN:
+ destroy_suspended_device(msr_class, MKDEV(MSR_MAJOR, cpu));
+ break;
}
return err ? NOTIFY_BAD : NOTIFY_OK;
}
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2683eac..ce6b64c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -726,11 +726,20 @@ int device_add(struct device *dev)
{
struct device *parent = NULL;
struct class_interface *class_intf;
- int error = -EINVAL;
+ int error;
+
+ error = pm_sleep_lock();
+ if (error) {
+ dev_warn(dev, "Suspicious %s during suspend\n", __FUNCTION__);
+ dump_stack();
+ return error;
+ }

dev = get_device(dev);
- if (!dev || !strlen(dev->bus_id))
+ if (!dev || !strlen(dev->bus_id)) {
+ error = -EINVAL;
goto Error;
+ }

pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);

@@ -795,6 +804,7 @@ int device_add(struct device *dev)
}
Done:
put_device(dev);
+ pm_sleep_unlock();
return error;
BusError:
device_pm_remove(dev);
@@ -905,6 +915,7 @@ void device_del(struct device * dev)
struct device * parent = dev->parent;
struct class_interface *class_intf;

+ device_pm_remove(dev);
if (parent)
klist_del(&dev->knode_parent);
if (MAJOR(dev->devt))
@@ -981,7 +992,6 @@ void device_del(struct device * dev)
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
- device_pm_remove(dev);
kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj);
if (parent)
@@ -1156,14 +1166,11 @@ error:
EXPORT_SYMBOL_GPL(device_create);

/**
- * device_destroy - removes a device that was created with device_create()
+ * find_device - finds a device that was created with device_create()
* @class: pointer to the struct class that this device was registered with
* @devt: the dev_t of the device that was previously registered
- *
- * This call unregisters and cleans up a device that was created with a
- * call to device_create().
*/
-void device_destroy(struct class *class, dev_t devt)
+static struct device *find_device(struct class *class, dev_t devt)
{
struct device *dev = NULL;
struct device *dev_tmp;
@@ -1176,12 +1183,54 @@ void device_destroy(struct class *class, dev_t devt)
}
}
up(&class->sem);
+ return dev;
+}

+/**
+ * device_destroy - removes a device that was created with device_create()
+ * @class: pointer to the struct class that this device was registered with
+ * @devt: the dev_t of the device that was previously registered
+ *
+ * This call unregisters and cleans up a device that was created with a
+ * call to device_create().
+ */
+void device_destroy(struct class *class, dev_t devt)
+{
+ struct device *dev;
+
+ dev = find_device(class, devt);
if (dev)
device_unregister(dev);
}
EXPORT_SYMBOL_GPL(device_destroy);

+#ifdef CONFIG_PM_SLEEP
+/**
+ * destroy_suspended_device - asks the PM core to remove a suspended device
+ * @class: pointer to the struct class that this device was registered with
+ * @devt: the dev_t of the device that was previously registered
+ *
+ * This call notifies the PM core of the necessity to unregister a suspended
+ * device created with a call to device_create() (devices cannot be
+ * unregistered directly while suspended, since the PM core holds their
+ * semaphores at that time).
+ *
+ * It can only be called within the scope of a system sleep transition. In
+ * practice this means it has to be directly or indirectly invoked either by
+ * a suspend or resume method, or by the PM core (e.g. via
+ * disable_nonboot_cpus() or enable_nonboot_cpus()).
+ */
+void destroy_suspended_device(struct class *class, dev_t devt)
+{
+ struct device *dev;
+
+ dev = find_device(class, devt);
+ if (dev)
+ device_pm_schedule_removal(dev);
+}
+EXPORT_SYMBOL_GPL(destroy_suspended_device);
+#endif /* CONFIG_PM_SLEEP */
+
/**
* device_rename - renames a device
* @dev: the pointer to the struct device to be renamed
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 691ffb6..200ed5f 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -24,20 +24,45 @@
#include <linux/mutex.h>
#include <linux/pm.h>
#include <linux/resume-trace.h>
+#include <linux/rwsem.h>

#include "../base.h"
#include "power.h"

+/*
+ * The entries in the dpm_active list are in a depth first order, simply
+ * because children are guaranteed to be discovered after parents, and
+ * are inserted at the back of the list on discovery.
+ *
+ * All the other lists are kept in the same order, for consistency.
+ * However the lists aren't always traversed in the same order.
+ * Semaphores must be acquired from the top (i.e., front) down
+ * and released in the opposite order. Devices must be suspended
+ * from the bottom (i.e., end) up and resumed in the opposite order.
+ * That way no parent will be suspended while it still has an active
+ * child.
+ *
+ * Since device_pm_add() may be called with a device semaphore held,
+ * we must never try to acquire a device semaphore while holding
+ * dpm_list_mutex.
+ */
+
LIST_HEAD(dpm_active);
+static LIST_HEAD(dpm_locked);
static LIST_HEAD(dpm_off);
static LIST_HEAD(dpm_off_irq);
+static LIST_HEAD(dpm_destroy);

-static DEFINE_MUTEX(dpm_mtx);
static DEFINE_MUTEX(dpm_list_mtx);

-int (*platform_enable_wakeup)(struct device *dev, int is_on);
+static DECLARE_RWSEM(pm_sleep_rwsem);

+int (*platform_enable_wakeup)(struct device *dev, int is_on);

+/**
+ * device_pm_add - add a device to the list of active devices
+ * @dev: Device to be added to the list
+ */
void device_pm_add(struct device *dev)
{
pr_debug("PM: Adding info for %s:%s\n",
@@ -48,8 +73,36 @@ void device_pm_add(struct device *dev)
mutex_unlock(&dpm_list_mtx);
}

+/**
+ * device_pm_remove - remove a device from the list of active devices
+ * @dev: Device to be removed from the list
+ *
+ * This function also removes the device's PM-related sysfs attributes.
+ */
void device_pm_remove(struct device *dev)
{
+ /*
+ * If this function is called during a suspend, it will be blocked,
+ * because we're holding the device's semaphore at that time, which may
+ * lead to a deadlock. In that case we want to print a warning.
+ * However, it may also be called by unregister_dropped_devices() with
+ * the device's semaphore released, in which case the warning should
+ * not be printed.
+ */
+ if (down_trylock(&dev->sem)) {
+ if (down_read_trylock(&pm_sleep_rwsem)) {
+ /* No suspend in progress, wait on dev->sem */
+ down(&dev->sem);
+ up_read(&pm_sleep_rwsem);
+ } else {
+ /* Suspend in progress, we may deadlock */
+ dev_warn(dev, "Suspicious %s during suspend\n",
+ __FUNCTION__);
+ dump_stack();
+ /* The user has been warned ... */
+ down(&dev->sem);
+ }
+ }
pr_debug("PM: Removing info for %s:%s\n",
dev->bus ? dev->bus->name : "No Bus",
kobject_name(&dev->kobj));
@@ -57,25 +110,124 @@ void device_pm_remove(struct device *dev)
dpm_sysfs_remove(dev);
list_del_init(&dev->power.entry);
mutex_unlock(&dpm_list_mtx);
+ up(&dev->sem);
+}
+
+/**
+ * device_pm_schedule_removal - schedule the removal of a suspended device
+ * @dev: Device to destroy
+ *
+ * Moves the device to the dpm_destroy list for further processing by
+ * unregister_dropped_devices().
+ */
+void device_pm_schedule_removal(struct device *dev)
+{
+ pr_debug("PM: Preparing for removal: %s:%s\n",
+ dev->bus ? dev->bus->name : "No Bus",
+ kobject_name(&dev->kobj));
+ mutex_lock(&dpm_list_mtx);
+ list_move_tail(&dev->power.entry, &dpm_destroy);
+ mutex_unlock(&dpm_list_mtx);
+}
+
+/**
+ * pm_sleep_lock - mutual exclusion for registration and suspend
+ *
+ * Returns 0 if no suspend is underway and device registration
+ * may proceed, otherwise -EBUSY.
+ */
+int pm_sleep_lock(void)
+{
+ if (down_read_trylock(&pm_sleep_rwsem))
+ return 0;
+
+ return -EBUSY;
+}
+
+/**
+ * pm_sleep_unlock - mutual exclusion for registration and suspend
+ *
+ * This routine undoes the effect of device_pm_add_lock
+ * when a device's registration is complete.
+ */
+void pm_sleep_unlock(void)
+{
+ up_read(&pm_sleep_rwsem);
}


/*------------------------- Resume routines -------------------------*/

/**
- * resume_device - Restore state for one device.
+ * resume_device_early - Power on one device (early resume).
* @dev: Device.
*
+ * Must be called with interrupts disabled.
*/
-
-static int resume_device(struct device * dev)
+static int resume_device_early(struct device *dev)
{
int error = 0;

TRACE_DEVICE(dev);
TRACE_RESUME(0);

- down(&dev->sem);
+ if (dev->bus && dev->bus->resume_early) {
+ dev_dbg(dev, "EARLY resume\n");
+ error = dev->bus->resume_early(dev);
+ }
+
+ TRACE_RESUME(error);
+ return error;
+}
+
+/**
+ * dpm_power_up - Power on all regular (non-sysdev) devices.
+ *
+ * Walk the dpm_off_irq list and power each device up. This
+ * is used for devices that required they be powered down with
+ * interrupts disabled. As devices are powered on, they are moved
+ * to the dpm_off list.
+ *
+ * Must be called with interrupts disabled and only one CPU running.
+ */
+static void dpm_power_up(void)
+{
+
+ while (!list_empty(&dpm_off_irq)) {
+ struct list_head *entry = dpm_off_irq.next;
+ struct device *dev = to_device(entry);
+
+ list_move_tail(entry, &dpm_off);
+ resume_device_early(dev);
+ }
+}
+
+/**
+ * device_power_up - Turn on all devices that need special attention.
+ *
+ * Power on system devices, then devices that required we shut them down
+ * with interrupts disabled.
+ *
+ * Must be called with interrupts disabled.
+ */
+void device_power_up(void)
+{
+ sysdev_resume();
+ dpm_power_up();
+}
+EXPORT_SYMBOL_GPL(device_power_up);
+
+/**
+ * resume_device - Restore state for one device.
+ * @dev: Device.
+ *
+ */
+static int resume_device(struct device *dev)
+{
+ int error = 0;
+
+ TRACE_DEVICE(dev);
+ TRACE_RESUME(0);

if (dev->bus && dev->bus->resume) {
dev_dbg(dev,"resuming\n");
@@ -92,126 +244,94 @@ static int resume_device(struct device * dev)
error = dev->class->resume(dev);
}

- up(&dev->sem);
-
TRACE_RESUME(error);
return error;
}

-
-static int resume_device_early(struct device * dev)
-{
- int error = 0;
-
- TRACE_DEVICE(dev);
- TRACE_RESUME(0);
- if (dev->bus && dev->bus->resume_early) {
- dev_dbg(dev,"EARLY resume\n");
- error = dev->bus->resume_early(dev);
- }
- TRACE_RESUME(error);
- return error;
-}
-
-/*
- * Resume the devices that have either not gone through
- * the late suspend, or that did go through it but also
- * went through the early resume
+/**
+ * dpm_resume - Resume every device.
+ *
+ * Resume the devices that have either not gone through
+ * the late suspend, or that did go through it but also
+ * went through the early resume.
+ *
+ * Take devices from the dpm_off_list, resume them,
+ * and put them on the dpm_locked list.
*/
static void dpm_resume(void)
{
mutex_lock(&dpm_list_mtx);
while(!list_empty(&dpm_off)) {
- struct list_head * entry = dpm_off.next;
- struct device * dev = to_device(entry);
-
- get_device(dev);
- list_move_tail(entry, &dpm_active);
+ struct list_head *entry = dpm_off.next;
+ struct device *dev = to_device(entry);

+ list_move_tail(entry, &dpm_locked);
mutex_unlock(&dpm_list_mtx);
resume_device(dev);
mutex_lock(&dpm_list_mtx);
- put_device(dev);
}
mutex_unlock(&dpm_list_mtx);
}

-
/**
- * device_resume - Restore state of each device in system.
+ * unlock_all_devices - Release each device's semaphore
*
- * Walk the dpm_off list, remove each entry, resume the device,
- * then add it to the dpm_active list.
+ * Go through the dpm_off list. Put each device on the dpm_active
+ * list and unlock it.
*/
-
-void device_resume(void)
+static void unlock_all_devices(void)
{
- might_sleep();
- mutex_lock(&dpm_mtx);
- dpm_resume();
- mutex_unlock(&dpm_mtx);
-}
-
-EXPORT_SYMBOL_GPL(device_resume);
+ mutex_lock(&dpm_list_mtx);
+ while (!list_empty(&dpm_locked)) {
+ struct list_head *entry = dpm_locked.prev;
+ struct device *dev = to_device(entry);

+ list_move(entry, &dpm_active);
+ up(&dev->sem);
+ }
+ mutex_unlock(&dpm_list_mtx);
+}

/**
- * dpm_power_up - Power on some devices.
- *
- * Walk the dpm_off_irq list and power each device up. This
- * is used for devices that required they be powered down with
- * interrupts disabled. As devices are powered on, they are moved
- * to the dpm_active list.
+ * unregister_dropped_devices - Unregister devices scheduled for removal
*
- * Interrupts must be disabled when calling this.
+ * Unregister all devices on the dpm_destroy list.
*/
-
-static void dpm_power_up(void)
+static void unregister_dropped_devices(void)
{
- while(!list_empty(&dpm_off_irq)) {
- struct list_head * entry = dpm_off_irq.next;
- struct device * dev = to_device(entry);
+ mutex_lock(&dpm_list_mtx);
+ while (!list_empty(&dpm_destroy)) {
+ struct list_head *entry = dpm_destroy.next;
+ struct device *dev = to_device(entry);

- list_move_tail(entry, &dpm_off);
- resume_device_early(dev);
+ up(&dev->sem);
+ mutex_unlock(&dpm_list_mtx);
+ /* This also removes the device from the list */
+ device_unregister(dev);
+ mutex_lock(&dpm_list_mtx);
}
+ mutex_unlock(&dpm_list_mtx);
}

-
/**
- * device_power_up - Turn on all devices that need special attention.
+ * device_resume - Restore state of each device in system.
*
- * Power on system devices then devices that required we shut them down
- * with interrupts disabled.
- * Called with interrupts disabled.
+ * Resume all the devices, unlock them all, and allow new
+ * devices to be registered once again.
*/
-
-void device_power_up(void)
+void device_resume(void)
{
- sysdev_resume();
- dpm_power_up();
+ might_sleep();
+ dpm_resume();
+ unlock_all_devices();
+ unregister_dropped_devices();
+ up_write(&pm_sleep_rwsem);
}
-
-EXPORT_SYMBOL_GPL(device_power_up);
+EXPORT_SYMBOL_GPL(device_resume);


/*------------------------- Suspend routines -------------------------*/

-/*
- * The entries in the dpm_active list are in a depth first order, simply
- * because children are guaranteed to be discovered after parents, and
- * are inserted at the back of the list on discovery.
- *
- * All list on the suspend path are done in reverse order, so we operate
- * on the leaves of the device tree (or forests, depending on how you want
- * to look at it ;) first. As nodes are removed from the back of the list,
- * they are inserted into the front of their destintation lists.
- *
- * Things are the reverse on the resume path - iterations are done in
- * forward order, and nodes are inserted at the back of their destination
- * lists. This way, the ancestors will be accessed before their descendents.
- */
-
static inline char *suspend_verb(u32 event)
{
switch (event) {
@@ -222,7 +342,6 @@ static inline char *suspend_verb(u32 event)
}
}

-
static void
suspend_device_dbg(struct device *dev, pm_message_t state, char *info)
{
@@ -232,16 +351,73 @@ suspend_device_dbg(struct device *dev, pm_message_t state, char *info)
}

/**
- * suspend_device - Save state of one device.
+ * suspend_device_late - Shut down one device (late suspend).
* @dev: Device.
* @state: Power state device is entering.
+ *
+ * This is called with interrupts off and only a single CPU running.
*/
+static int suspend_device_late(struct device *dev, pm_message_t state)
+{
+ int error = 0;

-static int suspend_device(struct device * dev, pm_message_t state)
+ if (dev->bus && dev->bus->suspend_late) {
+ suspend_device_dbg(dev, state, "LATE ");
+ error = dev->bus->suspend_late(dev, state);
+ suspend_report_result(dev->bus->suspend_late, error);
+ }
+ return error;
+}
+
+/**
+ * device_power_down - Shut down special devices.
+ * @state: Power state to enter.
+ *
+ * Power down devices that require interrupts to be disabled
+ * and move them from the dpm_off list to the dpm_off_irq list.
+ * Then power down system devices.
+ *
+ * Must be called with interrupts disabled and only one CPU running.
+ */
+int device_power_down(pm_message_t state)
+{
+ int error = 0;
+
+ while (!list_empty(&dpm_off)) {
+ struct list_head *entry = dpm_off.prev;
+ struct device *dev = to_device(entry);
+
+ list_del_init(&dev->power.entry);
+ error = suspend_device_late(dev, state);
+ if (error) {
+ printk(KERN_ERR "Could not power down device %s: "
+ "error %d\n",
+ kobject_name(&dev->kobj), error);
+ if (list_empty(&dev->power.entry))
+ list_add(&dev->power.entry, &dpm_off);
+ break;
+ }
+ if (list_empty(&dev->power.entry))
+ list_add(&dev->power.entry, &dpm_off_irq);
+ }
+
+ if (!error)
+ error = sysdev_suspend(state);
+ if (error)
+ dpm_power_up();
+ return error;
+}
+EXPORT_SYMBOL_GPL(device_power_down);
+
+/**
+ * suspend_device - Save state of one device.
+ * @dev: Device.
+ * @state: Power state device is entering.
+ */
+int suspend_device(struct device *dev, pm_message_t state)
{
int error = 0;

- down(&dev->sem);
if (dev->power.power_state.event) {
dev_dbg(dev, "PM: suspend %d-->%d\n",
dev->power.power_state.event, state.event);
@@ -264,123 +440,105 @@ static int suspend_device(struct device * dev, pm_message_t state)
error = dev->bus->suspend(dev, state);
suspend_report_result(dev->bus->suspend, error);
}
- up(&dev->sem);
- return error;
-}
-
-
-/*
- * This is called with interrupts off, only a single CPU
- * running. We can't acquire a mutex or semaphore (and we don't
- * need the protection)
- */
-static int suspend_device_late(struct device *dev, pm_message_t state)
-{
- int error = 0;
-
- if (dev->bus && dev->bus->suspend_late) {
- suspend_device_dbg(dev, state, "LATE ");
- error = dev->bus->suspend_late(dev, state);
- suspend_report_result(dev->bus->suspend_late, error);
- }
return error;
}

/**
- * device_suspend - Save state and stop all devices in system.
- * @state: Power state to put each device in.
+ * dpm_suspend - Suspend every device.
+ * @state: Power state to put each device in.
*
- * Walk the dpm_active list, call ->suspend() for each device, and move
- * it to the dpm_off list.
+ * Walk the dpm_locked list. Suspend each device and move it
+ * to the dpm_off list.
*
* (For historical reasons, if it returns -EAGAIN, that used to mean
* that the device would be called again with interrupts disabled.
* These days, we use the "suspend_late()" callback for that, so we
* print a warning and consider it an error).
- *
- * If we get a different error, try and back out.
- *
- * If we hit a failure with any of the devices, call device_resume()
- * above to bring the suspended devices back to life.
- *
*/
-
-int device_suspend(pm_message_t state)
+static int dpm_suspend(pm_message_t state)
{
int error = 0;

- might_sleep();
- mutex_lock(&dpm_mtx);
mutex_lock(&dpm_list_mtx);
- while (!list_empty(&dpm_active) && error == 0) {
- struct list_head * entry = dpm_active.prev;
- struct device * dev = to_device(entry);
+ while (!list_empty(&dpm_locked)) {
+ struct list_head *entry = dpm_locked.prev;
+ struct device *dev = to_device(entry);

- get_device(dev);
+ list_del_init(&dev->power.entry);
mutex_unlock(&dpm_list_mtx);
-
error = suspend_device(dev, state);
-
- mutex_lock(&dpm_list_mtx);
-
- /* Check if the device got removed */
- if (!list_empty(&dev->power.entry)) {
- /* Move it to the dpm_off list */
- if (!error)
- list_move(&dev->power.entry, &dpm_off);
- }
- if (error)
+ if (error) {
printk(KERN_ERR "Could not suspend device %s: "
- "error %d%s\n",
- kobject_name(&dev->kobj), error,
- error == -EAGAIN ? " (please convert to suspend_late)" : "");
- put_device(dev);
+ "error %d%s\n",
+ kobject_name(&dev->kobj),
+ error,
+ (error == -EAGAIN ?
+ " (please convert to suspend_late)" :
+ ""));
+ mutex_lock(&dpm_list_mtx);
+ if (list_empty(&dev->power.entry))
+ list_add(&dev->power.entry, &dpm_locked);
+ mutex_unlock(&dpm_list_mtx);
+ break;
+ }
+ mutex_lock(&dpm_list_mtx);
+ if (list_empty(&dev->power.entry))
+ list_add(&dev->power.entry, &dpm_off);
}
mutex_unlock(&dpm_list_mtx);
- if (error)
- dpm_resume();

- mutex_unlock(&dpm_mtx);
return error;
}

-EXPORT_SYMBOL_GPL(device_suspend);
-
/**
- * device_power_down - Shut down special devices.
- * @state: Power state to enter.
+ * lock_all_devices - Acquire every device's semaphore
*
- * Walk the dpm_off_irq list, calling ->power_down() for each device that
- * couldn't power down the device with interrupts enabled. When we're
- * done, power down system devices.
+ * Go through the dpm_active list. Carefully lock each device's
+ * semaphore and put it in on the dpm_locked list.
*/
-
-int device_power_down(pm_message_t state)
+static void lock_all_devices(void)
{
- int error = 0;
- struct device * dev;
+ mutex_lock(&dpm_list_mtx);
+ while (!list_empty(&dpm_active)) {
+ struct list_head *entry = dpm_active.next;
+ struct device *dev = to_device(entry);

- while (!list_empty(&dpm_off)) {
- struct list_head * entry = dpm_off.prev;
+ /* Required locking order is dev->sem first,
+ * then dpm_list_mutex. Hence this awkward code.
+ */
+ get_device(dev);
+ mutex_unlock(&dpm_list_mtx);
+ down(&dev->sem);
+ mutex_lock(&dpm_list_mtx);

- dev = to_device(entry);
- error = suspend_device_late(dev, state);
- if (error)
- goto Error;
- list_move(&dev->power.entry, &dpm_off_irq);
+ if (list_empty(entry))
+ up(&dev->sem); /* Device was removed */
+ else
+ list_move_tail(entry, &dpm_locked);
+ put_device(dev);
}
+ mutex_unlock(&dpm_list_mtx);
+}
+
+/**
+ * device_suspend - Save state and stop all devices in system.
+ *
+ * Prevent new devices from being registered, then lock all devices
+ * and suspend them.
+ */
+int device_suspend(pm_message_t state)
+{
+ int error;

- error = sysdev_suspend(state);
- Done:
+ might_sleep();
+ down_write(&pm_sleep_rwsem);
+ lock_all_devices();
+ error = dpm_suspend(state);
+ if (error)
+ device_resume();
return error;
- Error:
- printk(KERN_ERR "Could not power down device %s: "
- "error %d\n", kobject_name(&dev->kobj), error);
- dpm_power_up();
- goto Done;
}
-
-EXPORT_SYMBOL_GPL(device_power_down);
+EXPORT_SYMBOL_GPL(device_suspend);

void __suspend_report_result(const char *function, void *fn, int ret)
{
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 379da4e..10c2084 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -20,6 +20,9 @@ static inline struct device *to_device(struct list_head *entry)

extern void device_pm_add(struct device *);
extern void device_pm_remove(struct device *);
+extern void device_pm_schedule_removal(struct device *);
+extern int pm_sleep_lock(void);
+extern void pm_sleep_unlock(void);

#else /* CONFIG_PM_SLEEP */

@@ -32,6 +35,15 @@ static inline void device_pm_remove(struct device *dev)
{
}

+static inline int pm_sleep_lock(void)
+{
+ return 0;
+}
+
+static inline void pm_sleep_unlock(void)
+{
+}
+
#endif

#ifdef CONFIG_PM
diff --git a/include/linux/device.h b/include/linux/device.h
index 2e15822..cf4ae5c 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -521,6 +521,14 @@ extern struct device *device_create(struct class *cls, struct device *parent,
dev_t devt, const char *fmt, ...)
__attribute__((format(printf,4,5)));
extern void device_destroy(struct class *cls, dev_t devt);
+#ifdef CONFIG_PM_SLEEP
+extern void destroy_suspended_device(struct class *cls, dev_t devt);
+#else /* !CONFIG_PM_SLEEP */
+static inline void destroy_suspended_device(struct class *cls, dev_t devt)
+{
+ device_destroy(cls, devt);
+}
+#endif /* !CONFIG_PM_SLEEP */

/*
* Platform "fixup" functions - allow the platform to have their say
--
1.5.3.8

2008-01-25 07:19:00

by Greg KH

[permalink] [raw]
Subject: [PATCH 016/196] kref: add kref_set()

From: Evgeniy Polyakov <[email protected]>

This adds kref_set() to the kref api for future use by people who really
know what they are doing with krefs...

From: Evgeniy Polyakov <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kref.h | 1 +
lib/kref.c | 15 +++++++++++++--
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index 6fee353..5d18563 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -24,6 +24,7 @@ struct kref {
atomic_t refcount;
};

+void kref_set(struct kref *kref, int num);
void kref_init(struct kref *kref);
void kref_get(struct kref *kref);
int kref_put(struct kref *kref, void (*release) (struct kref *kref));
diff --git a/lib/kref.c b/lib/kref.c
index a6dc3ec..9ecd6e8 100644
--- a/lib/kref.c
+++ b/lib/kref.c
@@ -15,13 +15,23 @@
#include <linux/module.h>

/**
+ * kref_set - initialize object and set refcount to requested number.
+ * @kref: object in question.
+ * @num: initial reference counter
+ */
+void kref_set(struct kref *kref, int num)
+{
+ atomic_set(&kref->refcount, num);
+ smp_mb();
+}
+
+/**
* kref_init - initialize object.
* @kref: object in question.
*/
void kref_init(struct kref *kref)
{
- atomic_set(&kref->refcount,1);
- smp_mb();
+ kref_set(kref, 1);
}

/**
@@ -61,6 +71,7 @@ int kref_put(struct kref *kref, void (*release)(struct kref *kref))
return 0;
}

+EXPORT_SYMBOL(kref_set);
EXPORT_SYMBOL(kref_init);
EXPORT_SYMBOL(kref_get);
EXPORT_SYMBOL(kref_put);
--
1.5.3.8

2008-01-25 07:19:31

by Greg KH

[permalink] [raw]
Subject: [PATCH 017/196] aoechr: Convert from class_device to device

From: Tony Jones <[email protected]>

Signed-off-by: Tony Jones <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Sam Hopkins <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/aoe/aoechr.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 39e563e..d5480e3 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -259,9 +259,8 @@ aoechr_init(void)
return PTR_ERR(aoe_class);
}
for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
- class_device_create(aoe_class, NULL,
- MKDEV(AOE_MAJOR, chardevs[i].minor),
- NULL, chardevs[i].name);
+ device_create(aoe_class, NULL,
+ MKDEV(AOE_MAJOR, chardevs[i].minor), chardevs[i].name);

return 0;
}
@@ -272,7 +271,7 @@ aoechr_exit(void)
int i;

for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
- class_device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor));
+ device_destroy(aoe_class, MKDEV(AOE_MAJOR, chardevs[i].minor));
class_destroy(aoe_class);
unregister_chrdev(AOE_MAJOR, "aoechr");
}
--
1.5.3.8

2008-01-25 07:19:48

by Greg KH

[permalink] [raw]
Subject: [PATCH 018/196] coda: convert struct class_device to struct device

From: Kay Sievers <[email protected]>

Signed-off-by: Kay Sievers <[email protected]>
Cc: Tony Jones <[email protected]>
Cc: Jan Harkes <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/coda/psdev.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index dcc6aea..e3eb355 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -362,8 +362,8 @@ static int init_coda_psdev(void)
goto out_chrdev;
}
for (i = 0; i < MAX_CODADEVS; i++)
- class_device_create(coda_psdev_class, NULL,
- MKDEV(CODA_PSDEV_MAJOR,i), NULL, "cfs%d", i);
+ device_create(coda_psdev_class, NULL,
+ MKDEV(CODA_PSDEV_MAJOR,i), "cfs%d", i);
coda_sysctl_init();
goto out;

@@ -405,7 +405,7 @@ static int __init init_coda(void)
return 0;
out:
for (i = 0; i < MAX_CODADEVS; i++)
- class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
+ device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
class_destroy(coda_psdev_class);
unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
coda_sysctl_clean();
@@ -424,7 +424,7 @@ static void __exit exit_coda(void)
printk("coda: failed to unregister filesystem\n");
}
for (i = 0; i < MAX_CODADEVS; i++)
- class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
+ device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
class_destroy(coda_psdev_class);
unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
coda_sysctl_clean();
--
1.5.3.8

2008-01-25 07:20:08

by Greg KH

[permalink] [raw]
Subject: [PATCH 019/196] DMA: Convert from class_device to device for DMA engine

From: Tony Jones <[email protected]>

Signed-off-by: Tony Jones <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
Cc: Shannon Nelson <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/dma/dmaengine.c | 43 ++++++++++++++++++++++---------------------
include/linux/dmaengine.h | 3 ++-
2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index d59b2f4..bcf52df 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -41,12 +41,12 @@
* the definition of dma_event_callback in dmaengine.h.
*
* Each device has a kref, which is initialized to 1 when the device is
- * registered. A kref_get is done for each class_device registered. When the
- * class_device is released, the coresponding kref_put is done in the release
+ * registered. A kref_get is done for each device registered. When the
+ * device is released, the coresponding kref_put is done in the release
* method. Every time one of the device's channels is allocated to a client,
* a kref_get occurs. When the channel is freed, the coresponding kref_put
* happens. The device's release function does a completion, so
- * unregister_device does a remove event, class_device_unregister, a kref_put
+ * unregister_device does a remove event, device_unregister, a kref_put
* for the first reference, then waits on the completion for all other
* references to finish.
*
@@ -77,9 +77,9 @@ static LIST_HEAD(dma_client_list);

/* --- sysfs implementation --- */

-static ssize_t show_memcpy_count(struct class_device *cd, char *buf)
+static ssize_t show_memcpy_count(struct device *dev, struct device_attribute *attr, char *buf)
{
- struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ struct dma_chan *chan = to_dma_chan(dev);
unsigned long count = 0;
int i;

@@ -89,9 +89,10 @@ static ssize_t show_memcpy_count(struct class_device *cd, char *buf)
return sprintf(buf, "%lu\n", count);
}

-static ssize_t show_bytes_transferred(struct class_device *cd, char *buf)
+static ssize_t show_bytes_transferred(struct device *dev, struct device_attribute *attr,
+ char *buf)
{
- struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ struct dma_chan *chan = to_dma_chan(dev);
unsigned long count = 0;
int i;

@@ -101,9 +102,9 @@ static ssize_t show_bytes_transferred(struct class_device *cd, char *buf)
return sprintf(buf, "%lu\n", count);
}

-static ssize_t show_in_use(struct class_device *cd, char *buf)
+static ssize_t show_in_use(struct device *dev, struct device_attribute *attr, char *buf)
{
- struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ struct dma_chan *chan = to_dma_chan(dev);
int in_use = 0;

if (unlikely(chan->slow_ref) &&
@@ -119,7 +120,7 @@ static ssize_t show_in_use(struct class_device *cd, char *buf)
return sprintf(buf, "%d\n", in_use);
}

-static struct class_device_attribute dma_class_attrs[] = {
+static struct device_attribute dma_attrs[] = {
__ATTR(memcpy_count, S_IRUGO, show_memcpy_count, NULL),
__ATTR(bytes_transferred, S_IRUGO, show_bytes_transferred, NULL),
__ATTR(in_use, S_IRUGO, show_in_use, NULL),
@@ -128,16 +129,16 @@ static struct class_device_attribute dma_class_attrs[] = {

static void dma_async_device_cleanup(struct kref *kref);

-static void dma_class_dev_release(struct class_device *cd)
+static void dma_dev_release(struct device *dev)
{
- struct dma_chan *chan = container_of(cd, struct dma_chan, class_dev);
+ struct dma_chan *chan = to_dma_chan(dev);
kref_put(&chan->device->refcount, dma_async_device_cleanup);
}

static struct class dma_devclass = {
- .name = "dma",
- .class_dev_attrs = dma_class_attrs,
- .release = dma_class_dev_release,
+ .name = "dma",
+ .dev_attrs = dma_attrs,
+ .dev_release = dma_dev_release,
};

/* --- client and device registration --- */
@@ -377,12 +378,12 @@ int dma_async_device_register(struct dma_device *device)
continue;

chan->chan_id = chancnt++;
- chan->class_dev.class = &dma_devclass;
- chan->class_dev.dev = NULL;
- snprintf(chan->class_dev.class_id, BUS_ID_SIZE, "dma%dchan%d",
+ chan->dev.class = &dma_devclass;
+ chan->dev.parent = NULL;
+ snprintf(chan->dev.bus_id, BUS_ID_SIZE, "dma%dchan%d",
device->dev_id, chan->chan_id);

- rc = class_device_register(&chan->class_dev);
+ rc = device_register(&chan->dev);
if (rc) {
chancnt--;
free_percpu(chan->local);
@@ -411,7 +412,7 @@ err_out:
if (chan->local == NULL)
continue;
kref_put(&device->refcount, dma_async_device_cleanup);
- class_device_unregister(&chan->class_dev);
+ device_unregister(&chan->dev);
chancnt--;
free_percpu(chan->local);
}
@@ -445,7 +446,7 @@ void dma_async_device_unregister(struct dma_device *device)

list_for_each_entry(chan, &device->channels, device_node) {
dma_clients_notify_removed(chan);
- class_device_unregister(&chan->class_dev);
+ device_unregister(&chan->dev);
dma_chan_release(chan);
}

diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index a3b6035..55c9a69 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -132,7 +132,7 @@ struct dma_chan {

/* sysfs */
int chan_id;
- struct class_device class_dev;
+ struct device dev;

struct kref refcount;
int slow_ref;
@@ -142,6 +142,7 @@ struct dma_chan {
struct dma_chan_percpu *local;
};

+#define to_dma_chan(p) container_of(p, struct dma_chan, dev)

void dma_chan_cleanup(struct kref *kref);

--
1.5.3.8

2008-01-25 07:20:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 020/196] IDE: Convert from class_device to device for ide-tape

From: Tony Jones <[email protected]>

Signed-off-by: Tony Jones <[email protected]>
Cc: Gadi Oxman <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/ide/ide-tape.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 7b9181b..1495792 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -4724,10 +4724,8 @@ static void ide_tape_release(struct kref *kref)

drive->dsc_overlap = 0;
drive->driver_data = NULL;
- class_device_destroy(idetape_sysfs_class,
- MKDEV(IDETAPE_MAJOR, tape->minor));
- class_device_destroy(idetape_sysfs_class,
- MKDEV(IDETAPE_MAJOR, tape->minor + 128));
+ device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
+ device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor + 128));
idetape_devs[tape->minor] = NULL;
g->private_data = NULL;
put_disk(g);
@@ -4884,10 +4882,10 @@ static int ide_tape_probe(ide_drive_t *drive)

idetape_setup(drive, tape, minor);

- class_device_create(idetape_sysfs_class, NULL,
- MKDEV(IDETAPE_MAJOR, minor), &drive->gendev, "%s", tape->name);
- class_device_create(idetape_sysfs_class, NULL,
- MKDEV(IDETAPE_MAJOR, minor + 128), &drive->gendev, "n%s", tape->name);
+ device_create(idetape_sysfs_class, &drive->gendev,
+ MKDEV(IDETAPE_MAJOR, minor), "%s", tape->name);
+ device_create(idetape_sysfs_class, &drive->gendev,
+ MKDEV(IDETAPE_MAJOR, minor + 128), "n%s", tape->name);

g->fops = &idetape_block_ops;
ide_register_region(g);
--
1.5.3.8

2008-01-25 07:20:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 021/196] ISDN: Convert from class_device to device for ISDN capi

From: Tony Jones <[email protected]>

Signed-off-by: Tony Jones <[email protected]>
Cc: Kay Sievers <[email protected]>
Acked-by: Karsten Keil <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/isdn/capi/capi.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index f449dae..23ae66c 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1544,11 +1544,11 @@ static int __init capi_init(void)
return PTR_ERR(capi_class);
}

- class_device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
+ device_create(capi_class, NULL, MKDEV(capi_major, 0), "capi");

#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
if (capinc_tty_init() < 0) {
- class_device_destroy(capi_class, MKDEV(capi_major, 0));
+ device_destroy(capi_class, MKDEV(capi_major, 0));
class_destroy(capi_class);
unregister_chrdev(capi_major, "capi20");
return -ENOMEM;
@@ -1576,7 +1576,7 @@ static void __exit capi_exit(void)
{
proc_exit();

- class_device_destroy(capi_class, MKDEV(capi_major, 0));
+ device_destroy(capi_class, MKDEV(capi_major, 0));
class_destroy(capi_class);
unregister_chrdev(capi_major, "capi20");

--
1.5.3.8

2008-01-25 07:21:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 022/196] adb: Convert from class_device to device

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: Joshua Thompson <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/macintosh/adb.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 5c742a5..b7adde4 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -875,5 +875,5 @@ adbdev_init(void)
adb_dev_class = class_create(THIS_MODULE, "adb");
if (IS_ERR(adb_dev_class))
return;
- class_device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
+ device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), "adb");
}
--
1.5.3.8

2008-01-25 07:21:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 023/196] MCP_UCB1200: Convert from class_device to device

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: Russell King <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/mfd/ucb1x00-assabet.c | 17 +++++++++--------
drivers/mfd/ucb1x00-core.c | 14 +++++++-------
drivers/mfd/ucb1x00.h | 4 ++--
3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/drivers/mfd/ucb1x00-assabet.c b/drivers/mfd/ucb1x00-assabet.c
index e325fa7..b7c8e78 100644
--- a/drivers/mfd/ucb1x00-assabet.c
+++ b/drivers/mfd/ucb1x00-assabet.c
@@ -20,7 +20,8 @@
#include "ucb1x00.h"

#define UCB1X00_ATTR(name,input)\
-static ssize_t name##_show(struct class_device *dev, char *buf) \
+static ssize_t name##_show(struct device *dev, struct device_attribute *attr,
+ char *buf) \
{ \
struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); \
int val; \
@@ -29,7 +30,7 @@ static ssize_t name##_show(struct class_device *dev, char *buf) \
ucb1x00_adc_disable(ucb); \
return sprintf(buf, "%d\n", val); \
} \
-static CLASS_DEVICE_ATTR(name,0444,name##_show,NULL)
+static DEVICE_ATTR(name,0444,name##_show,NULL)

UCB1X00_ATTR(vbatt, UCB_ADC_INP_AD1);
UCB1X00_ATTR(vcharger, UCB_ADC_INP_AD0);
@@ -37,17 +38,17 @@ UCB1X00_ATTR(batt_temp, UCB_ADC_INP_AD2);

static int ucb1x00_assabet_add(struct ucb1x00_dev *dev)
{
- class_device_create_file(&dev->ucb->cdev, &class_device_attr_vbatt);
- class_device_create_file(&dev->ucb->cdev, &class_device_attr_vcharger);
- class_device_create_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
+ device_create_file(&dev->ucb->dev, &device_attr_vbatt);
+ device_create_file(&dev->ucb->dev, &device_attr_vcharger);
+ device_create_file(&dev->ucb->dev, &device_attr_batt_temp);
return 0;
}

static void ucb1x00_assabet_remove(struct ucb1x00_dev *dev)
{
- class_device_remove_file(&dev->ucb->cdev, &class_device_attr_batt_temp);
- class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vcharger);
- class_device_remove_file(&dev->ucb->cdev, &class_device_attr_vbatt);
+ device_remove_file(&dev->ucb->cdev, &device_attr_batt_temp);
+ device_remove_file(&dev->ucb->cdev, &device_attr_vcharger);
+ device_remove_file(&dev->ucb->cdev, &device_attr_vbatt);
}

static struct ucb1x00_driver ucb1x00_assabet_driver = {
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index e03f1bc..f6b10dd 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -458,7 +458,7 @@ static int ucb1x00_detect_irq(struct ucb1x00 *ucb)
return probe_irq_off(mask);
}

-static void ucb1x00_release(struct class_device *dev)
+static void ucb1x00_release(struct device *dev)
{
struct ucb1x00 *ucb = classdev_to_ucb1x00(dev);
kfree(ucb);
@@ -466,7 +466,7 @@ static void ucb1x00_release(struct class_device *dev)

static struct class ucb1x00_class = {
.name = "ucb1x00",
- .release = ucb1x00_release,
+ .dev_release = ucb1x00_release,
};

static int ucb1x00_probe(struct mcp *mcp)
@@ -490,9 +490,9 @@ static int ucb1x00_probe(struct mcp *mcp)
goto err_disable;


- ucb->cdev.class = &ucb1x00_class;
- ucb->cdev.dev = &mcp->attached_device;
- strlcpy(ucb->cdev.class_id, "ucb1x00", sizeof(ucb->cdev.class_id));
+ ucb->dev.class = &ucb1x00_class;
+ ucb->dev.parent = &mcp->attached_device;
+ strlcpy(ucb->dev.bus_id, "ucb1x00", sizeof(ucb->dev.bus_id));

spin_lock_init(&ucb->lock);
spin_lock_init(&ucb->io_lock);
@@ -517,7 +517,7 @@ static int ucb1x00_probe(struct mcp *mcp)

mcp_set_drvdata(mcp, ucb);

- ret = class_device_register(&ucb->cdev);
+ ret = device_register(&ucb->dev);
if (ret)
goto err_irq;

@@ -554,7 +554,7 @@ static void ucb1x00_remove(struct mcp *mcp)
mutex_unlock(&ucb1x00_mutex);

free_irq(ucb->irq, ucb);
- class_device_unregister(&ucb->cdev);
+ device_unregister(&ucb->dev);
}

int ucb1x00_register_driver(struct ucb1x00_driver *drv)
diff --git a/drivers/mfd/ucb1x00.h b/drivers/mfd/ucb1x00.h
index ca8df80..a8ad8a0 100644
--- a/drivers/mfd/ucb1x00.h
+++ b/drivers/mfd/ucb1x00.h
@@ -120,7 +120,7 @@ struct ucb1x00 {
u16 irq_fal_enbl;
u16 irq_ris_enbl;
struct ucb1x00_irq irq_handler[16];
- struct class_device cdev;
+ struct device dev;
struct list_head node;
struct list_head devs;
};
@@ -144,7 +144,7 @@ struct ucb1x00_driver {
int (*resume)(struct ucb1x00_dev *dev);
};

-#define classdev_to_ucb1x00(cd) container_of(cd, struct ucb1x00, cdev)
+#define classdev_to_ucb1x00(cd) container_of(cd, struct ucb1x00, dev)

int ucb1x00_register_driver(struct ucb1x00_driver *);
void ucb1x00_unregister_driver(struct ucb1x00_driver *);
--
1.5.3.8

2008-01-25 07:22:07

by Greg KH

[permalink] [raw]
Subject: [PATCH 024/196] mtd: Convert from class_device to device for MTD/mtdchar

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/mtd/mtdchar.c | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 22ed96c..a0cee86 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -27,12 +27,10 @@ static void mtd_notify_add(struct mtd_info* mtd)
if (!mtd)
return;

- class_device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
- NULL, "mtd%d", mtd->index);
+ device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), "mtd%d", mtd->index);

- class_device_create(mtd_class, NULL,
- MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
- NULL, "mtd%dro", mtd->index);
+ device_create(mtd_class, NULL,
+ MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), "mtd%dro", mtd->index);
}

static void mtd_notify_remove(struct mtd_info* mtd)
@@ -40,8 +38,8 @@ static void mtd_notify_remove(struct mtd_info* mtd)
if (!mtd)
return;

- class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
- class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
+ device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
+ device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
}

static struct mtd_notifier notifier = {
--
1.5.3.8

2008-01-25 07:22:34

by Greg KH

[permalink] [raw]
Subject: [PATCH 025/196] paride: Convert from class_device to device for block/paride

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: Tim Waugh <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/paride/pg.c | 6 +++---
drivers/block/paride/pt.c | 12 ++++++------
2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index d89e7d3..ab86e23 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -676,8 +676,8 @@ static int __init pg_init(void)
for (unit = 0; unit < PG_UNITS; unit++) {
struct pg *dev = &devices[unit];
if (dev->present)
- class_device_create(pg_class, NULL, MKDEV(major, unit),
- NULL, "pg%u", unit);
+ device_create(pg_class, NULL, MKDEV(major, unit),
+ "pg%u", unit);
}
err = 0;
goto out;
@@ -695,7 +695,7 @@ static void __exit pg_exit(void)
for (unit = 0; unit < PG_UNITS; unit++) {
struct pg *dev = &devices[unit];
if (dev->present)
- class_device_destroy(pg_class, MKDEV(major, unit));
+ device_destroy(pg_class, MKDEV(major, unit));
}
class_destroy(pg_class);
unregister_chrdev(major, name);
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index b91accf..76096ca 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -972,10 +972,10 @@ static int __init pt_init(void)

for (unit = 0; unit < PT_UNITS; unit++)
if (pt[unit].present) {
- class_device_create(pt_class, NULL, MKDEV(major, unit),
- NULL, "pt%d", unit);
- class_device_create(pt_class, NULL, MKDEV(major, unit + 128),
- NULL, "pt%dn", unit);
+ device_create(pt_class, NULL, MKDEV(major, unit),
+ "pt%d", unit);
+ device_create(pt_class, NULL, MKDEV(major, unit + 128),
+ "pt%dn", unit);
}
goto out;

@@ -990,8 +990,8 @@ static void __exit pt_exit(void)
int unit;
for (unit = 0; unit < PT_UNITS; unit++)
if (pt[unit].present) {
- class_device_destroy(pt_class, MKDEV(major, unit));
- class_device_destroy(pt_class, MKDEV(major, unit + 128));
+ device_destroy(pt_class, MKDEV(major, unit));
+ device_destroy(pt_class, MKDEV(major, unit + 128));
}
class_destroy(pt_class);
unregister_chrdev(major, name);
--
1.5.3.8

2008-01-25 07:22:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 026/196] pktcdvd: Convert from class_device to device for block/pktcdvd

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: Peter Osterlund <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/pktcdvd.c | 16 +++++++---------
include/linux/pktcdvd.h | 2 +-
2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 3535ef8..17da699 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -301,18 +301,16 @@ static struct kobj_type kobj_pkt_type_wqueue = {
static void pkt_sysfs_dev_new(struct pktcdvd_device *pd)
{
if (class_pktcdvd) {
- pd->clsdev = class_device_create(class_pktcdvd,
- NULL, pd->pkt_dev,
- NULL, "%s", pd->name);
- if (IS_ERR(pd->clsdev))
- pd->clsdev = NULL;
+ pd->dev = device_create(class_pktcdvd, NULL, pd->pkt_dev, "%s", pd->name);
+ if (IS_ERR(pd->dev))
+ pd->dev = NULL;
}
- if (pd->clsdev) {
+ if (pd->dev) {
pd->kobj_stat = pkt_kobj_create(pd, "stat",
- &pd->clsdev->kobj,
+ &pd->dev->kobj,
&kobj_pkt_type_stat);
pd->kobj_wqueue = pkt_kobj_create(pd, "write_queue",
- &pd->clsdev->kobj,
+ &pd->dev->kobj,
&kobj_pkt_type_wqueue);
}
}
@@ -322,7 +320,7 @@ static void pkt_sysfs_dev_remove(struct pktcdvd_device *pd)
pkt_kobj_remove(pd->kobj_stat);
pkt_kobj_remove(pd->kobj_wqueue);
if (class_pktcdvd)
- class_device_destroy(class_pktcdvd, pd->pkt_dev);
+ device_destroy(class_pktcdvd, pd->pkt_dev);
}


diff --git a/include/linux/pktcdvd.h b/include/linux/pktcdvd.h
index 5ea4f05..04b4d73 100644
--- a/include/linux/pktcdvd.h
+++ b/include/linux/pktcdvd.h
@@ -290,7 +290,7 @@ struct pktcdvd_device
int write_congestion_off;
int write_congestion_on;

- struct class_device *clsdev; /* sysfs pktcdvd[0-7] class dev */
+ struct device *dev; /* sysfs pktcdvd[0-7] dev */
struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */

--
1.5.3.8

2008-01-25 07:23:20

by Greg KH

[permalink] [raw]
Subject: [PATCH 027/196] tifm: Convert from class_device to device for TI flash media

From: Tony Jones <[email protected]>

Signed-off-by: Tony Jones <[email protected]>
Cc: Alex Dubov <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/misc/tifm_7xx1.c | 4 ++--
drivers/misc/tifm_core.c | 24 ++++++++++++------------
include/linux/tifm.h | 2 +-
3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index 2d1b3df..54380da 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -149,7 +149,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
socket_change_set = fm->socket_change_set;
fm->socket_change_set = 0;

- dev_dbg(fm->cdev.dev, "checking media set %x\n",
+ dev_dbg(fm->dev.parent, "checking media set %x\n",
socket_change_set);

if (!socket_change_set) {
@@ -164,7 +164,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
if (sock) {
printk(KERN_INFO
"%s : demand removing card from socket %u:%u\n",
- fm->cdev.class_id, fm->id, cnt);
+ fm->dev.bus_id, fm->id, cnt);
fm->sockets[cnt] = NULL;
sock_addr = sock->addr;
spin_unlock_irqrestore(&fm->lock, flags);
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c
index 8f77949..9754405 100644
--- a/drivers/misc/tifm_core.c
+++ b/drivers/misc/tifm_core.c
@@ -160,16 +160,16 @@ static struct bus_type tifm_bus_type = {
.resume = tifm_device_resume
};

-static void tifm_free(struct class_device *cdev)
+static void tifm_free(struct device *dev)
{
- struct tifm_adapter *fm = container_of(cdev, struct tifm_adapter, cdev);
+ struct tifm_adapter *fm = container_of(dev, struct tifm_adapter, dev);

kfree(fm);
}

static struct class tifm_adapter_class = {
.name = "tifm_adapter",
- .release = tifm_free
+ .dev_release = tifm_free
};

struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
@@ -180,9 +180,9 @@ struct tifm_adapter *tifm_alloc_adapter(unsigned int num_sockets,
fm = kzalloc(sizeof(struct tifm_adapter)
+ sizeof(struct tifm_dev*) * num_sockets, GFP_KERNEL);
if (fm) {
- fm->cdev.class = &tifm_adapter_class;
- fm->cdev.dev = dev;
- class_device_initialize(&fm->cdev);
+ fm->dev.class = &tifm_adapter_class;
+ fm->dev.parent = dev;
+ device_initialize(&fm->dev);
spin_lock_init(&fm->lock);
fm->num_sockets = num_sockets;
}
@@ -203,8 +203,8 @@ int tifm_add_adapter(struct tifm_adapter *fm)
if (rc)
return rc;

- snprintf(fm->cdev.class_id, BUS_ID_SIZE, "tifm%u", fm->id);
- rc = class_device_add(&fm->cdev);
+ snprintf(fm->dev.bus_id, BUS_ID_SIZE, "tifm%u", fm->id);
+ rc = device_add(&fm->dev);
if (rc) {
spin_lock(&tifm_adapter_lock);
idr_remove(&tifm_adapter_idr, fm->id);
@@ -228,13 +228,13 @@ void tifm_remove_adapter(struct tifm_adapter *fm)
spin_lock(&tifm_adapter_lock);
idr_remove(&tifm_adapter_idr, fm->id);
spin_unlock(&tifm_adapter_lock);
- class_device_del(&fm->cdev);
+ device_del(&fm->dev);
}
EXPORT_SYMBOL(tifm_remove_adapter);

void tifm_free_adapter(struct tifm_adapter *fm)
{
- class_device_put(&fm->cdev);
+ put_device(&fm->dev);
}
EXPORT_SYMBOL(tifm_free_adapter);

@@ -261,9 +261,9 @@ struct tifm_dev *tifm_alloc_device(struct tifm_adapter *fm, unsigned int id,
sock->card_event = tifm_dummy_event;
sock->data_event = tifm_dummy_event;

- sock->dev.parent = fm->cdev.dev;
+ sock->dev.parent = fm->dev.parent;
sock->dev.bus = &tifm_bus_type;
- sock->dev.dma_mask = fm->cdev.dev->dma_mask;
+ sock->dev.dma_mask = fm->dev.parent->dma_mask;
sock->dev.release = tifm_free_device;

snprintf(sock->dev.bus_id, BUS_ID_SIZE,
diff --git a/include/linux/tifm.h b/include/linux/tifm.h
index 6b3a318..2096b76 100644
--- a/include/linux/tifm.h
+++ b/include/linux/tifm.h
@@ -120,7 +120,7 @@ struct tifm_adapter {
struct completion *finish_me;

struct work_struct media_switcher;
- struct class_device cdev;
+ struct device dev;

void (*eject)(struct tifm_adapter *fm,
struct tifm_dev *sock);
--
1.5.3.8

2008-01-25 07:23:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 028/196] cosa: Convert from class_device to device for cosa sync driver

From: Tony Jones <[email protected]>

struct class_device is going away, this converts the code to use struct
device instead.

Signed-off-by: Tony Jones <[email protected]>
Cc: Jan "Yenya" Kasprzak <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/net/wan/cosa.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index ff37bf4..1d706ea 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -395,8 +395,7 @@ static int __init cosa_init(void)
goto out_chrdev;
}
for (i=0; i<nr_cards; i++) {
- class_device_create(cosa_class, NULL, MKDEV(cosa_major, i),
- NULL, "cosa%d", i);
+ device_create(cosa_class, NULL, MKDEV(cosa_major, i), "cosa%d", i);
}
err = 0;
goto out;
@@ -415,7 +414,7 @@ static void __exit cosa_exit(void)
printk(KERN_INFO "Unloading the cosa module\n");

for (i=0; i<nr_cards; i++)
- class_device_destroy(cosa_class, MKDEV(cosa_major, i));
+ device_destroy(cosa_class, MKDEV(cosa_major, i));
class_destroy(cosa_class);
for (cosa=cosa_cards; nr_cards--; cosa++) {
/* Clean up the per-channel data */
--
1.5.3.8

2008-01-25 07:23:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 029/196] ecryptfs: clean up attribute mess

It isn't that hard to add simple kset attributes, so don't go through
all the gyrations of creating your own object type and show and store
functions. Just use the functions that are already present. This makes
things much simpler.

Note, the version_str string violates the "one value per file" rule for
sysfs. I suggest changing this now (individual files per type supported
is one suggested way.)


Cc: Michael A. Halcrow <[email protected]>
Cc: Michael C. Thompson <[email protected]>
Cc: Tyler Hicks <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 85 +++++++++++-----------------------------------------
1 files changed, 18 insertions(+), 67 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index e5580bc..f9f3247 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,58 +734,14 @@ static int ecryptfs_init_kmem_caches(void)
return 0;
}

-struct ecryptfs_obj {
- char *name;
- struct list_head slot_list;
- struct kobject kobj;
-};
-
-struct ecryptfs_attribute {
- struct attribute attr;
- ssize_t(*show) (struct ecryptfs_obj *, char *);
- ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t);
-};
-
-static ssize_t
-ecryptfs_attr_store(struct kobject *kobj,
- struct attribute *attr, const char *buf, size_t len)
-{
- struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
- kobj);
- struct ecryptfs_attribute *attribute =
- container_of(attr, struct ecryptfs_attribute, attr);
-
- return (attribute->store ? attribute->store(obj, buf, len) : 0);
-}
-
-static ssize_t
-ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
-{
- struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
- kobj);
- struct ecryptfs_attribute *attribute =
- container_of(attr, struct ecryptfs_attribute, attr);
-
- return (attribute->show ? attribute->show(obj, buf) : 0);
-}
-
-static struct sysfs_ops ecryptfs_sysfs_ops = {
- .show = ecryptfs_attr_show,
- .store = ecryptfs_attr_store
-};
+static decl_subsys(ecryptfs, NULL, NULL);

-static struct kobj_type ecryptfs_ktype = {
- .sysfs_ops = &ecryptfs_sysfs_ops
-};
-
-static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
-
-static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
+static ssize_t version_show(struct kset *kset, char *buff)
{
return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
}

-static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
+static struct subsys_attribute version_attr = __ATTR_RO(version);

static struct ecryptfs_version_str_map_elem {
u32 flag;
@@ -799,7 +755,7 @@ static struct ecryptfs_version_str_map_elem {
{ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
};

-static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
+static ssize_t version_str_show(struct kset *kset, char *buff)
{
int i;
int remaining = PAGE_SIZE;
@@ -826,7 +782,17 @@ out:
return total_written;
}

-static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
+static struct subsys_attribute version_attr_str = __ATTR_RO(version_str);
+
+static struct attribute *attributes[] = {
+ &version_attr.attr,
+ &version_attr_str.attr,
+ NULL,
+};
+
+static struct attribute_group attr_group = {
+ .attrs = attributes,
+};

static int do_sysfs_registration(void)
{
@@ -838,23 +804,11 @@ static int do_sysfs_registration(void)
"Unable to register ecryptfs sysfs subsystem\n");
goto out;
}
- rc = sysfs_create_file(&ecryptfs_subsys.kobj,
- &sysfs_attr_version.attr);
+ rc = sysfs_create_group(&ecryptfs_subsys.kobj, &attr_group);
if (rc) {
printk(KERN_ERR
- "Unable to create ecryptfs version attribute\n");
+ "Unable to create ecryptfs version attributes\n");
subsystem_unregister(&ecryptfs_subsys);
- goto out;
- }
- rc = sysfs_create_file(&ecryptfs_subsys.kobj,
- &sysfs_attr_version_str.attr);
- if (rc) {
- printk(KERN_ERR
- "Unable to create ecryptfs version_str attribute\n");
- sysfs_remove_file(&ecryptfs_subsys.kobj,
- &sysfs_attr_version.attr);
- subsystem_unregister(&ecryptfs_subsys);
- goto out;
}
out:
return rc;
@@ -862,10 +816,7 @@ out:

static void do_sysfs_unregistration(void)
{
- sysfs_remove_file(&ecryptfs_subsys.kobj,
- &sysfs_attr_version.attr);
- sysfs_remove_file(&ecryptfs_subsys.kobj,
- &sysfs_attr_version_str.attr);
+ sysfs_remove_group(&ecryptfs_subsys.kobj, &attr_group);
subsystem_unregister(&ecryptfs_subsys);
}

--
1.5.3.8

2008-01-25 07:24:22

by Greg KH

[permalink] [raw]
Subject: [PATCH 030/196] driver core: Make the dev_*() family of macros in device.h complete

From: Emil Medve <[email protected]>

Removed duplicates defined elsewhere

Signed-off-by: Emil Medve <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/i2c/chips/isp1301_omap.c | 6 ------
drivers/isdn/gigaset/gigaset.h | 6 ------
include/linux/device.h | 24 +++++++++++++++---------
3 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index b767603..ebfbb29 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -259,12 +259,6 @@ static inline const char *state_name(struct isp1301 *isp)
return state_string(isp->otg.state);
}

-#ifdef VERBOSE
-#define dev_vdbg dev_dbg
-#else
-#define dev_vdbg(dev, fmt, arg...) do{}while(0)
-#endif
-
/*-------------------------------------------------------------------------*/

/* NOTE: some of this ISP1301 setup is specific to H2 boards;
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index a0317ab..02bdaf2 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -106,12 +106,6 @@ enum debuglevel {
activated */
};

-/* missing from linux/device.h ... */
-#ifndef dev_notice
-#define dev_notice(dev, format, arg...) \
- dev_printk(KERN_NOTICE , dev , format , ## arg)
-#endif
-
/* Kernel message macros for situations where dev_printk and friends cannot be
* used for lack of reliable access to a device structure.
* linux/usb.h already contains these but in an obsolete form which clutters
diff --git a/include/linux/device.h b/include/linux/device.h
index cf4ae5c..dbbbe89 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -565,6 +565,21 @@ extern const char *dev_driver_string(struct device *dev);
#define dev_printk(level, dev, format, arg...) \
printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)

+#define dev_emerg(dev, format, arg...) \
+ dev_printk(KERN_EMERG , dev , format , ## arg)
+#define dev_alert(dev, format, arg...) \
+ dev_printk(KERN_ALERT , dev , format , ## arg)
+#define dev_crit(dev, format, arg...) \
+ dev_printk(KERN_CRIT , dev , format , ## arg)
+#define dev_err(dev, format, arg...) \
+ dev_printk(KERN_ERR , dev , format , ## arg)
+#define dev_warn(dev, format, arg...) \
+ dev_printk(KERN_WARNING , dev , format , ## arg)
+#define dev_notice(dev, format, arg...) \
+ dev_printk(KERN_NOTICE , dev , format , ## arg)
+#define dev_info(dev, format, arg...) \
+ dev_printk(KERN_INFO , dev , format , ## arg)
+
#ifdef DEBUG
#define dev_dbg(dev, format, arg...) \
dev_printk(KERN_DEBUG , dev , format , ## arg)
@@ -586,15 +601,6 @@ dev_vdbg(struct device * dev, const char * fmt, ...)
}
#endif

-#define dev_err(dev, format, arg...) \
- dev_printk(KERN_ERR , dev , format , ## arg)
-#define dev_info(dev, format, arg...) \
- dev_printk(KERN_INFO , dev , format , ## arg)
-#define dev_warn(dev, format, arg...) \
- dev_printk(KERN_WARNING , dev , format , ## arg)
-#define dev_notice(dev, format, arg...) \
- dev_printk(KERN_NOTICE , dev , format , ## arg)
-
/* Create alias, so I can be autoloaded. */
#define MODULE_ALIAS_CHARDEV(major,minor) \
MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
--
1.5.3.8

2008-01-25 07:24:38

by Greg KH

[permalink] [raw]
Subject: [PATCH 031/196] sysfs: create optimal relative symlink targets

From: Kay Sievers <[email protected]>

Instead of walking from the source down to the root of sysfs, and back
to the target, we stop at the first directory the source and the target
share.

This link:
/devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0/ep_81

pointed to:
../../../../../devices/pci0000:00/0000:00:1d.0/usb2/2-0:1.0/usb_endpoint/usbdev2.1_ep81

now it just points to:
usb_endpoint/usbdev1.1_ep81

Thanks to Denis Cheng for bringing this up, and sending the initial patch.

CC: Denis Cheng <[email protected]>
Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/sysfs/symlink.c | 88 +++++++++++++++++++++++++---------------------------
1 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 3eac20c..5f66c44 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -19,39 +19,6 @@

#include "sysfs.h"

-static int object_depth(struct sysfs_dirent *sd)
-{
- int depth = 0;
-
- for (; sd->s_parent; sd = sd->s_parent)
- depth++;
-
- return depth;
-}
-
-static int object_path_length(struct sysfs_dirent * sd)
-{
- int length = 1;
-
- for (; sd->s_parent; sd = sd->s_parent)
- length += strlen(sd->s_name) + 1;
-
- return length;
-}
-
-static void fill_object_path(struct sysfs_dirent *sd, char *buffer, int length)
-{
- --length;
- for (; sd->s_parent; sd = sd->s_parent) {
- int cur = strlen(sd->s_name);
-
- /* back up enough to print this bus id with '/' */
- length -= cur;
- strncpy(buffer + length, sd->s_name, cur);
- *(buffer + --length) = '/';
- }
-}
-
/**
* sysfs_create_link - create symlink between two objects.
* @kobj: object whose directory we're creating the link in.
@@ -112,7 +79,6 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
return error;
}

-
/**
* sysfs_remove_link - remove symlink in object's directory.
* @kobj: object we're acting for.
@@ -124,24 +90,54 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
sysfs_hash_and_remove(kobj->sd, name);
}

-static int sysfs_get_target_path(struct sysfs_dirent * parent_sd,
- struct sysfs_dirent * target_sd, char *path)
+static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
+ struct sysfs_dirent *target_sd, char *path)
{
- char * s;
- int depth, size;
+ struct sysfs_dirent *base, *sd;
+ char *s = path;
+ int len = 0;
+
+ /* go up to the root, stop at the base */
+ base = parent_sd;
+ while (base->s_parent) {
+ sd = target_sd->s_parent;
+ while (sd->s_parent && base != sd)
+ sd = sd->s_parent;
+
+ if (base == sd)
+ break;
+
+ strcpy(s, "../");
+ s += 3;
+ base = base->s_parent;
+ }
+
+ /* determine end of target string for reverse fillup */
+ sd = target_sd;
+ while (sd->s_parent && sd != base) {
+ len += strlen(sd->s_name) + 1;
+ sd = sd->s_parent;
+ }

- depth = object_depth(parent_sd);
- size = object_path_length(target_sd) + depth * 3 - 1;
- if (size > PATH_MAX)
+ /* check limits */
+ if (len < 2)
+ return -EINVAL;
+ len--;
+ if ((s - path) + len > PATH_MAX)
return -ENAMETOOLONG;

- pr_debug("%s: depth = %d, size = %d\n", __FUNCTION__, depth, size);
+ /* reverse fillup of target string from target to base */
+ sd = target_sd;
+ while (sd->s_parent && sd != base) {
+ int slen = strlen(sd->s_name);

- for (s = path; depth--; s += 3)
- strcpy(s,"../");
+ len -= slen;
+ strncpy(s + len, sd->s_name, slen);
+ if (len)
+ s[--len] = '/';

- fill_object_path(target_sd, path, size);
- pr_debug("%s: path = '%s'\n", __FUNCTION__, path);
+ sd = sd->s_parent;
+ }

return 0;
}
--
1.5.3.8

2008-01-25 07:24:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 032/196] sysfs: remove SPIN_LOCK_UNLOCKED

From: Jiri Slaby <[email protected]>

SPIN_LOCK_UNLOCKED is deprecated, use DEFINE_SPINLOCK instead

Signed-off-by: Jiri Slaby <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Cc: Tejun Heo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/sysfs/file.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4045bdc..09a0611 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -66,7 +66,7 @@ static struct sysfs_ops subsys_sysfs_ops = {
* sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open
* is protected by sysfs_open_dirent_lock.
*/
-static spinlock_t sysfs_open_dirent_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(sysfs_open_dirent_lock);

struct sysfs_open_dirent {
atomic_t refcnt;
--
1.5.3.8

2008-01-25 07:25:25

by Greg KH

[permalink] [raw]
Subject: [PATCH 033/196] kobject: convert ibmasm to use kref, not kobject

The IBM asm driver is using a kobject only for reference counting,
nothing else. So switch it to use a kref instead, which is all that is
needed, and is much smaller.

Cc: Max Asböck <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/misc/ibmasm/command.c | 12 +++---------
drivers/misc/ibmasm/ibmasm.h | 10 ++++++----
2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/misc/ibmasm/command.c b/drivers/misc/ibmasm/command.c
index 6497872..1a0e797 100644
--- a/drivers/misc/ibmasm/command.c
+++ b/drivers/misc/ibmasm/command.c
@@ -26,11 +26,6 @@
#include "lowlevel.h"

static void exec_next_command(struct service_processor *sp);
-static void free_command(struct kobject *kobj);
-
-static struct kobj_type ibmasm_cmd_kobj_type = {
- .release = free_command,
-};

static atomic_t command_count = ATOMIC_INIT(0);

@@ -53,8 +48,7 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s
}
cmd->buffer_size = buffer_size;

- kobject_init(&cmd->kobj);
- cmd->kobj.ktype = &ibmasm_cmd_kobj_type;
+ kref_init(&cmd->kref);
cmd->lock = &sp->lock;

cmd->status = IBMASM_CMD_PENDING;
@@ -67,9 +61,9 @@ struct command *ibmasm_new_command(struct service_processor *sp, size_t buffer_s
return cmd;
}

-static void free_command(struct kobject *kobj)
+void ibmasm_free_command(struct kref *kref)
{
- struct command *cmd = to_command(kobj);
+ struct command *cmd = to_command(kref);

list_del(&cmd->queue_node);
atomic_dec(&command_count);
diff --git a/drivers/misc/ibmasm/ibmasm.h b/drivers/misc/ibmasm/ibmasm.h
index de860bc..4d8a4e2 100644
--- a/drivers/misc/ibmasm/ibmasm.h
+++ b/drivers/misc/ibmasm/ibmasm.h
@@ -31,6 +31,7 @@
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/interrupt.h>
+#include <linux/kref.h>
#include <linux/device.h>
#include <linux/input.h>

@@ -92,24 +93,25 @@ struct command {
unsigned char *buffer;
size_t buffer_size;
int status;
- struct kobject kobj;
+ struct kref kref;
spinlock_t *lock;
};
-#define to_command(c) container_of(c, struct command, kobj)
+#define to_command(c) container_of(c, struct command, kref)

+void ibmasm_free_command(struct kref *kref);
static inline void command_put(struct command *cmd)
{
unsigned long flags;
spinlock_t *lock = cmd->lock;

spin_lock_irqsave(lock, flags);
- kobject_put(&cmd->kobj);
+ kref_put(&cmd->kref, ibmasm_free_command);
spin_unlock_irqrestore(lock, flags);
}

static inline void command_get(struct command *cmd)
{
- kobject_get(&cmd->kobj);
+ kref_get(&cmd->kref);
}


--
1.5.3.8

2008-01-25 07:25:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 034/196] kobject: convert hvc_console to use kref, not kobject

hvc_console is using a kobject only for reference counting, nothing
else. So switch it to use a kref instead, which is all that is needed,
and is much smaller.

Cc: Anton Blanchard <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Ryan S. Arnold <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/char/hvc_console.c | 80 ++++++++++++++++++--------------------------
1 files changed, 33 insertions(+), 47 deletions(-)

diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 8252f86..480fae2 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -27,7 +27,7 @@
#include <linux/init.h>
#include <linux/kbd_kern.h>
#include <linux/kernel.h>
-#include <linux/kobject.h>
+#include <linux/kref.h>
#include <linux/kthread.h>
#include <linux/list.h>
#include <linux/module.h>
@@ -89,7 +89,7 @@ struct hvc_struct {
int irq_requested;
int irq;
struct list_head next;
- struct kobject kobj; /* ref count & hvc_struct lifetime */
+ struct kref kref; /* ref count & hvc_struct lifetime */
};

/* dynamic list of hvc_struct instances */
@@ -110,7 +110,7 @@ static int last_hvc = -1;

/*
* Do not call this function with either the hvc_structs_lock or the hvc_struct
- * lock held. If successful, this function increments the kobject reference
+ * lock held. If successful, this function increments the kref reference
* count against the target hvc_struct so it should be released when finished.
*/
static struct hvc_struct *hvc_get_by_index(int index)
@@ -123,7 +123,7 @@ static struct hvc_struct *hvc_get_by_index(int index)
list_for_each_entry(hp, &hvc_structs, next) {
spin_lock_irqsave(&hp->lock, flags);
if (hp->index == index) {
- kobject_get(&hp->kobj);
+ kref_get(&hp->kref);
spin_unlock_irqrestore(&hp->lock, flags);
spin_unlock(&hvc_structs_lock);
return hp;
@@ -242,6 +242,23 @@ static int __init hvc_console_init(void)
}
console_initcall(hvc_console_init);

+/* callback when the kboject ref count reaches zero. */
+static void destroy_hvc_struct(struct kref *kref)
+{
+ struct hvc_struct *hp = container_of(kref, struct hvc_struct, kref);
+ unsigned long flags;
+
+ spin_lock(&hvc_structs_lock);
+
+ spin_lock_irqsave(&hp->lock, flags);
+ list_del(&(hp->next));
+ spin_unlock_irqrestore(&hp->lock, flags);
+
+ spin_unlock(&hvc_structs_lock);
+
+ kfree(hp);
+}
+
/*
* hvc_instantiate() is an early console discovery method which locates
* consoles * prior to the vio subsystem discovering them. Hotplugged
@@ -261,7 +278,7 @@ int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
/* make sure no no tty has been registered in this index */
hp = hvc_get_by_index(index);
if (hp) {
- kobject_put(&hp->kobj);
+ kref_put(&hp->kref, destroy_hvc_struct);
return -1;
}

@@ -318,9 +335,8 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
unsigned long flags;
int irq = 0;
int rc = 0;
- struct kobject *kobjp;

- /* Auto increments kobject reference if found. */
+ /* Auto increments kref reference if found. */
if (!(hp = hvc_get_by_index(tty->index)))
return -ENODEV;

@@ -341,8 +357,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
if (irq)
hp->irq_requested = 1;

- kobjp = &hp->kobj;
-
spin_unlock_irqrestore(&hp->lock, flags);
/* check error, fallback to non-irq */
if (irq)
@@ -352,7 +366,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
* If the request_irq() fails and we return an error. The tty layer
* will call hvc_close() after a failed open but we don't want to clean
* up there so we'll clean up here and clear out the previously set
- * tty fields and return the kobject reference.
+ * tty fields and return the kref reference.
*/
if (rc) {
spin_lock_irqsave(&hp->lock, flags);
@@ -360,7 +374,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
hp->irq_requested = 0;
spin_unlock_irqrestore(&hp->lock, flags);
tty->driver_data = NULL;
- kobject_put(kobjp);
+ kref_put(&hp->kref, destroy_hvc_struct);
printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc);
}
/* Force wakeup of the polling thread */
@@ -372,7 +386,6 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
static void hvc_close(struct tty_struct *tty, struct file * filp)
{
struct hvc_struct *hp;
- struct kobject *kobjp;
int irq = 0;
unsigned long flags;

@@ -382,7 +395,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
/*
* No driver_data means that this close was issued after a failed
* hvc_open by the tty layer's release_dev() function and we can just
- * exit cleanly because the kobject reference wasn't made.
+ * exit cleanly because the kref reference wasn't made.
*/
if (!tty->driver_data)
return;
@@ -390,7 +403,6 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
hp = tty->driver_data;
spin_lock_irqsave(&hp->lock, flags);

- kobjp = &hp->kobj;
if (--hp->count == 0) {
if (hp->irq_requested)
irq = hp->irq;
@@ -417,7 +429,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
spin_unlock_irqrestore(&hp->lock, flags);
}

- kobject_put(kobjp);
+ kref_put(&hp->kref, destroy_hvc_struct);
}

static void hvc_hangup(struct tty_struct *tty)
@@ -426,7 +438,6 @@ static void hvc_hangup(struct tty_struct *tty)
unsigned long flags;
int irq = 0;
int temp_open_count;
- struct kobject *kobjp;

if (!hp)
return;
@@ -443,7 +454,6 @@ static void hvc_hangup(struct tty_struct *tty)
return;
}

- kobjp = &hp->kobj;
temp_open_count = hp->count;
hp->count = 0;
hp->n_outbuf = 0;
@@ -457,7 +467,7 @@ static void hvc_hangup(struct tty_struct *tty)
free_irq(irq, hp);
while(temp_open_count) {
--temp_open_count;
- kobject_put(kobjp);
+ kref_put(&hp->kref, destroy_hvc_struct);
}
}

@@ -729,27 +739,6 @@ static const struct tty_operations hvc_ops = {
.chars_in_buffer = hvc_chars_in_buffer,
};

-/* callback when the kboject ref count reaches zero. */
-static void destroy_hvc_struct(struct kobject *kobj)
-{
- struct hvc_struct *hp = container_of(kobj, struct hvc_struct, kobj);
- unsigned long flags;
-
- spin_lock(&hvc_structs_lock);
-
- spin_lock_irqsave(&hp->lock, flags);
- list_del(&(hp->next));
- spin_unlock_irqrestore(&hp->lock, flags);
-
- spin_unlock(&hvc_structs_lock);
-
- kfree(hp);
-}
-
-static struct kobj_type hvc_kobj_type = {
- .release = destroy_hvc_struct,
-};
-
struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
struct hv_ops *ops, int outbuf_size)
{
@@ -776,8 +765,7 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
hp->outbuf_size = outbuf_size;
hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];

- kobject_init(&hp->kobj);
- hp->kobj.ktype = &hvc_kobj_type;
+ kref_init(&hp->kref);

spin_lock_init(&hp->lock);
spin_lock(&hvc_structs_lock);
@@ -806,12 +794,10 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
int __devexit hvc_remove(struct hvc_struct *hp)
{
unsigned long flags;
- struct kobject *kobjp;
struct tty_struct *tty;

spin_lock_irqsave(&hp->lock, flags);
tty = hp->tty;
- kobjp = &hp->kobj;

if (hp->index < MAX_NR_HVC_CONSOLES)
vtermnos[hp->index] = -1;
@@ -821,12 +807,12 @@ int __devexit hvc_remove(struct hvc_struct *hp)
spin_unlock_irqrestore(&hp->lock, flags);

/*
- * We 'put' the instance that was grabbed when the kobject instance
- * was initialized using kobject_init(). Let the last holder of this
- * kobject cause it to be removed, which will probably be the tty_hangup
+ * We 'put' the instance that was grabbed when the kref instance
+ * was initialized using kref_init(). Let the last holder of this
+ * kref cause it to be removed, which will probably be the tty_hangup
* below.
*/
- kobject_put(kobjp);
+ kref_put(&hp->kref, destroy_hvc_struct);

/*
* This function call will auto chain call hvc_hangup. The tty should
--
1.5.3.8

2008-01-25 07:26:11

by Greg KH

[permalink] [raw]
Subject: [PATCH 035/196] kobject: convert hvcs to use kref, not kobject

hvcs is using a kobject only for reference counting, nothing else. So
switch it to use a kref instead, which is all that is needed, and is
much smaller.

Cc: Anton Blanchard <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Ryan S. Arnold <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/char/hvcs.c | 78 ++++++++++++++++----------------------------------
1 files changed, 25 insertions(+), 53 deletions(-)

diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 69d8866..fd75590 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -57,11 +57,7 @@
* rescanning partner information upon a user's request.
*
* Each vty-server, prior to being exposed to this driver is reference counted
- * using the 2.6 Linux kernel kobject construct. This kobject is also used by
- * the vio bus to provide a vio device sysfs entry that this driver attaches
- * device specific attributes to, including partner information. The vio bus
- * framework also provides a sysfs entry for each vio driver. The hvcs driver
- * provides driver attributes in this entry.
+ * using the 2.6 Linux kernel kref construct.
*
* For direction on installation and usage of this driver please reference
* Documentation/powerpc/hvcs.txt.
@@ -71,7 +67,7 @@
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
-#include <linux/kobject.h>
+#include <linux/kref.h>
#include <linux/kthread.h>
#include <linux/list.h>
#include <linux/major.h>
@@ -293,12 +289,12 @@ struct hvcs_struct {
int chars_in_buffer;

/*
- * Any variable below the kobject is valid before a tty is connected and
+ * Any variable below the kref is valid before a tty is connected and
* stays valid after the tty is disconnected. These shouldn't be
* whacked until the koject refcount reaches zero though some entries
* may be changed via sysfs initiatives.
*/
- struct kobject kobj; /* ref count & hvcs_struct lifetime */
+ struct kref kref; /* ref count & hvcs_struct lifetime */
int connected; /* is the vty-server currently connected to a vty? */
uint32_t p_unit_address; /* partner unit address */
uint32_t p_partition_ID; /* partner partition ID */
@@ -307,8 +303,8 @@ struct hvcs_struct {
struct vio_dev *vdev;
};

-/* Required to back map a kobject to its containing object */
-#define from_kobj(kobj) container_of(kobj, struct hvcs_struct, kobj)
+/* Required to back map a kref to its containing object */
+#define from_kref(k) container_of(k, struct hvcs_struct, kref)

static struct list_head hvcs_structs = LIST_HEAD_INIT(hvcs_structs);
static DEFINE_SPINLOCK(hvcs_structs_lock);
@@ -334,7 +330,6 @@ static void hvcs_partner_free(struct hvcs_struct *hvcsd);
static int hvcs_enable_device(struct hvcs_struct *hvcsd,
uint32_t unit_address, unsigned int irq, struct vio_dev *dev);

-static void destroy_hvcs_struct(struct kobject *kobj);
static int hvcs_open(struct tty_struct *tty, struct file *filp);
static void hvcs_close(struct tty_struct *tty, struct file *filp);
static void hvcs_hangup(struct tty_struct * tty);
@@ -703,10 +698,10 @@ static void hvcs_return_index(int index)
hvcs_index_list[index] = -1;
}

-/* callback when the kboject ref count reaches zero */
-static void destroy_hvcs_struct(struct kobject *kobj)
+/* callback when the kref ref count reaches zero */
+static void destroy_hvcs_struct(struct kref *kref)
{
- struct hvcs_struct *hvcsd = from_kobj(kobj);
+ struct hvcs_struct *hvcsd = from_kref(kref);
struct vio_dev *vdev;
unsigned long flags;

@@ -743,10 +738,6 @@ static void destroy_hvcs_struct(struct kobject *kobj)
kfree(hvcsd);
}

-static struct kobj_type hvcs_kobj_type = {
- .release = destroy_hvcs_struct,
-};
-
static int hvcs_get_index(void)
{
int i;
@@ -791,9 +782,7 @@ static int __devinit hvcs_probe(

spin_lock_init(&hvcsd->lock);
/* Automatically incs the refcount the first time */
- kobject_init(&hvcsd->kobj);
- /* Set up the callback for terminating the hvcs_struct's life */
- hvcsd->kobj.ktype = &hvcs_kobj_type;
+ kref_init(&hvcsd->kref);

hvcsd->vdev = dev;
dev->dev.driver_data = hvcsd;
@@ -844,7 +833,6 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
{
struct hvcs_struct *hvcsd = dev->dev.driver_data;
unsigned long flags;
- struct kobject *kobjp;
struct tty_struct *tty;

if (!hvcsd)
@@ -856,15 +844,13 @@ static int __devexit hvcs_remove(struct vio_dev *dev)

tty = hvcsd->tty;

- kobjp = &hvcsd->kobj;
-
spin_unlock_irqrestore(&hvcsd->lock, flags);

/*
* Let the last holder of this object cause it to be removed, which
* would probably be tty_hangup below.
*/
- kobject_put (kobjp);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);

/*
* The hangup is a scheduled function which will auto chain call
@@ -1086,7 +1072,7 @@ static int hvcs_enable_device(struct hvcs_struct *hvcsd, uint32_t unit_address,
}

/*
- * This always increments the kobject ref count if the call is successful.
+ * This always increments the kref ref count if the call is successful.
* Please remember to dec when you are done with the instance.
*
* NOTICE: Do NOT hold either the hvcs_struct.lock or hvcs_structs_lock when
@@ -1103,7 +1089,7 @@ static struct hvcs_struct *hvcs_get_by_index(int index)
list_for_each_entry(hvcsd, &hvcs_structs, next) {
spin_lock_irqsave(&hvcsd->lock, flags);
if (hvcsd->index == index) {
- kobject_get(&hvcsd->kobj);
+ kref_get(&hvcsd->kref);
spin_unlock_irqrestore(&hvcsd->lock, flags);
spin_unlock(&hvcs_structs_lock);
return hvcsd;
@@ -1129,14 +1115,13 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
unsigned int irq;
struct vio_dev *vdev;
unsigned long unit_address;
- struct kobject *kobjp;

if (tty->driver_data)
goto fast_open;

/*
* Is there a vty-server that shares the same index?
- * This function increments the kobject index.
+ * This function increments the kref index.
*/
if (!(hvcsd = hvcs_get_by_index(tty->index))) {
printk(KERN_WARNING "HVCS: open failed, no device associated"
@@ -1181,7 +1166,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
* and will grab the spinlock and free the connection if it fails.
*/
if (((rc = hvcs_enable_device(hvcsd, unit_address, irq, vdev)))) {
- kobject_put(&hvcsd->kobj);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);
printk(KERN_WARNING "HVCS: enable device failed.\n");
return rc;
}
@@ -1192,17 +1177,11 @@ fast_open:
hvcsd = tty->driver_data;

spin_lock_irqsave(&hvcsd->lock, flags);
- if (!kobject_get(&hvcsd->kobj)) {
- spin_unlock_irqrestore(&hvcsd->lock, flags);
- printk(KERN_ERR "HVCS: Kobject of open"
- " hvcs doesn't exist.\n");
- return -EFAULT; /* Is this the right return value? */
- }
-
+ kref_get(&hvcsd->kref);
hvcsd->open_count++;
-
hvcsd->todo_mask |= HVCS_SCHED_READ;
spin_unlock_irqrestore(&hvcsd->lock, flags);
+
open_success:
hvcs_kick();

@@ -1212,9 +1191,8 @@ open_success:
return 0;

error_release:
- kobjp = &hvcsd->kobj;
spin_unlock_irqrestore(&hvcsd->lock, flags);
- kobject_put(&hvcsd->kobj);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);

printk(KERN_WARNING "HVCS: partner connect failed.\n");
return retval;
@@ -1224,7 +1202,6 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
{
struct hvcs_struct *hvcsd;
unsigned long flags;
- struct kobject *kobjp;
int irq = NO_IRQ;

/*
@@ -1245,7 +1222,6 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
hvcsd = tty->driver_data;

spin_lock_irqsave(&hvcsd->lock, flags);
- kobjp = &hvcsd->kobj;
if (--hvcsd->open_count == 0) {

vio_disable_interrupts(hvcsd->vdev);
@@ -1270,7 +1246,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
tty->driver_data = NULL;

free_irq(irq, hvcsd);
- kobject_put(kobjp);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);
return;
} else if (hvcsd->open_count < 0) {
printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
@@ -1279,7 +1255,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
}

spin_unlock_irqrestore(&hvcsd->lock, flags);
- kobject_put(kobjp);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);
}

static void hvcs_hangup(struct tty_struct * tty)
@@ -1287,21 +1263,17 @@ static void hvcs_hangup(struct tty_struct * tty)
struct hvcs_struct *hvcsd = tty->driver_data;
unsigned long flags;
int temp_open_count;
- struct kobject *kobjp;
int irq = NO_IRQ;

spin_lock_irqsave(&hvcsd->lock, flags);
- /* Preserve this so that we know how many kobject refs to put */
+ /* Preserve this so that we know how many kref refs to put */
temp_open_count = hvcsd->open_count;

/*
- * Don't kobject put inside the spinlock because the destruction
+ * Don't kref put inside the spinlock because the destruction
* callback may use the spinlock and it may get called before the
- * spinlock has been released. Get a pointer to the kobject and
- * kobject_put on that after releasing the spinlock.
+ * spinlock has been released.
*/
- kobjp = &hvcsd->kobj;
-
vio_disable_interrupts(hvcsd->vdev);

hvcsd->todo_mask = 0;
@@ -1324,7 +1296,7 @@ static void hvcs_hangup(struct tty_struct * tty)
free_irq(irq, hvcsd);

/*
- * We need to kobject_put() for every open_count we have since the
+ * We need to kref_put() for every open_count we have since the
* tty_hangup() function doesn't invoke a close per open connection on a
* non-console device.
*/
@@ -1335,7 +1307,7 @@ static void hvcs_hangup(struct tty_struct * tty)
* NOTE: If this hangup was signaled from user space then the
* final put will never happen.
*/
- kobject_put(kobjp);
+ kref_put(&hvcsd->kref, destroy_hvcs_struct);
}
}

--
1.5.3.8

2008-01-25 07:26:36

by Greg KH

[permalink] [raw]
Subject: [PATCH 036/196] kobject: convert icom to use kref, not kobject

The IBM icom serial driver is using a kobject only for reference
counting, nothing else. So switch it to use a kref instead, which is
all that is needed, and is much smaller.

Cc: Anton Blanchard <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Ryan S. Arnold <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/serial/icom.c | 24 ++++++++++--------------
drivers/serial/icom.h | 2 +-
2 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 9d3105b..9c2df5c 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -48,7 +48,7 @@
#include <linux/vmalloc.h>
#include <linux/smp.h>
#include <linux/spinlock.h>
-#include <linux/kobject.h>
+#include <linux/kref.h>
#include <linux/firmware.h>
#include <linux/bitops.h>

@@ -65,7 +65,7 @@
#define ICOM_VERSION_STR "1.3.1"
#define NR_PORTS 128
#define ICOM_PORT ((struct icom_port *)port)
-#define to_icom_adapter(d) container_of(d, struct icom_adapter, kobj)
+#define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)

static const struct pci_device_id icom_pci_table[] = {
{
@@ -141,6 +141,7 @@ static inline void trace(struct icom_port *, char *, unsigned long) {};
#else
static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
#endif
+static void icom_kref_release(struct kref *kref);

static void free_port_memory(struct icom_port *icom_port)
{
@@ -1063,11 +1064,11 @@ static int icom_open(struct uart_port *port)
{
int retval;

- kobject_get(&ICOM_PORT->adapter->kobj);
+ kref_get(&ICOM_PORT->adapter->kref);
retval = startup(ICOM_PORT);

if (retval) {
- kobject_put(&ICOM_PORT->adapter->kobj);
+ kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
trace(ICOM_PORT, "STARTUP_ERROR", 0);
return retval;
}
@@ -1088,7 +1089,7 @@ static void icom_close(struct uart_port *port)

shutdown(ICOM_PORT);

- kobject_put(&ICOM_PORT->adapter->kobj);
+ kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
}

static void icom_set_termios(struct uart_port *port,
@@ -1485,18 +1486,14 @@ static void icom_remove_adapter(struct icom_adapter *icom_adapter)
pci_release_regions(icom_adapter->pci_dev);
}

-static void icom_kobj_release(struct kobject *kobj)
+static void icom_kref_release(struct kref *kref)
{
struct icom_adapter *icom_adapter;

- icom_adapter = to_icom_adapter(kobj);
+ icom_adapter = to_icom_adapter(kref);
icom_remove_adapter(icom_adapter);
}

-static struct kobj_type icom_kobj_type = {
- .release = icom_kobj_release,
-};
-
static int __devinit icom_probe(struct pci_dev *dev,
const struct pci_device_id *ent)
{
@@ -1592,8 +1589,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
}
}

- kobject_init(&icom_adapter->kobj);
- icom_adapter->kobj.ktype = &icom_kobj_type;
+ kref_init(&icom_adapter->kref);
return 0;

probe_exit2:
@@ -1619,7 +1615,7 @@ static void __devexit icom_remove(struct pci_dev *dev)
icom_adapter = list_entry(tmp, struct icom_adapter,
icom_adapter_entry);
if (icom_adapter->pci_dev == dev) {
- kobject_put(&icom_adapter->kobj);
+ kref_put(&icom_adapter->kref, icom_kref_release);
return;
}
}
diff --git a/drivers/serial/icom.h b/drivers/serial/icom.h
index e8578d8..0274554 100644
--- a/drivers/serial/icom.h
+++ b/drivers/serial/icom.h
@@ -270,7 +270,7 @@ struct icom_adapter {
#define V2_ONE_PORT_RVX_ONE_PORT_IMBED_MDM 0x0251
int numb_ports;
struct list_head icom_adapter_entry;
- struct kobject kobj;
+ struct kref kref;
};

/* prototype */
--
1.5.3.8

2008-01-25 07:26:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 037/196] kobject: fix up kobject_set_name to use kvasprintf

Kay pointed out that kobject_set_name was being very stupid, doing two
allocations for every call, when it should just be using the kernel
function kvasprintf() instead.

This change adds the internal kobject_set_name_vargs() function, which
other follow-on patches will be using.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 71 +++++++++++++++++++++++++-------------------------------
1 files changed, 32 insertions(+), 39 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 9500339..4a310e5 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -232,60 +232,53 @@ int kobject_register(struct kobject * kobj)
return error;
}

+/**
+ * kobject_set_name_vargs - Set the name of an kobject
+ * @kobj: struct kobject to set the name of
+ * @fmt: format string used to build the name
+ * @vargs: vargs to format the string.
+ */
+static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
+ va_list vargs)
+{
+ va_list aq;
+ char *name;
+
+ va_copy(aq, vargs);
+ name = kvasprintf(GFP_KERNEL, fmt, vargs);
+ va_end(aq);
+
+ if (!name)
+ return -ENOMEM;
+
+ /* Free the old name, if necessary. */
+ kfree(kobj->k_name);
+
+ /* Now, set the new name */
+ kobj->k_name = name;
+
+ return 0;
+}

/**
* kobject_set_name - Set the name of a kobject
- * @kobj: kobject to name
+ * @kobj: struct kobject to set the name of
* @fmt: format string used to build the name
*
* This sets the name of the kobject. If you have already added the
* kobject to the system, you must call kobject_rename() in order to
* change the name of the kobject.
*/
-int kobject_set_name(struct kobject * kobj, const char * fmt, ...)
+int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
{
- int error = 0;
- int limit;
- int need;
va_list args;
- char *name;
+ int retval;

- /* find out how big a buffer we need */
- name = kmalloc(1024, GFP_KERNEL);
- if (!name) {
- error = -ENOMEM;
- goto done;
- }
va_start(args, fmt);
- need = vsnprintf(name, 1024, fmt, args);
+ retval = kobject_set_name_vargs(kobj, fmt, args);
va_end(args);
- kfree(name);

- /* Allocate the new space and copy the string in */
- limit = need + 1;
- name = kmalloc(limit, GFP_KERNEL);
- if (!name) {
- error = -ENOMEM;
- goto done;
- }
- va_start(args, fmt);
- need = vsnprintf(name, limit, fmt, args);
- va_end(args);
-
- /* something wrong with the string we copied? */
- if (need >= limit) {
- kfree(name);
- error = -EFAULT;
- goto done;
- }
-
- /* Free the old name, if necessary. */
- kfree(kobj->k_name);
-
- /* Now, set the new name */
- kobj->k_name = name;
-done:
- return error;
+ return retval;
}
EXPORT_SYMBOL(kobject_set_name);

--
1.5.3.8

2008-01-25 07:27:18

by Greg KH

[permalink] [raw]
Subject: [PATCH 038/196] kobject: make kobject_cleanup be static

No one except the kobject core calls it so make the function static.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 2 --
lib/kobject.c | 9 ++++-----
2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 4a0d27f..2d19a07 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -79,8 +79,6 @@ static inline const char * kobject_name(const struct kobject * kobj)
}

extern void kobject_init(struct kobject *);
-extern void kobject_cleanup(struct kobject *);
-
extern int __must_check kobject_add(struct kobject *);
extern void kobject_del(struct kobject *);

diff --git a/lib/kobject.c b/lib/kobject.c
index 4a310e5..a152036 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -436,12 +436,11 @@ struct kobject * kobject_get(struct kobject * kobj)
return kobj;
}

-/**
- * kobject_cleanup - free kobject resources.
- * @kobj: object.
+/*
+ * kobject_cleanup - free kobject resources.
+ * @kobj: object to cleanup
*/
-
-void kobject_cleanup(struct kobject * kobj)
+static void kobject_cleanup(struct kobject *kobj)
{
struct kobj_type * t = get_ktype(kobj);
struct kset * s = kobj->kset;
--
1.5.3.8

2008-01-25 07:27:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 039/196] kobject: add kobject_init_ng function

This is what the kobject_init function is going to become.

Add this to the kernel and then we can convert the tree over to use it.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 1 +
lib/kobject.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 2d19a07..bdf4f7c 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -79,6 +79,7 @@ static inline const char * kobject_name(const struct kobject * kobj)
}

extern void kobject_init(struct kobject *);
+extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
extern int __must_check kobject_add(struct kobject *);
extern void kobject_del(struct kobject *);

diff --git a/lib/kobject.c b/lib/kobject.c
index a152036..60586bc 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -283,6 +283,48 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
EXPORT_SYMBOL(kobject_set_name);

/**
+ * kobject_init_ng - initialize a kobject structure
+ * @kobj: pointer to the kobject to initialize
+ * @ktype: pointer to the ktype for this kobject.
+ *
+ * This function will properly initialize a kobject such that it can then
+ * be passed to the kobject_add() call.
+ *
+ * After this function is called, the kobject MUST be cleaned up by a call
+ * to kobject_put(), not by a call to kfree directly to ensure that all of
+ * the memory is cleaned up properly.
+ */
+void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype)
+{
+ char *err_str;
+
+ if (!kobj) {
+ err_str = "invalid kobject pointer!";
+ goto error;
+ }
+ if (!ktype) {
+ err_str = "must have a ktype to be initialized properly!\n";
+ goto error;
+ }
+ if (atomic_read(&kobj->kref.refcount)) {
+ /* do not error out as sometimes we can recover */
+ printk(KERN_ERR "kobject: reference count is already set, "
+ "something is seriously wrong.\n");
+ dump_stack();
+ }
+
+ kref_init(&kobj->kref);
+ INIT_LIST_HEAD(&kobj->entry);
+ kobj->ktype = ktype;
+ return;
+
+error:
+ printk(KERN_ERR "kobject: %s\n", err_str);
+ dump_stack();
+}
+EXPORT_SYMBOL(kobject_init_ng);
+
+/**
* kobject_rename - change the name of an object
* @kobj: object in question.
* @new_name: object's new name
--
1.5.3.8

2008-01-25 07:28:00

by Greg KH

[permalink] [raw]
Subject: [PATCH 040/196] kobject: add kobject_add_ng function

This is what the kobject_add function is going to become.

Add this to the kernel and then we can convert the tree over to use it.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 3 ++
lib/kobject.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bdf4f7c..57eea4c 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -81,6 +81,9 @@ static inline const char * kobject_name(const struct kobject * kobj)
extern void kobject_init(struct kobject *);
extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
extern int __must_check kobject_add(struct kobject *);
+extern int __must_check kobject_add_ng(struct kobject *kobj,
+ struct kobject *parent,
+ const char *fmt, ...);
extern void kobject_del(struct kobject *);

extern int __must_check kobject_rename(struct kobject *, const char *new_name);
diff --git a/lib/kobject.c b/lib/kobject.c
index 60586bc..329fd11 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -324,6 +324,72 @@ error:
}
EXPORT_SYMBOL(kobject_init_ng);

+static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
+ const char *fmt, va_list vargs)
+{
+ va_list aq;
+ int retval;
+
+ va_copy(aq, vargs);
+ retval = kobject_set_name_vargs(kobj, fmt, aq);
+ va_end(aq);
+ if (retval) {
+ printk(KERN_ERR "kobject: can not set name properly!\n");
+ return retval;
+ }
+ kobj->parent = parent;
+ return kobject_add(kobj);
+}
+
+/**
+ * kobject_add_ng - the main kobject add function
+ * @kobj: the kobject to add
+ * @parent: pointer to the parent of the kobject.
+ * @fmt: format to name the kobject with.
+ *
+ * The kobject name is set and added to the kobject hierarchy in this
+ * function.
+ *
+ * If @parent is set, then the parent of the @kobj will be set to it.
+ * If @parent is NULL, then the parent of the @kobj will be set to the
+ * kobject associted with the kset assigned to this kobject. If no kset
+ * is assigned to the kobject, then the kobject will be located in the
+ * root of the sysfs tree.
+ *
+ * If this function returns an error, kobject_put() must be called to
+ * properly clean up the memory associated with the object.
+ *
+ * If the function is successful, the only way to properly clean up the
+ * memory is with a call to kobject_del(), in which case, a call to
+ * kobject_put() is not necessary (kobject_del() does the final
+ * kobject_put() to call the release function in the ktype's release
+ * pointer.)
+ *
+ * Under no instance should the kobject that is passed to this function
+ * be directly freed with a call to kfree(), that can leak memory.
+ *
+ * Note, no uevent will be created with this call, the caller should set
+ * up all of the necessary sysfs files for the object and then call
+ * kobject_uevent() with the UEVENT_ADD parameter to ensure that
+ * userspace is properly notified of this kobject's creation.
+ */
+int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
+ const char *fmt, ...)
+{
+ va_list args;
+ int retval;
+
+ if (!kobj)
+ return -EINVAL;
+
+ va_start(args, fmt);
+ retval = kobject_add_varg(kobj, parent, fmt, args);
+ va_end(args);
+
+ return retval;
+}
+EXPORT_SYMBOL(kobject_add_ng);
+
/**
* kobject_rename - change the name of an object
* @kobj: object in question.
--
1.5.3.8

2008-01-25 07:28:35

by Greg KH

[permalink] [raw]
Subject: [PATCH 041/196] kobject: add kobject_init_and_add function

Also add a kobject_init_and_add function which bundles up what a lot of
the current callers want to do all at once, and it properly handles the
memory usages, unlike kobject_register();

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 5 +++++
lib/kobject.c | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 57eea4c..e2b8c3d 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -84,6 +84,11 @@ extern int __must_check kobject_add(struct kobject *);
extern int __must_check kobject_add_ng(struct kobject *kobj,
struct kobject *parent,
const char *fmt, ...);
+extern int __must_check kobject_init_and_add(struct kobject *kobj,
+ struct kobj_type *ktype,
+ struct kobject *parent,
+ const char *fmt, ...);
+
extern void kobject_del(struct kobject *);

extern int __must_check kobject_rename(struct kobject *, const char *new_name);
diff --git a/lib/kobject.c b/lib/kobject.c
index 329fd11..8f24940 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -391,6 +391,33 @@ int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
EXPORT_SYMBOL(kobject_add_ng);

/**
+ * kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
+ * @kobj: pointer to the kobject to initialize
+ * @ktype: pointer to the ktype for this kobject.
+ * @parent: pointer to the parent of this kobject.
+ * @fmt: the name of the kobject.
+ *
+ * This function combines the call to kobject_init_ng() and
+ * kobject_add_ng(). The same type of error handling after a call to
+ * kobject_add_ng() and kobject lifetime rules are the same here.
+ */
+int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
+ struct kobject *parent, const char *fmt, ...)
+{
+ va_list args;
+ int retval;
+
+ kobject_init_ng(kobj, ktype);
+
+ va_start(args, fmt);
+ retval = kobject_add_varg(kobj, parent, fmt, args);
+ va_end(args);
+
+ return retval;
+}
+EXPORT_SYMBOL_GPL(kobject_init_and_add);
+
+/**
* kobject_rename - change the name of an object
* @kobj: object in question.
* @new_name: object's new name
--
1.5.3.8

2008-01-25 07:28:53

by Greg KH

[permalink] [raw]
Subject: [PATCH 042/196] kobject: remove struct kobj_type from struct kset

We don't need a "default" ktype for a kset. We should set this
explicitly every time for each kset. This change is needed so that we
can make ksets dynamic, and cleans up one of the odd, undocumented
assumption that the kset/kobject/ktype model has.

This patch is based on a lot of help from Kay Sievers.

Nasty bug in the block code was found by Dave Young
<[email protected]>

Cc: Kay Sievers <[email protected]>
Cc: Dave Young <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/powerpc/platforms/pseries/power.c | 2 +-
arch/s390/hypfs/inode.c | 4 ++--
arch/s390/kernel/ipl.c | 8 ++++----
block/genhd.c | 5 +++--
drivers/acpi/bus.c | 2 +-
drivers/base/bus.c | 5 +++--
drivers/base/class.c | 8 +++++---
drivers/base/core.c | 5 +++--
drivers/base/firmware.c | 5 +++--
drivers/base/hypervisor.c | 2 +-
drivers/base/sys.c | 3 ++-
drivers/edac/edac_mc_sysfs.c | 2 +-
drivers/firmware/edd.c | 5 +++--
drivers/firmware/efivars.c | 9 +++++----
drivers/parisc/pdc_stable.c | 9 +++++----
drivers/pci/hotplug/pci_hotplug_core.c | 7 ++++---
drivers/pci/hotplug/rpadlpar_sysfs.c | 1 -
drivers/uio/uio.c | 2 +-
fs/configfs/mount.c | 4 ++--
fs/debugfs/inode.c | 4 ++--
fs/dlm/lockspace.c | 6 ++----
fs/ecryptfs/main.c | 4 ++--
fs/fuse/inode.c | 8 ++++----
fs/gfs2/locking/dlm/sysfs.c | 6 ++----
fs/gfs2/sys.c | 6 ++----
fs/namespace.c | 2 +-
fs/ocfs2/cluster/masklog.c | 2 +-
fs/ocfs2/cluster/sys.c | 2 +-
fs/sysfs/file.c | 4 +---
include/linux/kobject.h | 15 ++++-----------
kernel/ksysfs.c | 2 +-
kernel/module.c | 2 +-
kernel/params.c | 9 +++++----
kernel/power/main.c | 2 +-
mm/slub.c | 5 +++--
security/inode.c | 4 ++--
36 files changed, 84 insertions(+), 87 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index 73e6902..08d7a50 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -57,7 +57,7 @@ static struct subsys_attribute auto_poweron_attr = {
};

#ifndef CONFIG_PM
-decl_subsys(power,NULL,NULL);
+decl_subsys(power, NULL);

static struct attribute *g[] = {
&auto_poweron_attr.attr,
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 5245717..c022ccc 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -490,7 +490,7 @@ static struct super_operations hypfs_s_ops = {
.show_options = hypfs_show_options,
};

-static decl_subsys(s390, NULL, NULL);
+static decl_subsys(s390, NULL);

static int __init hypfs_init(void)
{
@@ -506,7 +506,7 @@ static int __init hypfs_init(void)
goto fail_diag;
}
}
- kobj_set_kset_s(&s390_subsys, hypervisor_subsys);
+ s390_subsys.kobj.kset = &hypervisor_subsys;
rc = subsystem_register(&s390_subsys);
if (rc)
goto fail_sysfs;
diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index ce0856d..cae793a 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -418,7 +418,7 @@ static struct attribute_group ipl_unknown_attr_group = {
.attrs = ipl_unknown_attrs,
};

-static decl_subsys(ipl, NULL, NULL);
+static decl_subsys(ipl, NULL);

/*
* reipl section
@@ -590,7 +590,7 @@ static ssize_t reipl_type_store(struct kset *kset, const char *buf,
static struct subsys_attribute reipl_type_attr =
__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);

-static decl_subsys(reipl, NULL, NULL);
+static decl_subsys(reipl, NULL);

/*
* dump section
@@ -685,13 +685,13 @@ static ssize_t dump_type_store(struct kset *kset, const char *buf,
static struct subsys_attribute dump_type_attr =
__ATTR(dump_type, 0644, dump_type_show, dump_type_store);

-static decl_subsys(dump, NULL, NULL);
+static decl_subsys(dump, NULL);

/*
* Shutdown actions section
*/

-static decl_subsys(shutdown_actions, NULL, NULL);
+static decl_subsys(shutdown_actions, NULL);

/* on panic */

diff --git a/block/genhd.c b/block/genhd.c
index f2ac914..32227b7 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -584,7 +584,7 @@ static struct kset_uevent_ops block_uevent_ops = {
.uevent = block_uevent,
};

-decl_subsys(block, &ktype_block, &block_uevent_ops);
+decl_subsys(block, &block_uevent_ops);

/*
* aggregate disk stat collector. Uses the same stats that the sysfs
@@ -721,7 +721,8 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
}
}
disk->minors = minors;
- kobj_set_kset_s(disk,block_subsys);
+ disk->kobj.kset = &block_subsys;
+ disk->kobj.ktype = &ktype_block;
kobject_init(&disk->kobj);
rand_initialize_disk(disk);
INIT_WORK(&disk->async_notify,
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index f4487c3..7c172d9 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -743,7 +743,7 @@ static int __init acpi_bus_init(void)
return -ENODEV;
}

-decl_subsys(acpi, NULL, NULL);
+decl_subsys(acpi, NULL);

static int __init acpi_init(void)
{
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 9a19b07..6309560 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -166,7 +166,7 @@ static struct kset_uevent_ops bus_uevent_ops = {
.filter = bus_uevent_filter,
};

-static decl_subsys(bus, &bus_ktype, &bus_uevent_ops);
+static decl_subsys(bus, &bus_uevent_ops);


#ifdef CONFIG_HOTPLUG
@@ -639,6 +639,7 @@ int bus_add_driver(struct device_driver *drv)
if (error)
goto out_put_bus;
drv->kobj.kset = &bus->drivers;
+ drv->kobj.ktype = &driver_ktype;
error = kobject_register(&drv->kobj);
if (error)
goto out_put_bus;
@@ -851,6 +852,7 @@ int bus_register(struct bus_type * bus)
goto out;

bus->subsys.kobj.kset = &bus_subsys;
+ bus->subsys.kobj.ktype = &bus_ktype;

retval = subsystem_register(&bus->subsys);
if (retval)
@@ -868,7 +870,6 @@ int bus_register(struct bus_type * bus)

kobject_set_name(&bus->drivers.kobj, "drivers");
bus->drivers.kobj.parent = &bus->subsys.kobj;
- bus->drivers.ktype = &driver_ktype;
retval = kset_register(&bus->drivers);
if (retval)
goto bus_drivers_fail;
diff --git a/drivers/base/class.c b/drivers/base/class.c
index a863bb0..8ad9892 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -71,7 +71,7 @@ static struct kobj_type class_ktype = {
};

/* Hotplug events for classes go to the class_obj subsys */
-static decl_subsys(class, &class_ktype, NULL);
+static decl_subsys(class, NULL);


int class_create_file(struct class * cls, const struct class_attribute * attr)
@@ -150,6 +150,7 @@ int class_register(struct class * cls)
return error;

cls->subsys.kobj.kset = &class_subsys;
+ cls->subsys.kobj.ktype = &class_ktype;

error = subsystem_register(&cls->subsys);
if (!error) {
@@ -452,7 +453,7 @@ static struct kset_uevent_ops class_uevent_ops = {
.uevent = class_uevent,
};

-static decl_subsys(class_obj, &class_device_ktype, &class_uevent_ops);
+static decl_subsys(class_obj, &class_uevent_ops);


static int class_device_add_attrs(struct class_device * cd)
@@ -537,7 +538,8 @@ static struct class_device_attribute class_uevent_attr =

void class_device_initialize(struct class_device *class_dev)
{
- kobj_set_kset_s(class_dev, class_obj_subsys);
+ class_dev->kobj.kset = &class_obj_subsys;
+ class_dev->kobj.ktype = &class_device_ktype;
kobject_init(&class_dev->kobj);
INIT_LIST_HEAD(&class_dev->node);
}
diff --git a/drivers/base/core.c b/drivers/base/core.c
index ce6b64c..c8f2ac0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -405,7 +405,7 @@ static struct device_attribute devt_attr =
* devices_subsys - structure to be registered with kobject core.
*/

-decl_subsys(devices, &device_ktype, &device_uevent_ops);
+decl_subsys(devices, &device_uevent_ops);


/**
@@ -525,7 +525,8 @@ static void klist_children_put(struct klist_node *n)

void device_initialize(struct device *dev)
{
- kobj_set_kset_s(dev, devices_subsys);
+ dev->kobj.kset = &devices_subsys;
+ dev->kobj.ktype = &device_ktype;
kobject_init(&dev->kobj);
klist_init(&dev->klist_children, klist_children_get,
klist_children_put);
diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 90c8629..336be04 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -15,11 +15,12 @@

#include "base.h"

-static decl_subsys(firmware, NULL, NULL);
+static decl_subsys(firmware, NULL);

int firmware_register(struct kset *s)
{
- kobj_set_kset_s(s, firmware_subsys);
+ s->kobj.kset = &firmware_subsys;
+ s->kobj.ktype = NULL;
return subsystem_register(s);
}

diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c
index 7080b41..14e75e9 100644
--- a/drivers/base/hypervisor.c
+++ b/drivers/base/hypervisor.c
@@ -11,7 +11,7 @@

#include "base.h"

-decl_subsys(hypervisor, NULL, NULL);
+decl_subsys(hypervisor, NULL);
EXPORT_SYMBOL_GPL(hypervisor_subsys);

int __init hypervisor_init(void)
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index ac7ff6d..7cf19fc 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -131,7 +131,7 @@ EXPORT_SYMBOL_GPL(sysdev_class_remove_file);
/*
* declare system_subsys
*/
-static decl_subsys(system, &ktype_sysdev_class, NULL);
+static decl_subsys(system, NULL);

int sysdev_class_register(struct sysdev_class * cls)
{
@@ -139,6 +139,7 @@ int sysdev_class_register(struct sysdev_class * cls)
kobject_name(&cls->kset.kobj));
INIT_LIST_HEAD(&cls->drivers);
cls->kset.kobj.parent = &system_subsys.kobj;
+ cls->kset.kobj.ktype = &ktype_sysdev_class;
cls->kset.kobj.kset = &system_subsys;
return kset_register(&cls->kset);
}
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 3706b2b..905fcd7 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -744,7 +744,6 @@ static struct kobj_type ktype_mc_set_attribs = {
*/
static struct kset mc_kset = {
.kobj = {.ktype = &ktype_mc_set_attribs },
- .ktype = &ktype_mci,
};


@@ -767,6 +766,7 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)

/* this instance become part of the mc_kset */
kobj_mci->kset = &mc_kset;
+ kobj_mci->ktype = &ktype_mci;

/* set the name of the mc<id> object */
err = kobject_set_name(kobj_mci, "mc%d", mci->mc_idx);
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 6942e06..fc567fa 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -631,7 +631,7 @@ static struct kobj_type edd_ktype = {
.default_attrs = def_attrs,
};

-static decl_subsys(edd, &edd_ktype, NULL);
+static decl_subsys(edd, NULL);


/**
@@ -723,7 +723,8 @@ edd_device_register(struct edd_device *edev, int i)
edd_dev_set_info(edev, i);
kobject_set_name(&edev->kobj, "int13_dev%02x",
0x80 + i);
- kobj_set_kset_s(edev,edd_subsys);
+ edev->kobj.kset = &edd_subsys;
+ edev->kobj.ktype = &edd_ktype;
error = kobject_register(&edev->kobj);
if (!error)
edd_populate_dir(edev);
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 858a7b9..06ecdb9 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -583,8 +583,8 @@ static struct subsys_attribute *efi_subsys_attrs[] = {
NULL, /* maybe more in the future? */
};

-static decl_subsys(vars, &efivar_ktype, NULL);
-static decl_subsys(efi, NULL, NULL);
+static decl_subsys(vars, NULL);
+static decl_subsys(efi, NULL);

/*
* efivar_create_sysfs_entry()
@@ -629,7 +629,8 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

kobject_set_name(&new_efivar->kobj, "%s", short_name);
- kobj_set_kset_s(new_efivar, vars_subsys);
+ new_efivar->kobj.kset = &vars_subsys;
+ new_efivar->kobj.ktype = &efivar_ktype;
i = kobject_register(&new_efivar->kobj);
if (i) {
kfree(short_name);
@@ -687,7 +688,7 @@ efivars_init(void)
goto out_free;
}

- kobj_set_kset_s(&vars_subsys, efi_subsys);
+ vars_subsys.kobj.kset = &efi_subsys;

error = subsystem_register(&vars_subsys);

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index ebb09e9..1382be6 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -964,8 +964,8 @@ static struct subsys_attribute *pdcs_subsys_attrs[] = {
NULL,
};

-static decl_subsys(paths, &ktype_pdcspath, NULL);
-static decl_subsys(stable, NULL, NULL);
+static decl_subsys(paths, NULL);
+static decl_subsys(stable, NULL);

/**
* pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
@@ -997,7 +997,8 @@ pdcs_register_pathentries(void)

if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
return err;
- kobj_set_kset_s(entry, paths_subsys);
+ entry->kobj.kset = &paths_subsys;
+ entry->kobj.ktype = &ktype_pdcspath;
if ((err = kobject_register(&entry->kobj)))
return err;

@@ -1072,7 +1073,7 @@ pdc_stable_init(void)
error = subsys_create_file(&stable_subsys, attr);

/* register the paths subsys as a subsystem of stable subsys */
- kobj_set_kset_s(&paths_subsys, stable_subsys);
+ paths_subsys.kobj.kset = &stable_subsys;
if ((rc = subsystem_register(&paths_subsys)))
goto fail_subsysreg;

diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 01c351c..ce1cff0 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -96,7 +96,7 @@ static struct kobj_type hotplug_slot_ktype = {
.release = &hotplug_slot_release,
};

-decl_subsys_name(pci_hotplug_slots, slots, &hotplug_slot_ktype, NULL);
+decl_subsys_name(pci_hotplug_slots, slots, NULL);

/* these strings match up with the values in pci_bus_speed */
static char *pci_bus_speed_strings[] = {
@@ -633,7 +633,8 @@ int pci_hp_register (struct hotplug_slot *slot)
}

kobject_set_name(&slot->kobj, "%s", slot->name);
- kobj_set_kset_s(slot, pci_hotplug_slots_subsys);
+ slot->kobj.kset = &pci_hotplug_slots_subsys;
+ slot->kobj.ktype = &hotplug_slot_ktype;

/* this can fail if we have already registered a slot with the same name */
if (kobject_register(&slot->kobj)) {
@@ -701,7 +702,7 @@ static int __init pci_hotplug_init (void)
{
int result;

- kobj_set_kset_s(&pci_hotplug_slots_subsys, pci_bus_type.subsys);
+ pci_hotplug_slots_subsys.kobj.kset = &pci_bus_type.subsys;
result = subsystem_register(&pci_hotplug_slots_subsys);
if (result) {
err("Register subsys with error %d\n", result);
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index a080fed..7609093 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -131,7 +131,6 @@ struct kobj_type ktype_dlpar_io = {
struct kset dlpar_io_kset = {
.kobj = {.ktype = &ktype_dlpar_io,
.parent = &pci_hotplug_slots_subsys.kobj},
- .ktype = &ktype_dlpar_io,
};

int dlpar_sysfs_init(void)
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 865f32b..606aae7 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -160,7 +160,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
if (!map_found) {
map_found = 1;
kobject_set_name(&idev->map_attr_kset.kobj,"maps");
- idev->map_attr_kset.ktype = &map_attr_type;
+ idev->map_attr_kset.kobj.ktype = &map_attr_type;
idev->map_attr_kset.kobj.parent = &idev->dev->kobj;
ret = kset_register(&idev->map_attr_kset);
if (ret)
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 3bf0278..374ddbd 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -128,7 +128,7 @@ void configfs_release_fs(void)
}


-static decl_subsys(config, NULL, NULL);
+static decl_subsys(config, NULL);

static int __init configfs_init(void)
{
@@ -140,7 +140,7 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep)
goto out;

- kobj_set_kset_s(&config_subsys, kernel_subsys);
+ config_subsys.kobj.kset = &kernel_subsys;
err = subsystem_register(&config_subsys);
if (err) {
kmem_cache_destroy(configfs_dir_cachep);
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 6a713b3..f7f1351 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -426,13 +426,13 @@ exit:
}
EXPORT_SYMBOL_GPL(debugfs_rename);

-static decl_subsys(debug, NULL, NULL);
+static decl_subsys(debug, NULL);

static int __init debugfs_init(void)
{
int retval;

- kobj_set_kset_s(&debug_subsys, kernel_subsys);
+ debug_subsys.kobj.kset = &kernel_subsys;
retval = subsystem_register(&debug_subsys);
if (retval)
return retval;
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 6353a83..18e4a17 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -166,9 +166,7 @@ static struct kobj_type dlm_ktype = {
.release = lockspace_kobj_release,
};

-static struct kset dlm_kset = {
- .ktype = &dlm_ktype,
-};
+static struct kset dlm_kset;

static int kobject_setup(struct dlm_ls *ls)
{
@@ -228,7 +226,7 @@ int dlm_lockspace_init(void)
spin_lock_init(&lslist_lock);

kobject_set_name(&dlm_kset.kobj, "dlm");
- kobj_set_kset_s(&dlm_kset, kernel_subsys);
+ dlm_kset.kobj.kset = &kernel_subsys;
error = kset_register(&dlm_kset);
if (error)
printk("dlm_lockspace_init: cannot register kset %d\n", error);
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index f9f3247..fe2f44f 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,7 +734,7 @@ static int ecryptfs_init_kmem_caches(void)
return 0;
}

-static decl_subsys(ecryptfs, NULL, NULL);
+static decl_subsys(ecryptfs, NULL);

static ssize_t version_show(struct kset *kset, char *buff)
{
@@ -798,6 +798,7 @@ static int do_sysfs_registration(void)
{
int rc;

+ ecryptfs_subsys.kobj.kset = &fs_subsys;
rc = subsystem_register(&ecryptfs_subsys);
if (rc) {
printk(KERN_ERR
@@ -845,7 +846,6 @@ static int __init ecryptfs_init(void)
printk(KERN_ERR "Failed to register filesystem\n");
goto out_free_kmem_caches;
}
- kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
rc = do_sysfs_registration();
if (rc) {
printk(KERN_ERR "sysfs registration failed\n");
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 84f9f7d..f5e4182 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -744,8 +744,8 @@ static inline void unregister_fuseblk(void)
}
#endif

-static decl_subsys(fuse, NULL, NULL);
-static decl_subsys(connections, NULL, NULL);
+static decl_subsys(fuse, NULL);
+static decl_subsys(connections, NULL);

static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo)
{
@@ -795,12 +795,12 @@ static int fuse_sysfs_init(void)
{
int err;

- kobj_set_kset_s(&fuse_subsys, fs_subsys);
+ fuse_subsys.kobj.kset = &fs_subsys;
err = subsystem_register(&fuse_subsys);
if (err)
goto out_err;

- kobj_set_kset_s(&connections_subsys, fuse_subsys);
+ connections_subsys.kobj.kset = &fuse_subsys;
err = subsystem_register(&connections_subsys);
if (err)
goto out_fuse_unregister;
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index ae9e6a2..93e66b2 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -189,9 +189,7 @@ static struct kobj_type gdlm_ktype = {
.sysfs_ops = &gdlm_attr_ops,
};

-static struct kset gdlm_kset = {
- .ktype = &gdlm_ktype,
-};
+static struct kset gdlm_kset;

int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
{
@@ -224,7 +222,7 @@ int gdlm_sysfs_init(void)
int error;

kobject_set_name(&gdlm_kset.kobj, "lock_dlm");
- kobj_set_kset_s(&gdlm_kset, kernel_subsys);
+ gdlm_kset.kobj.kset = &kernel_subsys;
error = kset_register(&gdlm_kset);
if (error)
printk("lock_dlm: cannot register kset %d\n", error);
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 06e0b77..d7fa544 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -221,9 +221,7 @@ static struct kobj_type gfs2_ktype = {
.sysfs_ops = &gfs2_attr_ops,
};

-static struct kset gfs2_kset = {
- .ktype = &gfs2_ktype,
-};
+static struct kset gfs2_kset;

/*
* display struct lm_lockstruct fields
@@ -551,7 +549,7 @@ int gfs2_sys_init(void)
gfs2_sys_margs = NULL;
spin_lock_init(&gfs2_sys_margs_lock);
kobject_set_name(&gfs2_kset.kobj, "gfs2");
- kobj_set_kset_s(&gfs2_kset, fs_subsys);
+ gfs2_kset.kobj.kset = &fs_subsys;
return kset_register(&gfs2_kset);
}

diff --git a/fs/namespace.c b/fs/namespace.c
index 0608388..a4a3f70 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -41,7 +41,7 @@ static struct kmem_cache *mnt_cache __read_mostly;
static struct rw_semaphore namespace_sem;

/* /sys/fs */
-decl_subsys(fs, NULL, NULL);
+decl_subsys(fs, NULL);
EXPORT_SYMBOL_GPL(fs_subsys);

static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index a4882c8..dead319 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys)
mlog_attr_ptrs[i] = NULL;

kobject_set_name(&mlog_kset.kobj, "logmask");
- kobj_set_kset_s(&mlog_kset, *o2cb_subsys);
+ mlog_kset.kobj.kset = o2cb_subsys;
return kset_register(&mlog_kset);
}

diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 64f6f37..880d013 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -72,7 +72,7 @@ static struct kobj_type o2cb_subsys_type = {
};

/* gives us o2cb_subsys */
-static decl_subsys(o2cb, NULL, NULL);
+static decl_subsys(o2cb, NULL);

static ssize_t
o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 09a0611..387a636 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -365,9 +365,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
/* if the kobject has no ktype, then we assume that it is a subsystem
* itself, and use ops for it.
*/
- if (kobj->kset && kobj->kset->ktype)
- ops = kobj->kset->ktype->sysfs_ops;
- else if (kobj->ktype)
+ if (kobj->ktype)
ops = kobj->ktype->sysfs_ops;
else
ops = &subsys_sysfs_ops;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index e2b8c3d..5031565 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -135,7 +135,6 @@ struct kset_uevent_ops {
* define the attribute callbacks and other common events that happen to
* a kobject.
*
- * @ktype: the struct kobj_type for this specific kset
* @list: the list of all kobjects for this kset
* @list_lock: a lock for iterating over the kobjects
* @kobj: the embedded kobject for this kset (recursion, isn't it fun...)
@@ -145,7 +144,6 @@ struct kset_uevent_ops {
* desired.
*/
struct kset {
- struct kobj_type *ktype;
struct list_head list;
spinlock_t list_lock;
struct kobject kobj;
@@ -173,12 +171,9 @@ static inline void kset_put(struct kset * k)
kobject_put(&k->kobj);
}

-static inline struct kobj_type * get_ktype(struct kobject * k)
+static inline struct kobj_type *get_ktype(struct kobject *kobj)
{
- if (k->kset && k->kset->ktype)
- return k->kset->ktype;
- else
- return k->ktype;
+ return kobj->ktype;
}

extern struct kobject * kset_find_obj(struct kset *, const char *);
@@ -191,16 +186,14 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);
#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }


-#define decl_subsys(_name,_type,_uevent_ops) \
+#define decl_subsys(_name,_uevent_ops) \
struct kset _name##_subsys = { \
.kobj = { .k_name = __stringify(_name) }, \
- .ktype = _type, \
.uevent_ops =_uevent_ops, \
}
-#define decl_subsys_name(_varname,_name,_type,_uevent_ops) \
+#define decl_subsys_name(_varname,_name,_uevent_ops) \
struct kset _varname##_subsys = { \
.kobj = { .k_name = __stringify(_name) }, \
- .ktype = _type, \
.uevent_ops =_uevent_ops, \
}

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 65daa53..094e2bc 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -94,7 +94,7 @@ static struct bin_attribute notes_attr = {
.read = &notes_read,
};

-decl_subsys(kernel, NULL, NULL);
+decl_subsys(kernel, NULL);
EXPORT_SYMBOL_GPL(kernel_subsys);

static struct attribute * kernel_attrs[] = {
diff --git a/kernel/module.c b/kernel/module.c
index c2e3e2e..68df797 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1223,7 +1223,7 @@ int mod_sysfs_init(struct module *mod)
err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name);
if (err)
goto out;
- kobj_set_kset_s(&mod->mkobj, module_subsys);
+ mod->mkobj.kobj.kset = &module_subsys;
mod->mkobj.mod = mod;

kobject_init(&mod->mkobj.kobj);
diff --git a/kernel/params.c b/kernel/params.c
index 7686417..9f05182 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -30,6 +30,8 @@
#define DEBUGP(fmt, a...)
#endif

+static struct kobj_type module_ktype;
+
static inline char dash2underscore(char c)
{
if (c == '-')
@@ -560,7 +562,8 @@ static void __init kernel_param_sysfs_setup(const char *name,
BUG_ON(!mk);

mk->mod = THIS_MODULE;
- kobj_set_kset_s(mk, module_subsys);
+ mk->kobj.kset = &module_subsys;
+ mk->kobj.ktype = &module_ktype;
kobject_set_name(&mk->kobj, name);
kobject_init(&mk->kobj);
ret = kobject_add(&mk->kobj);
@@ -679,8 +682,6 @@ static struct sysfs_ops module_sysfs_ops = {
.store = module_attr_store,
};

-static struct kobj_type module_ktype;
-
static int uevent_filter(struct kset *kset, struct kobject *kobj)
{
struct kobj_type *ktype = get_ktype(kobj);
@@ -694,7 +695,7 @@ static struct kset_uevent_ops module_uevent_ops = {
.filter = uevent_filter,
};

-decl_subsys(module, &module_ktype, &module_uevent_ops);
+decl_subsys(module, &module_uevent_ops);
int module_sysfs_initialized;

static void module_release(struct kobject *kobj)
diff --git a/kernel/power/main.c b/kernel/power/main.c
index f71c950..1ef31c9 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -276,7 +276,7 @@ EXPORT_SYMBOL(pm_suspend);

#endif /* CONFIG_SUSPEND */

-decl_subsys(power,NULL,NULL);
+decl_subsys(power, NULL);


/**
diff --git a/mm/slub.c b/mm/slub.c
index 474945e..40bdf41 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3962,7 +3962,7 @@ static struct kset_uevent_ops slab_uevent_ops = {
.filter = uevent_filter,
};

-static decl_subsys(slab, &slab_ktype, &slab_uevent_ops);
+static decl_subsys(slab, &slab_uevent_ops);

#define ID_STR_LENGTH 64

@@ -4025,8 +4025,9 @@ static int sysfs_slab_add(struct kmem_cache *s)
name = create_unique_id(s);
}

- kobj_set_kset_s(s, slab_subsys);
kobject_set_name(&s->kobj, name);
+ s->kobj.kset = &slab_subsys;
+ s->kobj.ktype = &slab_ktype;
kobject_init(&s->kobj);
err = kobject_add(&s->kobj);
if (err)
diff --git a/security/inode.c b/security/inode.c
index b28a8ac..9e42f5f 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -315,13 +315,13 @@ void securityfs_remove(struct dentry *dentry)
}
EXPORT_SYMBOL_GPL(securityfs_remove);

-static decl_subsys(security, NULL, NULL);
+static decl_subsys(security, NULL);

static int __init securityfs_init(void)
{
int retval;

- kobj_set_kset_s(&security_subsys, kernel_subsys);
+ security_subsys.kobj.kset = &kernel_subsys;
retval = subsystem_register(&security_subsys);
if (retval)
return retval;
--
1.5.3.8

2008-01-25 07:29:23

by Greg KH

[permalink] [raw]
Subject: [PATCH 043/196] kobject: remove kobj_set_kset_s as no one is using it anymore

What a confusing name for a macro...

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 18 ------------------
1 files changed, 0 insertions(+), 18 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 5031565..0b97b3a 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -202,24 +202,6 @@ extern struct kset kernel_subsys;
/* The global /sys/hypervisor/ subsystem */
extern struct kset hypervisor_subsys;

-/*
- * Helpers for setting the kset of registered objects.
- * Often, a registered object belongs to a kset embedded in a
- * subsystem. These do no magic, just make the resulting code
- * easier to follow.
- */
-
-/**
- * kobj_set_kset_s(obj,subsys) - set kset for embedded kobject.
- * @obj: ptr to some object type.
- * @subsys: a subsystem object (not a ptr).
- *
- * Can be used for any object type with an embedded ->kobj.
- */
-
-#define kobj_set_kset_s(obj,subsys) \
- (obj)->kobj.kset = &(subsys)
-
extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);

--
1.5.3.8

2008-01-25 07:29:44

by Greg KH

[permalink] [raw]
Subject: [PATCH 044/196] kset: add kset_create_and_add function

Now ksets can be dynamically created on the fly, no static definitions
are required. Thanks to Miklos for hints on how to make this work
better for the callers.

And thanks to Kay for finding some stupid bugs in my original version
and pointing out that we need to handle the fact that kobject's can have
a kset as a parent and to handle that properly in kobject_add().

Cc: Kay Sievers <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 4 ++-
lib/kobject.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 94 insertions(+), 2 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 0b97b3a..f91aeb7 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -150,11 +150,13 @@ struct kset {
struct kset_uevent_ops *uevent_ops;
};

-
extern void kset_init(struct kset * k);
extern int __must_check kset_add(struct kset * k);
extern int __must_check kset_register(struct kset * k);
extern void kset_unregister(struct kset * k);
+extern struct kset * __must_check kset_create_and_add(const char *name,
+ struct kset_uevent_ops *u,
+ struct kobject *parent_kobj);

static inline struct kset * to_kset(struct kobject * kobj)
{
diff --git a/lib/kobject.c b/lib/kobject.c
index 8f24940..4fb27ba 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -186,8 +186,15 @@ int kobject_add(struct kobject * kobj)
if (kobj->kset) {
spin_lock(&kobj->kset->list_lock);

- if (!parent)
+ if (!parent) {
parent = kobject_get(&kobj->kset->kobj);
+ /*
+ * If the kset is our parent, get a second
+ * reference, we drop both the kset and the
+ * parent ref on cleanup
+ */
+ kobject_get(parent);
+ }

list_add_tail(&kobj->entry,&kobj->kset->list);
spin_unlock(&kobj->kset->list_lock);
@@ -787,6 +794,89 @@ int subsys_create_file(struct kset *s, struct subsys_attribute *a)
return error;
}

+static void kset_release(struct kobject *kobj)
+{
+ struct kset *kset = container_of(kobj, struct kset, kobj);
+ pr_debug("kset %s: now freed\n", kobject_name(kobj));
+ kfree(kset);
+}
+
+static struct kobj_type kset_type = {
+ .release = kset_release,
+};
+
+/**
+ * kset_create - create a struct kset dynamically
+ *
+ * @name: the name for the kset
+ * @uevent_ops: a struct kset_uevent_ops for the kset
+ * @parent_kobj: the parent kobject of this kset, if any.
+ *
+ * This function creates a kset structure dynamically. This structure can
+ * then be registered with the system and show up in sysfs with a call to
+ * kset_register(). When you are finished with this structure, if
+ * kset_register() has been called, call kset_unregister() and the
+ * structure will be dynamically freed when it is no longer being used.
+ *
+ * If the kset was not able to be created, NULL will be returned.
+ */
+static struct kset *kset_create(const char *name,
+ struct kset_uevent_ops *uevent_ops,
+ struct kobject *parent_kobj)
+{
+ struct kset *kset;
+
+ kset = kzalloc(sizeof(*kset), GFP_KERNEL);
+ if (!kset)
+ return NULL;
+ kobject_set_name(&kset->kobj, name);
+ kset->uevent_ops = uevent_ops;
+ kset->kobj.parent = parent_kobj;
+
+ /*
+ * The kobject of this kset will have a type of kset_type and belong to
+ * no kset itself. That way we can properly free it when it is
+ * finished being used.
+ */
+ kset->kobj.ktype = &kset_type;
+ kset->kobj.kset = NULL;
+
+ return kset;
+}
+
+/**
+ * kset_create_and_add - create a struct kset dynamically and add it to sysfs
+ *
+ * @name: the name for the kset
+ * @uevent_ops: a struct kset_uevent_ops for the kset
+ * @parent_kobj: the parent kobject of this kset, if any.
+ *
+ * This function creates a kset structure dynamically and registers it
+ * with sysfs. When you are finished with this structure, call
+ * kset_unregister() and the structure will be dynamically freed when it
+ * is no longer being used.
+ *
+ * If the kset was not able to be created, NULL will be returned.
+ */
+struct kset *kset_create_and_add(const char *name,
+ struct kset_uevent_ops *uevent_ops,
+ struct kobject *parent_kobj)
+{
+ struct kset *kset;
+ int error;
+
+ kset = kset_create(name, uevent_ops, parent_kobj);
+ if (!kset)
+ return NULL;
+ error = kset_register(kset);
+ if (error) {
+ kfree(kset);
+ return NULL;
+ }
+ return kset;
+}
+EXPORT_SYMBOL_GPL(kset_create_and_add);
+
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
--
1.5.3.8

2008-01-25 07:30:07

by Greg KH

[permalink] [raw]
Subject: [PATCH 045/196] kobject: add kobject_create_and_add function

This lets users create dynamic kobjects much easier.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 3 ++
lib/kobject.c | 81 ++++++++++++++++++++++++++++++++++++----------
2 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index f91aeb7..33e7a61 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -91,6 +91,9 @@ extern int __must_check kobject_init_and_add(struct kobject *kobj,

extern void kobject_del(struct kobject *);

+extern struct kobject * __must_check kobject_create_and_add(const char *name,
+ struct kobject *parent);
+
extern int __must_check kobject_rename(struct kobject *, const char *new_name);
extern int __must_check kobject_move(struct kobject *, struct kobject *);

diff --git a/lib/kobject.c b/lib/kobject.c
index 4fb27ba..98422a3 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -619,18 +619,69 @@ void kobject_put(struct kobject * kobj)
kref_put(&kobj->kref, kobject_release);
}

-
-static void dir_release(struct kobject *kobj)
+static void dynamic_kobj_release(struct kobject *kobj)
{
+ pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
kfree(kobj);
}

-static struct kobj_type dir_ktype = {
- .release = dir_release,
- .sysfs_ops = NULL,
- .default_attrs = NULL,
+static struct kobj_type dynamic_kobj_ktype = {
+ .release = dynamic_kobj_release,
};

+/*
+ * kobject_create - create a struct kobject dynamically
+ *
+ * This function creates a kobject structure dynamically and sets it up
+ * to be a "dynamic" kobject with a default release function set up.
+ *
+ * If the kobject was not able to be created, NULL will be returned.
+ */
+static struct kobject *kobject_create(void)
+{
+ struct kobject *kobj;
+
+ kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
+ if (!kobj)
+ return NULL;
+
+ kobject_init_ng(kobj, &dynamic_kobj_ktype);
+ return kobj;
+}
+
+/**
+ * kobject_create_and_add - create a struct kobject dynamically and register it with sysfs
+ *
+ * @name: the name for the kset
+ * @parent: the parent kobject of this kobject, if any.
+ *
+ * This function creates a kset structure dynamically and registers it
+ * with sysfs. When you are finished with this structure, call
+ * kobject_unregister() and the structure will be dynamically freed when
+ * it is no longer being used.
+ *
+ * If the kobject was not able to be created, NULL will be returned.
+ */
+struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
+{
+ struct kobject *kobj;
+ int retval;
+
+ kobj = kobject_create();
+ if (!kobj)
+ return NULL;
+
+ retval = kobject_add_ng(kobj, parent, "%s", name);
+ if (retval) {
+ printk(KERN_WARNING "%s: kobject_add error: %d\n",
+ __FUNCTION__, retval);
+ kobject_put(kobj);
+ kobj = NULL;
+ }
+ return kobj;
+}
+EXPORT_SYMBOL_GPL(kobject_create_and_add);
+
/**
* kobject_kset_add_dir - add sub directory of object.
* @kset: kset the directory is belongs to.
@@ -645,23 +696,17 @@ struct kobject *kobject_kset_add_dir(struct kset *kset,
struct kobject *k;
int ret;

- if (!parent)
- return NULL;
-
- k = kzalloc(sizeof(*k), GFP_KERNEL);
+ k = kobject_create();
if (!k)
return NULL;

k->kset = kset;
- k->parent = parent;
- k->ktype = &dir_ktype;
- kobject_set_name(k, name);
- ret = kobject_register(k);
+ ret = kobject_add_ng(k, parent, "%s", name);
if (ret < 0) {
- printk(KERN_WARNING "%s: kobject_register error: %d\n",
+ printk(KERN_WARNING "%s: kobject_add error: %d\n",
__func__, ret);
- kobject_del(k);
- return NULL;
+ kobject_put(k);
+ k = NULL;
}

return k;
@@ -676,7 +721,7 @@ struct kobject *kobject_kset_add_dir(struct kset *kset,
*/
struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
{
- return kobject_kset_add_dir(NULL, parent, name);
+ return kobject_create_and_add(name, parent);
}

/**
--
1.5.3.8

2008-01-25 07:30:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 046/196] kobject: get rid of kobject_add_dir

kobject_create_and_add is the same as kobject_add_dir, so drop
kobject_add_dir.


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 3 ++-
fs/partitions/check.c | 6 +++---
include/linux/kobject.h | 1 -
kernel/module.c | 6 +++---
lib/kobject.c | 12 ------------
5 files changed, 8 insertions(+), 20 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index c8f2ac0..992eba3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -562,7 +562,8 @@ static struct kobject *virtual_device_parent(struct device *dev)
static struct kobject *virtual_dir = NULL;

if (!virtual_dir)
- virtual_dir = kobject_add_dir(&devices_subsys.kobj, "virtual");
+ virtual_dir = kobject_create_and_add("virtual",
+ &devices_subsys.kobj);

return virtual_dir;
}
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 722e12e..69685bb 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -335,7 +335,7 @@ static inline void partition_sysfs_add_subdir(struct hd_struct *p)
struct kobject *k;

k = kobject_get(&p->kobj);
- p->holder_dir = kobject_add_dir(k, "holders");
+ p->holder_dir = kobject_create_and_add("holders", k);
kobject_put(k);
}

@@ -344,8 +344,8 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
struct kobject *k;

k = kobject_get(&disk->kobj);
- disk->holder_dir = kobject_add_dir(k, "holders");
- disk->slave_dir = kobject_add_dir(k, "slaves");
+ disk->holder_dir = kobject_create_and_add("holders", k);
+ disk->slave_dir = kobject_create_and_add("slaves", k);
kobject_put(k);
}

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 33e7a61..7b09136 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -105,7 +105,6 @@ extern void kobject_put(struct kobject *);

extern struct kobject *kobject_kset_add_dir(struct kset *kset,
struct kobject *, const char *);
-extern struct kobject *kobject_add_dir(struct kobject *, const char *);

extern char * kobject_get_path(struct kobject *, gfp_t);

diff --git a/kernel/module.c b/kernel/module.c
index 68df797..5514277 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1122,7 +1122,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
++loaded;
}

- notes_attrs->dir = kobject_add_dir(&mod->mkobj.kobj, "notes");
+ notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj);
if (!notes_attrs->dir)
goto out;

@@ -1243,7 +1243,7 @@ int mod_sysfs_setup(struct module *mod,
if (err)
goto out;

- mod->holders_dir = kobject_add_dir(&mod->mkobj.kobj, "holders");
+ mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
if (!mod->holders_dir) {
err = -ENOMEM;
goto out_unreg;
@@ -2521,7 +2521,7 @@ static void module_create_drivers_dir(struct module_kobject *mk)
if (!mk || mk->drivers_dir)
return;

- mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers");
+ mk->drivers_dir = kobject_create_and_add("drivers", &mk->kobj);
}

void module_add_driver(struct module *mod, struct device_driver *drv)
diff --git a/lib/kobject.c b/lib/kobject.c
index 98422a3..96b61d9 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -713,18 +713,6 @@ struct kobject *kobject_kset_add_dir(struct kset *kset,
}

/**
- * kobject_add_dir - add sub directory of object.
- * @parent: object in which a directory is created.
- * @name: directory name.
- *
- * Add a plain directory object as child of given object.
- */
-struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
-{
- return kobject_create_and_add(name, parent);
-}
-
-/**
* kset_init - initialize a kset for use
* @k: kset
*/
--
1.5.3.8

2008-01-25 07:30:59

by Greg KH

[permalink] [raw]
Subject: [PATCH 047/196] kobject: get rid of kobject_kset_add_dir

kobject_kset_add_dir is only called in one place so remove it and use
kobject_create() instead.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 16 ++++++++++++++--
include/linux/kobject.h | 4 +---
lib/kobject.c | 37 +++++--------------------------------
3 files changed, 20 insertions(+), 37 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 992eba3..7762ee8 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -571,6 +571,8 @@ static struct kobject *virtual_device_parent(struct device *dev)
static struct kobject * get_device_parent(struct device *dev,
struct device *parent)
{
+ int retval;
+
if (dev->class) {
struct kobject *kobj = NULL;
struct kobject *parent_kobj;
@@ -600,8 +602,18 @@ static struct kobject * get_device_parent(struct device *dev,
return kobj;

/* or create a new class-directory at the parent device */
- return kobject_kset_add_dir(&dev->class->class_dirs,
- parent_kobj, dev->class->name);
+ k = kobject_create();
+ if (!k)
+ return NULL;
+ k->kset = &dev->class->class_dirs;
+ retval = kobject_add_ng(k, parent_kobj, "%s", dev->class->name);
+ if (retval < 0) {
+ kobject_put(k);
+ return NULL;
+ }
+ /* Do not emit a uevent, as it's not needed for this
+ * "class glue" directory. */
+ return k;
}

if (parent)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 7b09136..718b488 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -91,6 +91,7 @@ extern int __must_check kobject_init_and_add(struct kobject *kobj,

extern void kobject_del(struct kobject *);

+extern struct kobject * __must_check kobject_create(void);
extern struct kobject * __must_check kobject_create_and_add(const char *name,
struct kobject *parent);

@@ -103,9 +104,6 @@ extern void kobject_unregister(struct kobject *);
extern struct kobject * kobject_get(struct kobject *);
extern void kobject_put(struct kobject *);

-extern struct kobject *kobject_kset_add_dir(struct kset *kset,
- struct kobject *, const char *);
-
extern char * kobject_get_path(struct kobject *, gfp_t);

struct kobj_type {
diff --git a/lib/kobject.c b/lib/kobject.c
index 96b61d9..67c3d38 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -629,15 +629,18 @@ static struct kobj_type dynamic_kobj_ktype = {
.release = dynamic_kobj_release,
};

-/*
+/**
* kobject_create - create a struct kobject dynamically
*
* This function creates a kobject structure dynamically and sets it up
* to be a "dynamic" kobject with a default release function set up.
*
* If the kobject was not able to be created, NULL will be returned.
+ * The kobject structure returned from here must be cleaned up with a
+ * call to kobject_put() and not kfree(), as kobject_init_ng() has
+ * already been called on this structure.
*/
-static struct kobject *kobject_create(void)
+struct kobject *kobject_create(void)
{
struct kobject *kobj;

@@ -683,36 +686,6 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
EXPORT_SYMBOL_GPL(kobject_create_and_add);

/**
- * kobject_kset_add_dir - add sub directory of object.
- * @kset: kset the directory is belongs to.
- * @parent: object in which a directory is created.
- * @name: directory name.
- *
- * Add a plain directory object as child of given object.
- */
-struct kobject *kobject_kset_add_dir(struct kset *kset,
- struct kobject *parent, const char *name)
-{
- struct kobject *k;
- int ret;
-
- k = kobject_create();
- if (!k)
- return NULL;
-
- k->kset = kset;
- ret = kobject_add_ng(k, parent, "%s", name);
- if (ret < 0) {
- printk(KERN_WARNING "%s: kobject_add error: %d\n",
- __func__, ret);
- kobject_put(k);
- k = NULL;
- }
-
- return k;
-}
-
-/**
* kset_init - initialize a kset for use
* @k: kset
*/
--
1.5.3.8

2008-01-25 07:31:27

by Greg KH

[permalink] [raw]
Subject: [PATCH 048/196] kobject: convert fuse to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Cc: Kay Sievers <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/fuse/inode.c | 26 ++++++++++++++------------
1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index f5e4182..9211806 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -744,9 +744,6 @@ static inline void unregister_fuseblk(void)
}
#endif

-static decl_subsys(fuse, NULL);
-static decl_subsys(connections, NULL);
-
static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo)
{
struct inode * inode = foo;
@@ -791,32 +788,37 @@ static void fuse_fs_cleanup(void)
kmem_cache_destroy(fuse_inode_cachep);
}

+static struct kobject *fuse_kobj;
+static struct kobject *connections_kobj;
+
static int fuse_sysfs_init(void)
{
int err;

- fuse_subsys.kobj.kset = &fs_subsys;
- err = subsystem_register(&fuse_subsys);
- if (err)
+ fuse_kobj = kobject_create_and_add("fuse", &fs_subsys.kobj);
+ if (!fuse_kobj) {
+ err = -ENOMEM;
goto out_err;
+ }

- connections_subsys.kobj.kset = &fuse_subsys;
- err = subsystem_register(&connections_subsys);
- if (err)
+ connections_kobj = kobject_create_and_add("connections", fuse_kobj);
+ if (!connections_kobj) {
+ err = -ENOMEM;
goto out_fuse_unregister;
+ }

return 0;

out_fuse_unregister:
- subsystem_unregister(&fuse_subsys);
+ kobject_unregister(fuse_kobj);
out_err:
return err;
}

static void fuse_sysfs_cleanup(void)
{
- subsystem_unregister(&connections_subsys);
- subsystem_unregister(&fuse_subsys);
+ kobject_unregister(connections_kobj);
+ kobject_unregister(fuse_kobj);
}

static int __init fuse_init(void)
--
1.5.3.8

2008-01-25 07:31:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 049/196] kobject: convert securityfs to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Cc: Kay Sievers <[email protected]>
Acked-by: Chris Wright <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
security/inode.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/security/inode.c b/security/inode.c
index 9e42f5f..dfc5978 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -315,20 +315,19 @@ void securityfs_remove(struct dentry *dentry)
}
EXPORT_SYMBOL_GPL(securityfs_remove);

-static decl_subsys(security, NULL);
+static struct kobject *security_kobj;

static int __init securityfs_init(void)
{
int retval;

- security_subsys.kobj.kset = &kernel_subsys;
- retval = subsystem_register(&security_subsys);
- if (retval)
- return retval;
+ security_kobj = kobject_create_and_add("security", &kernel_subsys.kobj);
+ if (!security_kobj)
+ return -EINVAL;

retval = register_filesystem(&fs_type);
if (retval)
- subsystem_unregister(&security_subsys);
+ kobject_unregister(security_kobj);
return retval;
}

--
1.5.3.8

2008-01-25 07:32:00

by Greg KH

[permalink] [raw]
Subject: [PATCH 050/196] kobject: convert debugfs to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/debugfs/inode.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index f7f1351..6672142 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -426,20 +426,19 @@ exit:
}
EXPORT_SYMBOL_GPL(debugfs_rename);

-static decl_subsys(debug, NULL);
+static struct kobject *debug_kobj;

static int __init debugfs_init(void)
{
int retval;

- debug_subsys.kobj.kset = &kernel_subsys;
- retval = subsystem_register(&debug_subsys);
- if (retval)
- return retval;
+ debug_kobj = kobject_create_and_add("debug", &kernel_subsys.kobj);
+ if (!debug_kobj)
+ return -EINVAL;

retval = register_filesystem(&debug_fs_type);
if (retval)
- subsystem_unregister(&debug_subsys);
+ kobject_unregister(debug_kobj);
return retval;
}

@@ -447,7 +446,7 @@ static void __exit debugfs_exit(void)
{
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
unregister_filesystem(&debug_fs_type);
- subsystem_unregister(&debug_subsys);
+ kobject_unregister(debug_kobj);
}

core_initcall(debugfs_init);
--
1.5.3.8

2008-01-25 07:32:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 051/196] kobject: convert configfs to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Joel Becker <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/configfs/mount.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 374ddbd..1330046 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -128,7 +128,7 @@ void configfs_release_fs(void)
}


-static decl_subsys(config, NULL);
+static struct kobject *config_kobj;

static int __init configfs_init(void)
{
@@ -140,9 +140,8 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep)
goto out;

- config_subsys.kobj.kset = &kernel_subsys;
- err = subsystem_register(&config_subsys);
- if (err) {
+ config_kobj = kobject_create_and_add("config", &kernel_subsys.kobj);
+ if (!config_kobj) {
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
goto out;
@@ -151,7 +150,7 @@ static int __init configfs_init(void)
err = register_filesystem(&configfs_fs_type);
if (err) {
printk(KERN_ERR "configfs: Unable to register filesystem!\n");
- subsystem_unregister(&config_subsys);
+ kobject_unregister(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
goto out;
@@ -160,7 +159,7 @@ static int __init configfs_init(void)
err = configfs_inode_init();
if (err) {
unregister_filesystem(&configfs_fs_type);
- subsystem_unregister(&config_subsys);
+ kobject_unregister(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
}
@@ -171,7 +170,7 @@ out:
static void __exit configfs_exit(void)
{
unregister_filesystem(&configfs_fs_type);
- subsystem_unregister(&config_subsys);
+ kobject_unregister(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
configfs_inode_exit();
--
1.5.3.8

2008-01-25 07:32:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 052/196] kset: convert ecryptfs to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Mike Halcrow <[email protected]>
Cc: Phillip Hellewell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index fe2f44f..4750d82 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,7 +734,7 @@ static int ecryptfs_init_kmem_caches(void)
return 0;
}

-static decl_subsys(ecryptfs, NULL);
+static struct kset *ecryptfs_kset;

static ssize_t version_show(struct kset *kset, char *buff)
{
@@ -798,18 +798,17 @@ static int do_sysfs_registration(void)
{
int rc;

- ecryptfs_subsys.kobj.kset = &fs_subsys;
- rc = subsystem_register(&ecryptfs_subsys);
- if (rc) {
- printk(KERN_ERR
- "Unable to register ecryptfs sysfs subsystem\n");
+ ecryptfs_kset = kset_create_and_add("ecryptfs", NULL, &fs_subsys.kobj);
+ if (!ecryptfs_kset) {
+ printk(KERN_ERR "Unable to create ecryptfs kset\n");
+ rc = -ENOMEM;
goto out;
}
- rc = sysfs_create_group(&ecryptfs_subsys.kobj, &attr_group);
+ rc = sysfs_create_group(&ecryptfs_kset->kobj, &attr_group);
if (rc) {
printk(KERN_ERR
"Unable to create ecryptfs version attributes\n");
- subsystem_unregister(&ecryptfs_subsys);
+ kset_unregister(ecryptfs_kset);
}
out:
return rc;
@@ -817,8 +816,8 @@ out:

static void do_sysfs_unregistration(void)
{
- sysfs_remove_group(&ecryptfs_subsys.kobj, &attr_group);
- subsystem_unregister(&ecryptfs_subsys);
+ sysfs_remove_group(&ecryptfs_kset->kobj, &attr_group);
+ kset_unregister(ecryptfs_kset);
}

static int __init ecryptfs_init(void)
--
1.5.3.8

2008-01-25 07:32:56

by Greg KH

[permalink] [raw]
Subject: [PATCH 053/196] kobject: convert main fs kobject to use kobject_create

This also renames fs_subsys to fs_kobj to catch all current users with a
build error instead of a build warning which can easily be missed.


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 2 +-
fs/fuse/inode.c | 2 +-
fs/gfs2/sys.c | 2 +-
fs/namespace.c | 11 +++++------
include/linux/fs.h | 2 +-
5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 4750d82..bdeac38 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -798,7 +798,7 @@ static int do_sysfs_registration(void)
{
int rc;

- ecryptfs_kset = kset_create_and_add("ecryptfs", NULL, &fs_subsys.kobj);
+ ecryptfs_kset = kset_create_and_add("ecryptfs", NULL, fs_kobj);
if (!ecryptfs_kset) {
printk(KERN_ERR "Unable to create ecryptfs kset\n");
rc = -ENOMEM;
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 9211806..e6e23a2 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -795,7 +795,7 @@ static int fuse_sysfs_init(void)
{
int err;

- fuse_kobj = kobject_create_and_add("fuse", &fs_subsys.kobj);
+ fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
if (!fuse_kobj) {
err = -ENOMEM;
goto out_err;
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index d7fa544..a0bdc4a 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -549,7 +549,7 @@ int gfs2_sys_init(void)
gfs2_sys_margs = NULL;
spin_lock_init(&gfs2_sys_margs_lock);
kobject_set_name(&gfs2_kset.kobj, "gfs2");
- gfs2_kset.kobj.kset = &fs_subsys;
+ gfs2_kset.kobj.parent = fs_kobj;
return kset_register(&gfs2_kset);
}

diff --git a/fs/namespace.c b/fs/namespace.c
index a4a3f70..61bf376 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -41,8 +41,8 @@ static struct kmem_cache *mnt_cache __read_mostly;
static struct rw_semaphore namespace_sem;

/* /sys/fs */
-decl_subsys(fs, NULL);
-EXPORT_SYMBOL_GPL(fs_subsys);
+struct kobject *fs_kobj;
+EXPORT_SYMBOL_GPL(fs_kobj);

static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
{
@@ -1861,10 +1861,9 @@ void __init mnt_init(void)
if (err)
printk(KERN_WARNING "%s: sysfs_init error: %d\n",
__FUNCTION__, err);
- err = subsystem_register(&fs_subsys);
- if (err)
- printk(KERN_WARNING "%s: subsystem_register error: %d\n",
- __FUNCTION__, err);
+ fs_kobj = kobject_create_and_add("fs", NULL);
+ if (!fs_kobj)
+ printk(KERN_WARNING "%s: kobj create error\n", __FUNCTION__);
init_rootfs();
init_mount_tree();
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index b3ec4a4..21398a5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1476,7 +1476,7 @@ extern void drop_collected_mounts(struct vfsmount *);
extern int vfs_statfs(struct dentry *, struct kstatfs *);

/* /sys/fs */
-extern struct kset fs_subsys;
+extern struct kobject *fs_kobj;

#define FLOCK_VERIFY_READ 1
#define FLOCK_VERIFY_WRITE 2
--
1.5.3.8

2008-01-25 07:33:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 054/196] kset: convert gfs2 to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Steven Whitehouse <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/gfs2/sys.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index a0bdc4a..44cfaae 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -221,7 +221,7 @@ static struct kobj_type gfs2_ktype = {
.sysfs_ops = &gfs2_attr_ops,
};

-static struct kset gfs2_kset;
+static struct kset *gfs2_kset;

/*
* display struct lm_lockstruct fields
@@ -493,7 +493,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
{
int error;

- sdp->sd_kobj.kset = &gfs2_kset;
+ sdp->sd_kobj.kset = gfs2_kset;
sdp->sd_kobj.ktype = &gfs2_ktype;

error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name);
@@ -548,14 +548,15 @@ int gfs2_sys_init(void)
{
gfs2_sys_margs = NULL;
spin_lock_init(&gfs2_sys_margs_lock);
- kobject_set_name(&gfs2_kset.kobj, "gfs2");
- gfs2_kset.kobj.parent = fs_kobj;
- return kset_register(&gfs2_kset);
+ gfs2_kset = kset_create_and_add("gfs2", NULL, fs_kobj);
+ if (!gfs2_kset)
+ return -ENOMEM;
+ return 0;
}

void gfs2_sys_uninit(void)
{
kfree(gfs2_sys_margs);
- kset_unregister(&gfs2_kset);
+ kset_unregister(gfs2_kset);
}

--
1.5.3.8

2008-01-25 07:33:41

by Greg KH

[permalink] [raw]
Subject: [PATCH 055/196] kset: convert gfs2 dlm to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Steven Whitehouse <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/gfs2/locking/dlm/sysfs.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index 93e66b2..0a86140 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -189,7 +189,7 @@ static struct kobj_type gdlm_ktype = {
.sysfs_ops = &gdlm_attr_ops,
};

-static struct kset gdlm_kset;
+static struct kset *gdlm_kset;

int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
{
@@ -201,7 +201,7 @@ int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
return error;
}

- ls->kobj.kset = &gdlm_kset;
+ ls->kobj.kset = gdlm_kset;
ls->kobj.ktype = &gdlm_ktype;
ls->kobj.parent = fskobj;

@@ -219,19 +219,17 @@ void gdlm_kobject_release(struct gdlm_ls *ls)

int gdlm_sysfs_init(void)
{
- int error;
-
- kobject_set_name(&gdlm_kset.kobj, "lock_dlm");
- gdlm_kset.kobj.kset = &kernel_subsys;
- error = kset_register(&gdlm_kset);
- if (error)
- printk("lock_dlm: cannot register kset %d\n", error);
-
- return error;
+ gdlm_kset = kset_create_and_add("lock_dlm", NULL,
+ &kernel_subsys.kobj);
+ if (!gdlm_kset) {
+ printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
+ return -ENOMEM;
+ }
+ return 0;
}

void gdlm_sysfs_exit(void)
{
- kset_unregister(&gdlm_kset);
+ kset_unregister(gdlm_kset);
}

--
1.5.3.8

2008-01-25 07:33:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 056/196] kset: convert dlm to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Steven Whitehouse <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/dlm/lockspace.c | 20 +++++++++-----------
1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 18e4a17..83a9c4d 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -166,7 +166,7 @@ static struct kobj_type dlm_ktype = {
.release = lockspace_kobj_release,
};

-static struct kset dlm_kset;
+static struct kset *dlm_kset;

static int kobject_setup(struct dlm_ls *ls)
{
@@ -180,7 +180,7 @@ static int kobject_setup(struct dlm_ls *ls)
if (error)
return error;

- ls->ls_kobj.kset = &dlm_kset;
+ ls->ls_kobj.kset = dlm_kset;
ls->ls_kobj.ktype = &dlm_ktype;
return 0;
}
@@ -218,24 +218,22 @@ static int do_uevent(struct dlm_ls *ls, int in)

int dlm_lockspace_init(void)
{
- int error;
-
ls_count = 0;
mutex_init(&ls_lock);
INIT_LIST_HEAD(&lslist);
spin_lock_init(&lslist_lock);

- kobject_set_name(&dlm_kset.kobj, "dlm");
- dlm_kset.kobj.kset = &kernel_subsys;
- error = kset_register(&dlm_kset);
- if (error)
- printk("dlm_lockspace_init: cannot register kset %d\n", error);
- return error;
+ dlm_kset = kset_create_and_add("dlm", NULL, &kernel_subsys.kobj);
+ if (!dlm_kset) {
+ printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
+ return -ENOMEM;
+ }
+ return 0;
}

void dlm_lockspace_exit(void)
{
- kset_unregister(&dlm_kset);
+ kset_unregister(dlm_kset);
}

static int dlm_scand(void *data)
--
1.5.3.8

2008-01-25 07:34:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 057/196] kset: convert pci hotplug to use kset_create_and_add

This also renames pci_hotplug_slots_subsys to pcis_hotplug_slots_kset
catch all current users with a build error instead of a build warning
which can easily be missed.

Cc: Kay Sievers <[email protected]>
Cc: Kristen Carlson Accardi <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pci/hotplug/acpiphp_ibm.c | 4 ++--
drivers/pci/hotplug/pci_hotplug_core.c | 23 +++++++++++------------
drivers/pci/hotplug/rpadlpar_sysfs.c | 2 +-
include/linux/pci_hotplug.h | 2 +-
4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
index 47d26b6..750ebd7 100644
--- a/drivers/pci/hotplug/acpiphp_ibm.c
+++ b/drivers/pci/hotplug/acpiphp_ibm.c
@@ -429,7 +429,7 @@ static int __init ibm_acpiphp_init(void)
int retval = 0;
acpi_status status;
struct acpi_device *device;
- struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj;
+ struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;

dbg("%s\n", __FUNCTION__);

@@ -476,7 +476,7 @@ init_return:
static void __exit ibm_acpiphp_exit(void)
{
acpi_status status;
- struct kobject *sysdir = &pci_hotplug_slots_subsys.kobj;
+ struct kobject *sysdir = &pci_hotplug_slots_kset->kobj;

dbg("%s\n", __FUNCTION__);

diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index ce1cff0..175e0c8 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -61,7 +61,7 @@ static int debug;

static LIST_HEAD(pci_hotplug_slot_list);

-struct kset pci_hotplug_slots_subsys;
+struct kset *pci_hotplug_slots_kset;

static ssize_t hotplug_slot_attr_show(struct kobject *kobj,
struct attribute *attr, char *buf)
@@ -96,8 +96,6 @@ static struct kobj_type hotplug_slot_ktype = {
.release = &hotplug_slot_release,
};

-decl_subsys_name(pci_hotplug_slots, slots, NULL);
-
/* these strings match up with the values in pci_bus_speed */
static char *pci_bus_speed_strings[] = {
"33 MHz PCI", /* 0x00 */
@@ -633,7 +631,7 @@ int pci_hp_register (struct hotplug_slot *slot)
}

kobject_set_name(&slot->kobj, "%s", slot->name);
- slot->kobj.kset = &pci_hotplug_slots_subsys;
+ slot->kobj.kset = pci_hotplug_slots_kset;
slot->kobj.ktype = &hotplug_slot_ktype;

/* this can fail if we have already registered a slot with the same name */
@@ -702,10 +700,11 @@ static int __init pci_hotplug_init (void)
{
int result;

- pci_hotplug_slots_subsys.kobj.kset = &pci_bus_type.subsys;
- result = subsystem_register(&pci_hotplug_slots_subsys);
- if (result) {
- err("Register subsys with error %d\n", result);
+ pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
+ &pci_bus_type.subsys.kobj);
+ if (!pci_hotplug_slots_kset) {
+ result = -ENOMEM;
+ err("Register subsys error\n");
goto exit;
}
result = cpci_hotplug_init(debug);
@@ -716,9 +715,9 @@ static int __init pci_hotplug_init (void)

info (DRIVER_DESC " version: " DRIVER_VERSION "\n");
goto exit;
-
+
err_subsys:
- subsystem_unregister(&pci_hotplug_slots_subsys);
+ kset_unregister(pci_hotplug_slots_kset);
exit:
return result;
}
@@ -726,7 +725,7 @@ exit:
static void __exit pci_hotplug_exit (void)
{
cpci_hotplug_exit();
- subsystem_unregister(&pci_hotplug_slots_subsys);
+ kset_unregister(pci_hotplug_slots_kset);
}

module_init(pci_hotplug_init);
@@ -738,7 +737,7 @@ MODULE_LICENSE("GPL");
module_param(debug, bool, 0644);
MODULE_PARM_DESC(debug, "Debugging mode enabled or not");

-EXPORT_SYMBOL_GPL(pci_hotplug_slots_subsys);
+EXPORT_SYMBOL_GPL(pci_hotplug_slots_kset);
EXPORT_SYMBOL_GPL(pci_hp_register);
EXPORT_SYMBOL_GPL(pci_hp_deregister);
EXPORT_SYMBOL_GPL(pci_hp_change_slot_info);
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index 7609093..5c3ddb6 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -130,7 +130,7 @@ struct kobj_type ktype_dlpar_io = {

struct kset dlpar_io_kset = {
.kobj = {.ktype = &ktype_dlpar_io,
- .parent = &pci_hotplug_slots_subsys.kobj},
+ .parent = &pci_hotplug_slots_kset->kobj},
};

int dlpar_sysfs_init(void)
diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
index ab4cb6e..8f67e8f 100644
--- a/include/linux/pci_hotplug.h
+++ b/include/linux/pci_hotplug.h
@@ -174,7 +174,7 @@ extern int pci_hp_register (struct hotplug_slot *slot);
extern int pci_hp_deregister (struct hotplug_slot *slot);
extern int __must_check pci_hp_change_slot_info (struct hotplug_slot *slot,
struct hotplug_slot_info *info);
-extern struct kset pci_hotplug_slots_subsys;
+extern struct kset *pci_hotplug_slots_kset;

/* PCI Setting Record (Type 0) */
struct hpp_type0 {
--
1.5.3.8

2008-01-25 07:34:44

by Greg KH

[permalink] [raw]
Subject: [PATCH 058/196] kset: remove decl_subsys_name

The last user of this macro (pci hotplug core) is now switched over to
using a dynamic kset, so this macro is no longer needed at all.

Cc: Kay Sievers <[email protected]>
Cc: Kristen Carlson Accardi <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 5 -----
1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 718b488..390ae14 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -193,11 +193,6 @@ struct kset _name##_subsys = { \
.kobj = { .k_name = __stringify(_name) }, \
.uevent_ops =_uevent_ops, \
}
-#define decl_subsys_name(_varname,_name,_uevent_ops) \
-struct kset _varname##_subsys = { \
- .kobj = { .k_name = __stringify(_name) }, \
- .uevent_ops =_uevent_ops, \
-}

/* The global /sys/kernel/ subsystem for people to chain off of */
extern struct kset kernel_subsys;
--
1.5.3.8

2008-01-25 07:35:02

by Greg KH

[permalink] [raw]
Subject: [PATCH 059/196] kset: convert kernel_subsys to use kset_create

Dynamically create the kset instead of declaring it statically. We also
rename kernel_subsys to kernel_kset to catch all users of this symbol
with a build error instead of an easy-to-ignore build warning.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/configfs/mount.c | 2 +-
fs/debugfs/inode.c | 2 +-
fs/dlm/lockspace.c | 2 +-
fs/gfs2/locking/dlm/sysfs.c | 3 +--
include/linux/kobject.h | 4 ++--
kernel/ksysfs.c | 42 ++++++++++++++++++++++++++++++------------
kernel/user.c | 4 ++--
security/inode.c | 2 +-
8 files changed, 39 insertions(+), 22 deletions(-)

diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 1330046..c4ee7f0 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -140,7 +140,7 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep)
goto out;

- config_kobj = kobject_create_and_add("config", &kernel_subsys.kobj);
+ config_kobj = kobject_create_and_add("config", &kernel_kset->kobj);
if (!config_kobj) {
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 6672142..5ce92c3 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -432,7 +432,7 @@ static int __init debugfs_init(void)
{
int retval;

- debug_kobj = kobject_create_and_add("debug", &kernel_subsys.kobj);
+ debug_kobj = kobject_create_and_add("debug", &kernel_kset->kobj);
if (!debug_kobj)
return -EINVAL;

diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 83a9c4d..0828beb 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -223,7 +223,7 @@ int dlm_lockspace_init(void)
INIT_LIST_HEAD(&lslist);
spin_lock_init(&lslist_lock);

- dlm_kset = kset_create_and_add("dlm", NULL, &kernel_subsys.kobj);
+ dlm_kset = kset_create_and_add("dlm", NULL, &kernel_kset->kobj);
if (!dlm_kset) {
printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
return -ENOMEM;
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index 0a86140..1a92b6f 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -219,8 +219,7 @@ void gdlm_kobject_release(struct gdlm_ls *ls)

int gdlm_sysfs_init(void)
{
- gdlm_kset = kset_create_and_add("lock_dlm", NULL,
- &kernel_subsys.kobj);
+ gdlm_kset = kset_create_and_add("lock_dlm", NULL, &kernel_kset->kobj);
if (!gdlm_kset) {
printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
return -ENOMEM;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 390ae14..bd741e8 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -194,8 +194,8 @@ struct kset _name##_subsys = { \
.uevent_ops =_uevent_ops, \
}

-/* The global /sys/kernel/ subsystem for people to chain off of */
-extern struct kset kernel_subsys;
+/* The global /sys/kernel/ kset for people to chain off of */
+extern struct kset *kernel_kset;
/* The global /sys/hypervisor/ subsystem */
extern struct kset hypervisor_subsys;

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 094e2bc..cf02d4b 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -94,8 +94,8 @@ static struct bin_attribute notes_attr = {
.read = &notes_read,
};

-decl_subsys(kernel, NULL);
-EXPORT_SYMBOL_GPL(kernel_subsys);
+struct kset *kernel_kset;
+EXPORT_SYMBOL_GPL(kernel_kset);

static struct attribute * kernel_attrs[] = {
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
@@ -116,24 +116,42 @@ static struct attribute_group kernel_attr_group = {

static int __init ksysfs_init(void)
{
- int error = subsystem_register(&kernel_subsys);
- if (!error)
- error = sysfs_create_group(&kernel_subsys.kobj,
- &kernel_attr_group);
+ int error;

- if (!error && notes_size > 0) {
+ kernel_kset = kset_create_and_add("kernel", NULL, NULL);
+ if (!kernel_kset) {
+ error = -ENOMEM;
+ goto exit;
+ }
+ error = sysfs_create_group(&kernel_kset->kobj, &kernel_attr_group);
+ if (error)
+ goto kset_exit;
+
+ if (notes_size > 0) {
notes_attr.size = notes_size;
- error = sysfs_create_bin_file(&kernel_subsys.kobj,
- &notes_attr);
+ error = sysfs_create_bin_file(&kernel_kset->kobj, &notes_attr);
+ if (error)
+ goto group_exit;
}

/*
* Create "/sys/kernel/uids" directory and corresponding root user's
* directory under it.
*/
- if (!error)
- error = uids_kobject_init();
-
+ error = uids_kobject_init();
+ if (error)
+ goto notes_exit;
+
+ return 0;
+
+notes_exit:
+ if (notes_size > 0)
+ sysfs_remove_bin_file(&kernel_kset->kobj, &notes_attr);
+group_exit:
+ sysfs_remove_group(&kernel_kset->kobj, &kernel_attr_group);
+kset_exit:
+ kset_unregister(kernel_kset);
+exit:
return error;
}

diff --git a/kernel/user.c b/kernel/user.c
index 8320a87..80f1116 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -198,8 +198,8 @@ int __init uids_kobject_init(void)
int error;

/* create under /sys/kernel dir */
- uids_kobject.parent = &kernel_subsys.kobj;
- uids_kobject.kset = &kernel_subsys;
+ uids_kobject.parent = &kernel_kset->kobj;
+ uids_kobject.kset = kernel_kset;
kobject_set_name(&uids_kobject, "uids");
kobject_init(&uids_kobject);

diff --git a/security/inode.c b/security/inode.c
index dfc5978..dbe040a 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -321,7 +321,7 @@ static int __init securityfs_init(void)
{
int retval;

- security_kobj = kobject_create_and_add("security", &kernel_subsys.kobj);
+ security_kobj = kobject_create_and_add("security", &kernel_kset->kobj);
if (!security_kobj)
return -EINVAL;

--
1.5.3.8

2008-01-25 07:35:36

by Greg KH

[permalink] [raw]
Subject: [PATCH 060/196] kset: convert drivers/base/bus.c to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6309560..e3b1010 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -166,7 +166,7 @@ static struct kset_uevent_ops bus_uevent_ops = {
.filter = bus_uevent_filter,
};

-static decl_subsys(bus, &bus_uevent_ops);
+static struct kset *bus_kset;


#ifdef CONFIG_HOTPLUG
@@ -767,7 +767,7 @@ EXPORT_SYMBOL_GPL(device_reprobe);
#if 0
struct bus_type * find_bus(char * name)
{
- struct kobject * k = kset_find_obj(&bus_subsys.kset, name);
+ struct kobject * k = kset_find_obj(bus_kset, name);
return k ? to_bus(k) : NULL;
}
#endif /* 0 */
@@ -851,7 +851,7 @@ int bus_register(struct bus_type * bus)
if (retval)
goto out;

- bus->subsys.kobj.kset = &bus_subsys;
+ bus->subsys.kobj.kset = bus_kset;
bus->subsys.kobj.ktype = &bus_ktype;

retval = subsystem_register(&bus->subsys);
@@ -935,7 +935,10 @@ EXPORT_SYMBOL_GPL(bus_unregister_notifier);

int __init buses_init(void)
{
- return subsystem_register(&bus_subsys);
+ bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL);
+ if (!bus_kset)
+ return -ENOMEM;
+ return 0;
}


--
1.5.3.8

2008-01-25 07:35:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 061/196] kset: convert drivers/base/class.c to use kset_create

Dynamically create the kset instead of declaring it statically.

The class_obj subsystem is not yet converted as it is more complex and
should be going away soon with the removal of class_device from the
kernel tree.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/class.c | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8ad9892..d8a92c6 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -71,7 +71,7 @@ static struct kobj_type class_ktype = {
};

/* Hotplug events for classes go to the class_obj subsys */
-static decl_subsys(class, NULL);
+static struct kset *class_kset;


int class_create_file(struct class * cls, const struct class_attribute * attr)
@@ -149,7 +149,7 @@ int class_register(struct class * cls)
if (error)
return error;

- cls->subsys.kobj.kset = &class_subsys;
+ cls->subsys.kobj.kset = class_kset;
cls->subsys.kobj.ktype = &class_ktype;

error = subsystem_register(&cls->subsys);
@@ -855,11 +855,9 @@ void class_interface_unregister(struct class_interface *class_intf)

int __init classes_init(void)
{
- int retval;
-
- retval = subsystem_register(&class_subsys);
- if (retval)
- return retval;
+ class_kset = kset_create_and_add("class", NULL, NULL);
+ if (!class_kset)
+ return -ENOMEM;

/* ick, this is ugly, the things we go through to keep from showing up
* in sysfs... */
--
1.5.3.8

2008-01-25 07:36:25

by Greg KH

[permalink] [raw]
Subject: [PATCH 062/196] kset: convert drivers/base/firmware.c to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/firmware.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 336be04..6a4e494 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -15,11 +15,11 @@

#include "base.h"

-static decl_subsys(firmware, NULL);
+static struct kset *firmware_kset;

int firmware_register(struct kset *s)
{
- s->kobj.kset = &firmware_subsys;
+ s->kobj.kset = firmware_kset;
s->kobj.ktype = NULL;
return subsystem_register(s);
}
@@ -31,7 +31,10 @@ void firmware_unregister(struct kset *s)

int __init firmware_init(void)
{
- return subsystem_register(&firmware_subsys);
+ firmware_kset = kset_create_and_add("firmware", NULL, NULL);
+ if (!firmware_kset)
+ return -ENOMEM;
+ return 0;
}

EXPORT_SYMBOL_GPL(firmware_register);
--
1.5.3.8

2008-01-25 07:36:43

by Greg KH

[permalink] [raw]
Subject: [PATCH 063/196] kset: convert /sys/devices to use kset_create

Dynamically create the kset instead of declaring it statically. We also
rename devices_subsys to devices_kset to catch all users of the
variable.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 2 +-
drivers/base/core.c | 16 ++++++++--------
drivers/base/power/shutdown.c | 2 +-
drivers/base/sys.c | 4 +---
4 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 10b2fb6..7e309a4 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -44,4 +44,4 @@ extern char *make_class_name(const char *name, struct kobject *kobj);

extern int devres_release_all(struct device *dev);

-extern struct kset devices_subsys;
+extern struct kset *devices_kset;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7762ee8..d2de2d5 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -401,11 +401,8 @@ static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
static struct device_attribute devt_attr =
__ATTR(dev, S_IRUGO, show_dev, NULL);

-/*
- * devices_subsys - structure to be registered with kobject core.
- */
-
-decl_subsys(devices, &device_uevent_ops);
+/* kset to create /sys/devices/ */
+struct kset *devices_kset;


/**
@@ -525,7 +522,7 @@ static void klist_children_put(struct klist_node *n)

void device_initialize(struct device *dev)
{
- dev->kobj.kset = &devices_subsys;
+ dev->kobj.kset = devices_kset;
dev->kobj.ktype = &device_ktype;
kobject_init(&dev->kobj);
klist_init(&dev->klist_children, klist_children_get,
@@ -563,7 +560,7 @@ static struct kobject *virtual_device_parent(struct device *dev)

if (!virtual_dir)
virtual_dir = kobject_create_and_add("virtual",
- &devices_subsys.kobj);
+ &devices_kset->kobj);

return virtual_dir;
}
@@ -1097,7 +1094,10 @@ struct device * device_find_child(struct device *parent, void *data,

int __init devices_init(void)
{
- return subsystem_register(&devices_subsys);
+ devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
+ if (!devices_kset)
+ return -ENOMEM;
+ return 0;
}

EXPORT_SYMBOL_GPL(device_for_each_child);
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index 56e8eaa..f51cbc1 100644
--- a/drivers/base/power/shutdown.c
+++ b/drivers/base/power/shutdown.c
@@ -34,7 +34,7 @@ void device_shutdown(void)
{
struct device * dev, *devn;

- list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.list,
+ list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
kobj.entry) {
if (dev->bus && dev->bus->shutdown) {
dev_dbg(dev, "shutdown\n");
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 7cf19fc..7693c95 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -25,8 +25,6 @@

#include "base.h"

-extern struct kset devices_subsys;
-
#define to_sysdev(k) container_of(k, struct sys_device, kobj)
#define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr)

@@ -459,7 +457,7 @@ int sysdev_resume(void)

int __init system_bus_init(void)
{
- system_subsys.kobj.parent = &devices_subsys.kobj;
+ system_subsys.kobj.parent = &devices_kset->kobj;
return subsystem_register(&system_subsys);
}

--
1.5.3.8

2008-01-25 07:37:07

by Greg KH

[permalink] [raw]
Subject: [PATCH 064/196] kobject: convert /sys/hypervisor to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

We also rename hypervisor_subsys to hypervisor_kset to catch all users
of the variable.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/s390/hypfs/inode.c | 2 +-
drivers/base/hypervisor.c | 12 ++++++++----
include/linux/kobject.h | 4 ++--
3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index c022ccc..b0ad479 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -506,7 +506,7 @@ static int __init hypfs_init(void)
goto fail_diag;
}
}
- s390_subsys.kobj.kset = &hypervisor_subsys;
+ s390_subsys.kobj.parent = hypervisor_kobj;
rc = subsystem_register(&s390_subsys);
if (rc)
goto fail_sysfs;
diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c
index 14e75e9..6428cba 100644
--- a/drivers/base/hypervisor.c
+++ b/drivers/base/hypervisor.c
@@ -2,19 +2,23 @@
* hypervisor.c - /sys/hypervisor subsystem.
*
* Copyright (C) IBM Corp. 2006
+ * Copyright (C) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (C) 2007 Novell Inc.
*
* This file is released under the GPLv2
*/

#include <linux/kobject.h>
#include <linux/device.h>
-
#include "base.h"

-decl_subsys(hypervisor, NULL);
-EXPORT_SYMBOL_GPL(hypervisor_subsys);
+struct kobject *hypervisor_kobj;
+EXPORT_SYMBOL_GPL(hypervisor_kobj);

int __init hypervisor_init(void)
{
- return subsystem_register(&hypervisor_subsys);
+ hypervisor_kobj = kobject_create_and_add("hypervisor", NULL);
+ if (!hypervisor_kobj)
+ return -ENOMEM;
+ return 0;
}
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bd741e8..f2483f6 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -196,8 +196,8 @@ struct kset _name##_subsys = { \

/* The global /sys/kernel/ kset for people to chain off of */
extern struct kset *kernel_kset;
-/* The global /sys/hypervisor/ subsystem */
-extern struct kset hypervisor_subsys;
+/* The global /sys/hypervisor/ kobject for people to chain off of */
+extern struct kobject *hypervisor_kobj;

extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);
--
1.5.3.8

2008-01-25 07:37:48

by Greg KH

[permalink] [raw]
Subject: [PATCH 065/196] kobject: convert s390 hypervisor to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Thanks to Cornelia for the build fix.

Cc: Kay Sievers <[email protected]>
Cc: Michael Holzheu <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/s390/hypfs/inode.c | 13 +++++++------
1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index b0ad479..631a610 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -490,7 +490,7 @@ static struct super_operations hypfs_s_ops = {
.show_options = hypfs_show_options,
};

-static decl_subsys(s390, NULL);
+static struct kobject *s390_kobj;

static int __init hypfs_init(void)
{
@@ -506,17 +506,18 @@ static int __init hypfs_init(void)
goto fail_diag;
}
}
- s390_subsys.kobj.parent = hypervisor_kobj;
- rc = subsystem_register(&s390_subsys);
- if (rc)
+ s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
+ if (!s390_kobj) {
+ rc = -ENOMEM;;
goto fail_sysfs;
+ }
rc = register_filesystem(&hypfs_type);
if (rc)
goto fail_filesystem;
return 0;

fail_filesystem:
- subsystem_unregister(&s390_subsys);
+ kobject_unregister(s390_kobj);
fail_sysfs:
if (!MACHINE_IS_VM)
hypfs_diag_exit();
@@ -530,7 +531,7 @@ static void __exit hypfs_exit(void)
if (!MACHINE_IS_VM)
hypfs_diag_exit();
unregister_filesystem(&hypfs_type);
- subsystem_unregister(&s390_subsys);
+ kobject_unregister(s390_kobj);
}

module_init(hypfs_init)
--
1.5.3.8

2008-01-25 07:38:15

by Greg KH

[permalink] [raw]
Subject: [PATCH 066/196] kset: convert /sys/devices/system to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/sys.c | 27 +++++++++++----------------
1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 7693c95..29eadc6 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -126,19 +126,16 @@ void sysdev_class_remove_file(struct sysdev_class *c,
}
EXPORT_SYMBOL_GPL(sysdev_class_remove_file);

-/*
- * declare system_subsys
- */
-static decl_subsys(system, NULL);
+static struct kset *system_kset;

int sysdev_class_register(struct sysdev_class * cls)
{
pr_debug("Registering sysdev class '%s'\n",
kobject_name(&cls->kset.kobj));
INIT_LIST_HEAD(&cls->drivers);
- cls->kset.kobj.parent = &system_subsys.kobj;
+ cls->kset.kobj.parent = &system_kset->kobj;
cls->kset.kobj.ktype = &ktype_sysdev_class;
- cls->kset.kobj.kset = &system_subsys;
+ cls->kset.kobj.kset = system_kset;
return kset_register(&cls->kset);
}

@@ -297,8 +294,7 @@ void sysdev_shutdown(void)
pr_debug("Shutting Down System Devices\n");

mutex_lock(&sysdev_drivers_lock);
- list_for_each_entry_reverse(cls, &system_subsys.list,
- kset.kobj.entry) {
+ list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
struct sys_device * sysdev;

pr_debug("Shutting down type '%s':\n",
@@ -360,9 +356,7 @@ int sysdev_suspend(pm_message_t state)

pr_debug("Suspending System Devices\n");

- list_for_each_entry_reverse(cls, &system_subsys.list,
- kset.kobj.entry) {
-
+ list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
pr_debug("Suspending type '%s':\n",
kobject_name(&cls->kset.kobj));

@@ -413,8 +407,7 @@ aux_driver:
}

/* resume other classes */
- list_for_each_entry_continue(cls, &system_subsys.list,
- kset.kobj.entry) {
+ list_for_each_entry_continue(cls, &system_kset->list, kset.kobj.entry) {
list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) {
pr_debug(" %s\n", kobject_name(&err_dev->kobj));
__sysdev_resume(err_dev);
@@ -439,7 +432,7 @@ int sysdev_resume(void)

pr_debug("Resuming System Devices\n");

- list_for_each_entry(cls, &system_subsys.list, kset.kobj.entry) {
+ list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) {
struct sys_device * sysdev;

pr_debug("Resuming type '%s':\n",
@@ -457,8 +450,10 @@ int sysdev_resume(void)

int __init system_bus_init(void)
{
- system_subsys.kobj.parent = &devices_kset->kobj;
- return subsystem_register(&system_subsys);
+ system_kset = kset_create_and_add("system", NULL, &devices_kset->kobj);
+ if (!system_kset)
+ return -ENOMEM;
+ return 0;
}

EXPORT_SYMBOL_GPL(sysdev_register);
--
1.5.3.8

2008-01-25 07:38:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 067/196] kset: convert slub to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Christoph Lameter <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
mm/slub.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 40bdf41..886131c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3962,7 +3962,7 @@ static struct kset_uevent_ops slab_uevent_ops = {
.filter = uevent_filter,
};

-static decl_subsys(slab, &slab_uevent_ops);
+static struct kset *slab_kset;

#define ID_STR_LENGTH 64

@@ -4015,7 +4015,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
* This is typically the case for debug situations. In that
* case we can catch duplicate names easily.
*/
- sysfs_remove_link(&slab_subsys.kobj, s->name);
+ sysfs_remove_link(&slab_kset->kobj, s->name);
name = s->name;
} else {
/*
@@ -4026,7 +4026,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
}

kobject_set_name(&s->kobj, name);
- s->kobj.kset = &slab_subsys;
+ s->kobj.kset = slab_kset;
s->kobj.ktype = &slab_ktype;
kobject_init(&s->kobj);
err = kobject_add(&s->kobj);
@@ -4071,9 +4071,8 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
/*
* If we have a leftover link then remove it.
*/
- sysfs_remove_link(&slab_subsys.kobj, name);
- return sysfs_create_link(&slab_subsys.kobj,
- &s->kobj, name);
+ sysfs_remove_link(&slab_kset->kobj, name);
+ return sysfs_create_link(&slab_kset->kobj, &s->kobj, name);
}

al = kmalloc(sizeof(struct saved_alias), GFP_KERNEL);
@@ -4092,8 +4091,8 @@ static int __init slab_sysfs_init(void)
struct kmem_cache *s;
int err;

- err = subsystem_register(&slab_subsys);
- if (err) {
+ slab_kset = kset_create_and_add("slab", &slab_uevent_ops, NULL);
+ if (!slab_kset) {
printk(KERN_ERR "Cannot register slab subsystem.\n");
return -ENOSYS;
}
--
1.5.3.8

2008-01-25 07:39:10

by Greg KH

[permalink] [raw]
Subject: [PATCH 068/196] kset: move /sys/slab to /sys/kernel/slab

/sys/kernel is where these things should go.
Also updated the documentation and tool that used this directory.

Cc: Kay Sievers <[email protected]>
Acked-by: Christoph Lameter <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/vm/slabinfo.c | 2 +-
Documentation/vm/slub.txt | 2 +-
mm/slub.c | 3 ++-
3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Documentation/vm/slabinfo.c b/Documentation/vm/slabinfo.c
index 7047696..488c1f3 100644
--- a/Documentation/vm/slabinfo.c
+++ b/Documentation/vm/slabinfo.c
@@ -1021,7 +1021,7 @@ void read_slab_dir(void)
char *t;
int count;

- if (chdir("/sys/slab"))
+ if (chdir("/sys/kernel/slab"))
fatal("SYSFS support for SLUB not active\n");

dir = opendir(".");
diff --git a/Documentation/vm/slub.txt b/Documentation/vm/slub.txt
index d17f324..dcf8bcf 100644
--- a/Documentation/vm/slub.txt
+++ b/Documentation/vm/slub.txt
@@ -63,7 +63,7 @@ In case you forgot to enable debugging on the kernel command line: It is
possible to enable debugging manually when the kernel is up. Look at the
contents of:

-/sys/slab/<slab name>/
+/sys/kernel/slab/<slab name>/

Look at the writable files. Writing 1 to them will enable the
corresponding debug option. All options can be set on a slab that does
diff --git a/mm/slub.c b/mm/slub.c
index 886131c..b6c7946 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4091,7 +4091,8 @@ static int __init slab_sysfs_init(void)
struct kmem_cache *s;
int err;

- slab_kset = kset_create_and_add("slab", &slab_uevent_ops, NULL);
+ slab_kset = kset_create_and_add("slab", &slab_uevent_ops,
+ &kernel_kset->kobj);
if (!slab_kset) {
printk(KERN_ERR "Cannot register slab subsystem.\n");
return -ENOSYS;
--
1.5.3.8

2008-01-25 07:39:36

by Greg KH

[permalink] [raw]
Subject: [PATCH 069/196] kset: convert /sys/module to use kset_create

Dynamically create the kset instead of declaring it statically. We also
rename module_subsys to module_kset to catch all users of the variable.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/module.h | 4 +++-
kernel/module.c | 7 +++----
kernel/params.c | 29 +++++++++--------------------
3 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/include/linux/module.h b/include/linux/module.h
index 2cbc0b8..fbe930b 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -574,7 +574,9 @@ struct device_driver;
#ifdef CONFIG_SYSFS
struct module;

-extern struct kset module_subsys;
+extern struct kset *module_kset;
+extern struct kobj_type module_ktype;
+extern int module_sysfs_initialized;

int mod_sysfs_init(struct module *mod);
int mod_sysfs_setup(struct module *mod,
diff --git a/kernel/module.c b/kernel/module.c
index 5514277..d03fcd9 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -47,8 +47,6 @@
#include <asm/cacheflush.h>
#include <linux/license.h>

-extern int module_sysfs_initialized;
-
#if 0
#define DEBUGP printk
#else
@@ -1223,7 +1221,8 @@ int mod_sysfs_init(struct module *mod)
err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name);
if (err)
goto out;
- mod->mkobj.kobj.kset = &module_subsys;
+ mod->mkobj.kobj.kset = module_kset;
+ mod->mkobj.kobj.ktype = &module_ktype;
mod->mkobj.mod = mod;

kobject_init(&mod->mkobj.kobj);
@@ -2539,7 +2538,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
struct kobject *mkobj;

/* Lookup built-in module entry in /sys/modules */
- mkobj = kset_find_obj(&module_subsys, drv->mod_name);
+ mkobj = kset_find_obj(module_kset, drv->mod_name);
if (mkobj) {
mk = container_of(mkobj, struct module_kobject, kobj);
/* remember our module structure */
diff --git a/kernel/params.c b/kernel/params.c
index 9f05182..97e0923 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -30,8 +30,6 @@
#define DEBUGP(fmt, a...)
#endif

-static struct kobj_type module_ktype;
-
static inline char dash2underscore(char c)
{
if (c == '-')
@@ -562,7 +560,7 @@ static void __init kernel_param_sysfs_setup(const char *name,
BUG_ON(!mk);

mk->mod = THIS_MODULE;
- mk->kobj.kset = &module_subsys;
+ mk->kobj.kset = module_kset;
mk->kobj.ktype = &module_ktype;
kobject_set_name(&mk->kobj, name);
kobject_init(&mk->kobj);
@@ -695,7 +693,7 @@ static struct kset_uevent_ops module_uevent_ops = {
.filter = uevent_filter,
};

-decl_subsys(module, &module_uevent_ops);
+struct kset *module_kset;
int module_sysfs_initialized;

static void module_release(struct kobject *kobj)
@@ -707,7 +705,7 @@ static void module_release(struct kobject *kobj)
*/
}

-static struct kobj_type module_ktype = {
+struct kobj_type module_ktype = {
.sysfs_ops = &module_sysfs_ops,
.release = module_release,
};
@@ -717,13 +715,11 @@ static struct kobj_type module_ktype = {
*/
static int __init param_sysfs_init(void)
{
- int ret;
-
- ret = subsystem_register(&module_subsys);
- if (ret < 0) {
- printk(KERN_WARNING "%s (%d): subsystem_register error: %d\n",
- __FILE__, __LINE__, ret);
- return ret;
+ module_kset = kset_create_and_add("module", &module_uevent_ops, NULL);
+ if (!module_kset) {
+ printk(KERN_WARNING "%s (%d): error creating kset\n",
+ __FILE__, __LINE__);
+ return -ENOMEM;
}
module_sysfs_initialized = 1;

@@ -733,14 +729,7 @@ static int __init param_sysfs_init(void)
}
subsys_initcall(param_sysfs_init);

-#else
-#if 0
-static struct sysfs_ops module_sysfs_ops = {
- .show = NULL,
- .store = NULL,
-};
-#endif
-#endif
+#endif /* CONFIG_SYSFS */

EXPORT_SYMBOL(param_set_byte);
EXPORT_SYMBOL(param_get_byte);
--
1.5.3.8

2008-01-25 07:39:53

by Greg KH

[permalink] [raw]
Subject: [PATCH 070/196] kset: convert /sys/power to use kset_create

Dynamically create the kset instead of declaring it statically. We also
rename power_subsys to power_kset to catch all users of the variable and
we properly export it so that people don't have to guess that it really
is present in the system.

The pseries code is wierd, why is it createing /sys/power if CONFIG_PM
is disabled? Oh well, stupid big boxes ignoring config options...

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/arm/mach-omap1/pm.c | 3 +--
arch/powerpc/platforms/pseries/power.c | 14 ++++++--------
include/linux/kobject.h | 2 ++
kernel/power/disk.c | 2 +-
kernel/power/main.c | 11 +++++------
kernel/power/power.h | 2 --
6 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 3bf01e2..402113c 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -97,7 +97,6 @@ static struct subsys_attribute sleep_while_idle_attr = {
.store = omap_pm_sleep_while_idle_store,
};

-extern struct kset power_subsys;
static void (*omap_sram_idle)(void) = NULL;
static void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL;

@@ -726,7 +725,7 @@ static int __init omap_pm_init(void)
omap_pm_init_proc();
#endif

- error = subsys_create_file(&power_subsys, &sleep_while_idle_attr);
+ error = subsys_create_file(power_kset, &sleep_while_idle_attr);
if (error)
printk(KERN_ERR "subsys_create_file failed: %d\n", error);

diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index 08d7a50..c36febe 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -57,7 +57,7 @@ static struct subsys_attribute auto_poweron_attr = {
};

#ifndef CONFIG_PM
-decl_subsys(power, NULL);
+struct kset *power_kset;

static struct attribute *g[] = {
&auto_poweron_attr.attr,
@@ -70,18 +70,16 @@ static struct attribute_group attr_group = {

static int __init pm_init(void)
{
- int error = subsystem_register(&power_subsys);
- if (!error)
- error = sysfs_create_group(&power_subsys.kobj, &attr_group);
- return error;
+ power_kset = kset_create_and_add("power", NULL, NULL);
+ if (!power_kset)
+ return -ENOMEM;
+ return sysfs_create_group(&power_kset->kobj, &attr_group);
}
core_initcall(pm_init);
#else
-extern struct kset power_subsys;
-
static int __init apo_pm_init(void)
{
- return (subsys_create_file(&power_subsys, &auto_poweron_attr));
+ return (subsys_create_file(power_kset, &auto_poweron_attr));
}
__initcall(apo_pm_init);
#endif
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index f2483f6..a6dd669 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -198,6 +198,8 @@ struct kset _name##_subsys = { \
extern struct kset *kernel_kset;
/* The global /sys/hypervisor/ kobject for people to chain off of */
extern struct kobject *hypervisor_kobj;
+/* The global /sys/power/ kset for people to chain off of */
+extern struct kset *power_kset;

extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 05b6479..c3f0e61 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -708,7 +708,7 @@ static struct attribute_group attr_group = {

static int __init pm_disk_init(void)
{
- return sysfs_create_group(&power_subsys.kobj, &attr_group);
+ return sysfs_create_group(&power_kset->kobj, &attr_group);
}

core_initcall(pm_disk_init);
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 1ef31c9..dce2d76 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -276,8 +276,7 @@ EXPORT_SYMBOL(pm_suspend);

#endif /* CONFIG_SUSPEND */

-decl_subsys(power, NULL);
-
+struct kset *power_kset;

/**
* state - control system power state.
@@ -386,10 +385,10 @@ static struct attribute_group attr_group = {

static int __init pm_init(void)
{
- int error = subsystem_register(&power_subsys);
- if (!error)
- error = sysfs_create_group(&power_subsys.kobj,&attr_group);
- return error;
+ power_kset = kset_create_and_add("power", NULL, NULL);
+ if (!power_kset)
+ return -ENOMEM;
+ return sysfs_create_group(&power_kset->kobj, &attr_group);
}

core_initcall(pm_init);
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 195dc46..1083e6b 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -63,8 +63,6 @@ static struct subsys_attribute _name##_attr = { \
.store = _name##_store, \
}

-extern struct kset power_subsys;
-
/* Preferred image size in bytes (default 500 MB) */
extern unsigned long image_size;
extern int in_suspend;
--
1.5.3.8

2008-01-25 07:40:20

by Greg KH

[permalink] [raw]
Subject: [PATCH 071/196] kset: convert struct bus_device->devices to use kset_create

Dynamically create the kset instead of declaring it statically.

Having 3 static kobjects in one structure is not only foolish, but ripe
for nasty race conditions if handled improperly. We also rename the
field to catch any potential users of it (not that there should be
outside of the driver core...)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 19 ++++++++++---------
include/linux/device.h | 2 +-
2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index e3b1010..b23eeb2 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -449,7 +449,7 @@ int bus_add_device(struct device * dev)
error = device_add_attrs(bus, dev);
if (error)
goto out_put;
- error = sysfs_create_link(&bus->devices.kobj,
+ error = sysfs_create_link(&bus->devices_kset->kobj,
&dev->kobj, dev->bus_id);
if (error)
goto out_id;
@@ -466,7 +466,7 @@ int bus_add_device(struct device * dev)
out_deprecated:
sysfs_remove_link(&dev->kobj, "subsystem");
out_subsys:
- sysfs_remove_link(&bus->devices.kobj, dev->bus_id);
+ sysfs_remove_link(&bus->devices_kset->kobj, dev->bus_id);
out_id:
device_remove_attrs(bus, dev);
out_put:
@@ -512,7 +512,7 @@ void bus_remove_device(struct device * dev)
if (dev->bus) {
sysfs_remove_link(&dev->kobj, "subsystem");
remove_deprecated_bus_links(dev);
- sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id);
+ sysfs_remove_link(&dev->bus->devices_kset->kobj, dev->bus_id);
device_remove_attrs(dev->bus, dev);
if (dev->is_registered) {
dev->is_registered = 0;
@@ -862,11 +862,12 @@ int bus_register(struct bus_type * bus)
if (retval)
goto bus_uevent_fail;

- kobject_set_name(&bus->devices.kobj, "devices");
- bus->devices.kobj.parent = &bus->subsys.kobj;
- retval = kset_register(&bus->devices);
- if (retval)
+ bus->devices_kset = kset_create_and_add("devices", NULL,
+ &bus->subsys.kobj);
+ if (!bus->devices_kset) {
+ retval = -ENOMEM;
goto bus_devices_fail;
+ }

kobject_set_name(&bus->drivers.kobj, "drivers");
bus->drivers.kobj.parent = &bus->subsys.kobj;
@@ -894,7 +895,7 @@ bus_attrs_fail:
bus_probe_files_fail:
kset_unregister(&bus->drivers);
bus_drivers_fail:
- kset_unregister(&bus->devices);
+ kset_unregister(bus->devices_kset);
bus_devices_fail:
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
@@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus)
bus_remove_attrs(bus);
remove_probe_files(bus);
kset_unregister(&bus->drivers);
- kset_unregister(&bus->devices);
+ kset_unregister(bus->devices_kset);
bus_remove_file(bus, &bus_attr_uevent);
subsystem_unregister(&bus->subsys);
}
diff --git a/include/linux/device.h b/include/linux/device.h
index dbbbe89..82c2777 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -55,7 +55,7 @@ struct bus_type {

struct kset subsys;
struct kset drivers;
- struct kset devices;
+ struct kset *devices_kset;
struct klist klist_devices;
struct klist klist_drivers;

--
1.5.3.8

2008-01-25 07:40:41

by Greg KH

[permalink] [raw]
Subject: [PATCH 072/196] kset: convert struct bus_device->drivers to use kset_create

Dynamically create the kset instead of declaring it statically.

Having 3 static kobjects in one structure is not only foolish, but ripe
for nasty race conditions if handled improperly. We also rename the
field to catch any potential users of it (not that there should be
outside of the driver core...)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 15 ++++++++-------
drivers/base/driver.c | 2 +-
include/linux/device.h | 2 +-
3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b23eeb2..6796d3e 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -638,7 +638,7 @@ int bus_add_driver(struct device_driver *drv)
error = kobject_set_name(&drv->kobj, "%s", drv->name);
if (error)
goto out_put_bus;
- drv->kobj.kset = &bus->drivers;
+ drv->kobj.kset = bus->drivers_kset;
drv->kobj.ktype = &driver_ktype;
error = kobject_register(&drv->kobj);
if (error)
@@ -869,11 +869,12 @@ int bus_register(struct bus_type * bus)
goto bus_devices_fail;
}

- kobject_set_name(&bus->drivers.kobj, "drivers");
- bus->drivers.kobj.parent = &bus->subsys.kobj;
- retval = kset_register(&bus->drivers);
- if (retval)
+ bus->drivers_kset = kset_create_and_add("drivers", NULL,
+ &bus->subsys.kobj);
+ if (!bus->drivers_kset) {
+ retval = -ENOMEM;
goto bus_drivers_fail;
+ }

klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
klist_init(&bus->klist_drivers, NULL, NULL);
@@ -893,7 +894,7 @@ int bus_register(struct bus_type * bus)
bus_attrs_fail:
remove_probe_files(bus);
bus_probe_files_fail:
- kset_unregister(&bus->drivers);
+ kset_unregister(bus->drivers_kset);
bus_drivers_fail:
kset_unregister(bus->devices_kset);
bus_devices_fail:
@@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus)
pr_debug("bus %s: unregistering\n", bus->name);
bus_remove_attrs(bus);
remove_probe_files(bus);
- kset_unregister(&bus->drivers);
+ kset_unregister(bus->drivers_kset);
kset_unregister(bus->devices_kset);
bus_remove_file(bus, &bus_attr_uevent);
subsystem_unregister(&bus->subsys);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eb11475..1c9770d 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)
*/
struct device_driver *driver_find(const char *name, struct bus_type *bus)
{
- struct kobject *k = kset_find_obj(&bus->drivers, name);
+ struct kobject *k = kset_find_obj(bus->drivers_kset, name);
if (k)
return to_drv(k);
return NULL;
diff --git a/include/linux/device.h b/include/linux/device.h
index 82c2777..110ace0 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -54,7 +54,7 @@ struct bus_type {
struct module * owner;

struct kset subsys;
- struct kset drivers;
+ struct kset *drivers_kset;
struct kset *devices_kset;
struct klist klist_devices;
struct klist klist_drivers;
--
1.5.3.8

2008-01-25 07:40:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 073/196] Driver Core: add kobj_attribute handling

From: Kay Sievers <[email protected]>

Add kobj_sysfs_ops to replace subsys_sysfs_ops. There is no
need for special kset operations, we want to be able to use
simple attribute operations at any kobject, not only ksets.

The whole concept of any default sysfs attribute operations
will go away with the upcoming removal of subsys_sysfs_ops.

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 10 ++++++++++
lib/kobject.c | 29 +++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index a6dd669..e694261 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -126,6 +126,16 @@ struct kset_uevent_ops {
struct kobj_uevent_env *env);
};

+struct kobj_attribute {
+ struct attribute attr;
+ ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf);
+ ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count);
+};
+
+extern struct sysfs_ops kobj_sysfs_ops;
+
/**
* struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
*
diff --git a/lib/kobject.c b/lib/kobject.c
index 67c3d38..1c343fe 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -697,6 +697,35 @@ void kset_init(struct kset * k)
spin_lock_init(&k->list_lock);
}

+/* default kobject attribute operations */
+static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ struct kobj_attribute *kattr;
+ ssize_t ret = -EIO;
+
+ kattr = container_of(attr, struct kobj_attribute, attr);
+ if (kattr->show)
+ ret = kattr->show(kobj, kattr, buf);
+ return ret;
+}
+
+static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ struct kobj_attribute *kattr;
+ ssize_t ret = -EIO;
+
+ kattr = container_of(attr, struct kobj_attribute, attr);
+ if (kattr->store)
+ ret = kattr->store(kobj, kattr, buf, count);
+ return ret;
+}
+
+struct sysfs_ops kobj_sysfs_ops = {
+ .show = kobj_attr_show,
+ .store = kobj_attr_store,
+};

/**
* kset_add - add a kset object to the hierarchy.
--
1.5.3.8

2008-01-25 07:41:21

by Greg KH

[permalink] [raw]
Subject: [PATCH 074/196] Driver Core: switch all dynamic ksets to kobj_sysfs_ops

From: Kay Sievers <[email protected]>

Switch all dynamically created ksets, that export simple attributes,
to kobj_attribute from subsys_attribute. Struct subsys_attribute will
be removed.

Signed-off-by: Kay Sievers <[email protected]>
Cc: Mike Halcrow <[email protected]>
Cc: Phillip Hellewell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 10 ++++++----
kernel/ksysfs.c | 35 +++++++++++++++++++++--------------
kernel/power/disk.c | 18 ++++++++++++------
kernel/power/main.c | 12 ++++++++----
kernel/power/power.h | 2 +-
lib/kobject.c | 10 ++++++----
6 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index bdeac38..6ded37b 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -736,12 +736,13 @@ static int ecryptfs_init_kmem_caches(void)

static struct kset *ecryptfs_kset;

-static ssize_t version_show(struct kset *kset, char *buff)
+static ssize_t version_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buff)
{
return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
}

-static struct subsys_attribute version_attr = __ATTR_RO(version);
+static struct kobj_attribute version_attr = __ATTR_RO(version);

static struct ecryptfs_version_str_map_elem {
u32 flag;
@@ -755,7 +756,8 @@ static struct ecryptfs_version_str_map_elem {
{ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
};

-static ssize_t version_str_show(struct kset *kset, char *buff)
+static ssize_t version_str_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buff)
{
int i;
int remaining = PAGE_SIZE;
@@ -782,7 +784,7 @@ out:
return total_written;
}

-static struct subsys_attribute version_attr_str = __ATTR_RO(version_str);
+static struct kobj_attribute version_attr_str = __ATTR_RO(version_str);

static struct attribute *attributes[] = {
&version_attr.attr,
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index cf02d4b..dd0f9e7 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -17,30 +17,34 @@
#include <linux/sched.h>

#define KERNEL_ATTR_RO(_name) \
-static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
+static struct kobj_attribute _name##_attr = __ATTR_RO(_name)

#define KERNEL_ATTR_RW(_name) \
-static struct subsys_attribute _name##_attr = \
+static struct kobj_attribute _name##_attr = \
__ATTR(_name, 0644, _name##_show, _name##_store)

#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
/* current uevent sequence number */
-static ssize_t uevent_seqnum_show(struct kset *kset, char *page)
+static ssize_t uevent_seqnum_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
+ return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum);
}
KERNEL_ATTR_RO(uevent_seqnum);

/* uevent helper program, used during early boo */
-static ssize_t uevent_helper_show(struct kset *kset, char *page)
+static ssize_t uevent_helper_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return sprintf(page, "%s\n", uevent_helper);
+ return sprintf(buf, "%s\n", uevent_helper);
}
-static ssize_t uevent_helper_store(struct kset *kset, const char *page, size_t count)
+static ssize_t uevent_helper_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
if (count+1 > UEVENT_HELPER_PATH_LEN)
return -ENOENT;
- memcpy(uevent_helper, page, count);
+ memcpy(uevent_helper, buf, count);
uevent_helper[count] = '\0';
if (count && uevent_helper[count-1] == '\n')
uevent_helper[count-1] = '\0';
@@ -50,21 +54,24 @@ KERNEL_ATTR_RW(uevent_helper);
#endif

#ifdef CONFIG_KEXEC
-static ssize_t kexec_loaded_show(struct kset *kset, char *page)
+static ssize_t kexec_loaded_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return sprintf(page, "%d\n", !!kexec_image);
+ return sprintf(buf, "%d\n", !!kexec_image);
}
KERNEL_ATTR_RO(kexec_loaded);

-static ssize_t kexec_crash_loaded_show(struct kset *kset, char *page)
+static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return sprintf(page, "%d\n", !!kexec_crash_image);
+ return sprintf(buf, "%d\n", !!kexec_crash_image);
}
KERNEL_ATTR_RO(kexec_crash_loaded);

-static ssize_t vmcoreinfo_show(struct kset *kset, char *page)
+static ssize_t vmcoreinfo_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return sprintf(page, "%lx %x\n",
+ return sprintf(buf, "%lx %x\n",
paddr_vmcoreinfo_note(),
(unsigned int)vmcoreinfo_max_size);
}
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index c3f0e61..ef5aa2c 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -567,7 +567,8 @@ static const char * const hibernation_modes[] = {
* supports it (as determined by having hibernation_ops).
*/

-static ssize_t disk_show(struct kset *kset, char *buf)
+static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
int i;
char *start = buf;
@@ -597,7 +598,8 @@ static ssize_t disk_show(struct kset *kset, char *buf)
}


-static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)
+static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
int error = 0;
int i;
@@ -642,13 +644,15 @@ static ssize_t disk_store(struct kset *kset, const char *buf, size_t n)

power_attr(disk);

-static ssize_t resume_show(struct kset *kset, char *buf)
+static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
return sprintf(buf,"%d:%d\n", MAJOR(swsusp_resume_device),
MINOR(swsusp_resume_device));
}

-static ssize_t resume_store(struct kset *kset, const char *buf, size_t n)
+static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
unsigned int maj, min;
dev_t res;
@@ -674,12 +678,14 @@ static ssize_t resume_store(struct kset *kset, const char *buf, size_t n)

power_attr(resume);

-static ssize_t image_size_show(struct kset *kset, char *buf)
+static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%lu\n", image_size);
}

-static ssize_t image_size_store(struct kset *kset, const char *buf, size_t n)
+static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
unsigned long size;

diff --git a/kernel/power/main.c b/kernel/power/main.c
index dce2d76..b813949 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -289,7 +289,8 @@ struct kset *power_kset;
* proper enumerated value, and initiates a suspend transition.
*/

-static ssize_t state_show(struct kset *kset, char *buf)
+static ssize_t state_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
char *s = buf;
#ifdef CONFIG_SUSPEND
@@ -310,7 +311,8 @@ static ssize_t state_show(struct kset *kset, char *buf)
return (s - buf);
}

-static ssize_t state_store(struct kset *kset, const char *buf, size_t n)
+static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
#ifdef CONFIG_SUSPEND
suspend_state_t state = PM_SUSPEND_STANDBY;
@@ -347,13 +349,15 @@ power_attr(state);
#ifdef CONFIG_PM_TRACE
int pm_trace_enabled;

-static ssize_t pm_trace_show(struct kset *kset, char *buf)
+static ssize_t pm_trace_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%d\n", pm_trace_enabled);
}

static ssize_t
-pm_trace_store(struct kset *kset, const char *buf, size_t n)
+pm_trace_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
int val;

diff --git a/kernel/power/power.h b/kernel/power/power.h
index 1083e6b..2093c3a 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -54,7 +54,7 @@ extern int pfn_is_nosave(unsigned long);
extern struct mutex pm_mutex;

#define power_attr(_name) \
-static struct subsys_attribute _name##_attr = { \
+static struct kobj_attribute _name##_attr = { \
.attr = { \
.name = __stringify(_name), \
.mode = 0644, \
diff --git a/lib/kobject.c b/lib/kobject.c
index 1c343fe..99f6354 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -626,7 +626,8 @@ static void dynamic_kobj_release(struct kobject *kobj)
}

static struct kobj_type dynamic_kobj_ktype = {
- .release = dynamic_kobj_release,
+ .release = dynamic_kobj_release,
+ .sysfs_ops = &kobj_sysfs_ops,
};

/**
@@ -836,7 +837,8 @@ static void kset_release(struct kobject *kobj)
kfree(kset);
}

-static struct kobj_type kset_type = {
+static struct kobj_type kset_ktype = {
+ .sysfs_ops = &kobj_sysfs_ops,
.release = kset_release,
};

@@ -869,11 +871,11 @@ static struct kset *kset_create(const char *name,
kset->kobj.parent = parent_kobj;

/*
- * The kobject of this kset will have a type of kset_type and belong to
+ * The kobject of this kset will have a type of kset_ktype and belong to
* no kset itself. That way we can properly free it when it is
* finished being used.
*/
- kset->kobj.ktype = &kset_type;
+ kset->kobj.ktype = &kset_ktype;
kset->kobj.kset = NULL;

return kset;
--
1.5.3.8

2008-01-25 07:41:37

by Greg KH

[permalink] [raw]
Subject: [PATCH 075/196] fix struct user_info export's sysfs interaction

From: Kay Sievers <[email protected]>

Clean up the use of ksets and kobjects. Kobjects are instances of
objects (like struct user_info), ksets are collections of objects of a
similar type (like the uids directory containing the user_info directories).
So, use kobjects for the user_info directories, and a kset for the "uids"
directory.

On object cleanup, the final kobject_put() was missing.

Cc: Dhaval Giani <[email protected]>
Cc: Srivatsa Vaddagiri <[email protected]>
Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/sched.h | 9 +---
kernel/ksysfs.c | 7 +--
kernel/user.c | 104 ++++++++++++++++++++++++-------------------------
3 files changed, 55 insertions(+), 65 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index cc14656..d6eacda 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -552,18 +552,13 @@ struct user_struct {
#ifdef CONFIG_FAIR_USER_SCHED
struct task_group *tg;
#ifdef CONFIG_SYSFS
- struct kset kset;
- struct subsys_attribute user_attr;
+ struct kobject kobj;
struct work_struct work;
#endif
#endif
};

-#ifdef CONFIG_FAIR_USER_SCHED
-extern int uids_kobject_init(void);
-#else
-static inline int uids_kobject_init(void) { return 0; }
-#endif
+extern int uids_sysfs_init(void);

extern struct user_struct *find_user(uid_t);

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index dd0f9e7..45e6465 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -141,11 +141,8 @@ static int __init ksysfs_init(void)
goto group_exit;
}

- /*
- * Create "/sys/kernel/uids" directory and corresponding root user's
- * directory under it.
- */
- error = uids_kobject_init();
+ /* create the /sys/kernel/uids/ directory */
+ error = uids_sysfs_init();
if (error)
goto notes_exit;

diff --git a/kernel/user.c b/kernel/user.c
index 80f1116..5a106f3 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -115,7 +115,7 @@ static void sched_switch_user(struct task_struct *p) { }

#if defined(CONFIG_FAIR_USER_SCHED) && defined(CONFIG_SYSFS)

-static struct kobject uids_kobject; /* represents /sys/kernel/uids directory */
+static struct kset *uids_kset; /* represents the /sys/kernel/uids/ directory */
static DEFINE_MUTEX(uids_mutex);

static inline void uids_mutex_lock(void)
@@ -128,86 +128,84 @@ static inline void uids_mutex_unlock(void)
mutex_unlock(&uids_mutex);
}

-/* return cpu shares held by the user */
-static ssize_t cpu_shares_show(struct kset *kset, char *buffer)
+/* uid directory attributes */
+static ssize_t cpu_shares_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
{
- struct user_struct *up = container_of(kset, struct user_struct, kset);
+ struct user_struct *up = container_of(kobj, struct user_struct, kobj);

- return sprintf(buffer, "%lu\n", sched_group_shares(up->tg));
+ return sprintf(buf, "%lu\n", sched_group_shares(up->tg));
}

-/* modify cpu shares held by the user */
-static ssize_t cpu_shares_store(struct kset *kset, const char *buffer,
- size_t size)
+static ssize_t cpu_shares_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t size)
{
- struct user_struct *up = container_of(kset, struct user_struct, kset);
+ struct user_struct *up = container_of(kobj, struct user_struct, kobj);
unsigned long shares;
int rc;

- sscanf(buffer, "%lu", &shares);
+ sscanf(buf, "%lu", &shares);

rc = sched_group_set_shares(up->tg, shares);

return (rc ? rc : size);
}

-static void user_attr_init(struct subsys_attribute *sa, char *name, int mode)
+static struct kobj_attribute cpu_share_attr =
+ __ATTR(cpu_share, 0644, cpu_shares_show, cpu_shares_store);
+
+/* default attributes per uid directory */
+static struct attribute *uids_attributes[] = {
+ &cpu_share_attr.attr,
+ NULL
+};
+
+/* the lifetime of user_struct is not managed by the core (now) */
+static void uids_release(struct kobject *kobj)
{
- sa->attr.name = name;
- sa->attr.mode = mode;
- sa->show = cpu_shares_show;
- sa->store = cpu_shares_store;
+ return;
}

-/* Create "/sys/kernel/uids/<uid>" directory and
- * "/sys/kernel/uids/<uid>/cpu_share" file for this user.
- */
-static int user_kobject_create(struct user_struct *up)
+static struct kobj_type uids_ktype = {
+ .sysfs_ops = &kobj_sysfs_ops,
+ .default_attrs = uids_attributes,
+ .release = uids_release,
+};
+
+/* create /sys/kernel/uids/<uid>/cpu_share file for this user */
+static int uids_user_create(struct user_struct *up)
{
- struct kset *kset = &up->kset;
- struct kobject *kobj = &kset->kobj;
+ struct kobject *kobj = &up->kobj;
int error;

- memset(kset, 0, sizeof(struct kset));
- kobj->parent = &uids_kobject; /* create under /sys/kernel/uids dir */
- kobject_set_name(kobj, "%d", up->uid);
- kset_init(kset);
- user_attr_init(&up->user_attr, "cpu_share", 0644);
-
+ memset(kobj, 0, sizeof(struct kobject));
+ kobj->ktype = &uids_ktype;
+ kobj->kset = uids_kset;
+ kobject_init(kobj);
+ kobject_set_name(&up->kobj, "%d", up->uid);
error = kobject_add(kobj);
if (error)
goto done;

- error = sysfs_create_file(kobj, &up->user_attr.attr);
- if (error)
- kobject_del(kobj);
-
kobject_uevent(kobj, KOBJ_ADD);
-
done:
return error;
}

-/* create these in sysfs filesystem:
+/* create these entries in sysfs:
* "/sys/kernel/uids" directory
* "/sys/kernel/uids/0" directory (for root user)
* "/sys/kernel/uids/0/cpu_share" file (for root user)
*/
-int __init uids_kobject_init(void)
+int __init uids_sysfs_init(void)
{
- int error;
+ uids_kset = kset_create_and_add("uids", NULL, &kernel_kset->kobj);
+ if (!uids_kset)
+ return -ENOMEM;

- /* create under /sys/kernel dir */
- uids_kobject.parent = &kernel_kset->kobj;
- uids_kobject.kset = kernel_kset;
- kobject_set_name(&uids_kobject, "uids");
- kobject_init(&uids_kobject);
-
- error = kobject_add(&uids_kobject);
- if (!error)
- error = user_kobject_create(&root_user);
-
- return error;
+ return uids_user_create(&root_user);
}

/* work function to remove sysfs directory for a user and free up
@@ -216,7 +214,6 @@ int __init uids_kobject_init(void)
static void remove_user_sysfs_dir(struct work_struct *w)
{
struct user_struct *up = container_of(w, struct user_struct, work);
- struct kobject *kobj = &up->kset.kobj;
unsigned long flags;
int remove_user = 0;

@@ -238,9 +235,9 @@ static void remove_user_sysfs_dir(struct work_struct *w)
if (!remove_user)
goto done;

- sysfs_remove_file(kobj, &up->user_attr.attr);
- kobject_uevent(kobj, KOBJ_REMOVE);
- kobject_del(kobj);
+ kobject_uevent(&up->kobj, KOBJ_REMOVE);
+ kobject_del(&up->kobj);
+ kobject_put(&up->kobj);

sched_destroy_user(up);
key_put(up->uid_keyring);
@@ -267,7 +264,8 @@ static inline void free_user(struct user_struct *up, unsigned long flags)

#else /* CONFIG_FAIR_USER_SCHED && CONFIG_SYSFS */

-static inline int user_kobject_create(struct user_struct *up) { return 0; }
+int uids_sysfs_init(void) { return 0; }
+static inline int uids_user_create(struct user_struct *up) { return 0; }
static inline void uids_mutex_lock(void) { }
static inline void uids_mutex_unlock(void) { }

@@ -324,7 +322,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
struct hlist_head *hashent = uidhashentry(ns, uid);
struct user_struct *up;

- /* Make uid_hash_find() + user_kobject_create() + uid_hash_insert()
+ /* Make uid_hash_find() + uids_user_create() + uid_hash_insert()
* atomic.
*/
uids_mutex_lock();
@@ -370,7 +368,7 @@ struct user_struct * alloc_uid(struct user_namespace *ns, uid_t uid)
return NULL;
}

- if (user_kobject_create(new)) {
+ if (uids_user_create(new)) {
sched_destroy_user(new);
key_put(new->uid_keyring);
key_put(new->session_keyring);
--
1.5.3.8

2008-01-25 07:41:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 076/196] ecryptfs: remove version_str file from sysfs

This file violates the one-value-per-file sysfs rule.

If you all want it added back, please do something like a per-feature
file to show what is present and what isn't.

Cc: Kay Sievers <[email protected]>
Cc: Mike Halcrow <[email protected]>
Cc: Phillip Hellewell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 43 -------------------------------------------
1 files changed, 0 insertions(+), 43 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 6ded37b..d984eac 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -744,51 +744,8 @@ static ssize_t version_show(struct kobject *kobj,

static struct kobj_attribute version_attr = __ATTR_RO(version);

-static struct ecryptfs_version_str_map_elem {
- u32 flag;
- char *str;
-} ecryptfs_version_str_map[] = {
- {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
- {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
- {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
- {ECRYPTFS_VERSIONING_POLICY, "policy"},
- {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"},
- {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
-};
-
-static ssize_t version_str_show(struct kobject *kobj,
- struct kobj_attribute *attr, char *buff)
-{
- int i;
- int remaining = PAGE_SIZE;
- int total_written = 0;
-
- buff[0] = '\0';
- for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
- int entry_size;
-
- if (!(ECRYPTFS_VERSIONING_MASK
- & ecryptfs_version_str_map[i].flag))
- continue;
- entry_size = strlen(ecryptfs_version_str_map[i].str);
- if ((entry_size + 2) > remaining)
- goto out;
- memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
- buff[entry_size++] = '\n';
- buff[entry_size] = '\0';
- buff += entry_size;
- total_written += entry_size;
- remaining -= entry_size;
- }
-out:
- return total_written;
-}
-
-static struct kobj_attribute version_attr_str = __ATTR_RO(version_str);
-
static struct attribute *attributes[] = {
&version_attr.attr,
- &version_attr_str.attr,
NULL,
};

--
1.5.3.8

2008-01-25 07:42:18

by Greg KH

[permalink] [raw]
Subject: [PATCH 077/196] efivars: make new_var and del_var binary sysfs files

These files should not be "normal" sysfs files as they really are binary
ones. This patch makes them binary files and saves code in doing so.

Cc: Kay Sievers <[email protected]>
Tested-by: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 51 +++++++++++++++++++------------------------
1 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 06ecdb9..82183c2 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -143,13 +143,6 @@ struct efivar_attribute efivar_attr_##_name = { \
.store = _store, \
};

-#define VAR_SUBSYS_ATTR(_name, _mode, _show, _store) \
-struct subsys_attribute var_subsys_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode}, \
- .show = _show, \
- .store = _store, \
-};
-
#define to_efivar_attr(_attr) container_of(_attr, struct efivar_attribute, attr)
#define to_efivar_entry(obj) container_of(obj, struct efivar_entry, kobj)

@@ -408,12 +401,6 @@ static struct kobj_type efivar_ktype = {
.default_attrs = def_attrs,
};

-static ssize_t
-dummy(struct kset *kset, char *buf)
-{
- return -ENODEV;
-}
-
static inline void
efivar_unregister(struct efivar_entry *var)
{
@@ -421,8 +408,9 @@ efivar_unregister(struct efivar_entry *var)
}


-static ssize_t
-efivar_create(struct kset *kset, const char *buf, size_t count)
+static ssize_t efivar_create(struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t pos, size_t count)
{
struct efi_variable *new_var = (struct efi_variable *)buf;
struct efivar_entry *search_efivar, *n;
@@ -479,8 +467,9 @@ efivar_create(struct kset *kset, const char *buf, size_t count)
return count;
}

-static ssize_t
-efivar_delete(struct kset *kset, const char *buf, size_t count)
+static ssize_t efivar_delete(struct kobject *kobj,
+ struct bin_attribute *bin_attr,
+ char *buf, loff_t pos, size_t count)
{
struct efi_variable *del_var = (struct efi_variable *)buf;
struct efivar_entry *search_efivar, *n;
@@ -537,13 +526,14 @@ efivar_delete(struct kset *kset, const char *buf, size_t count)
return count;
}

-static VAR_SUBSYS_ATTR(new_var, 0200, dummy, efivar_create);
-static VAR_SUBSYS_ATTR(del_var, 0200, dummy, efivar_delete);
+static struct bin_attribute var_subsys_attr_new_var = {
+ .attr = {.name = "new_var", .mode = 0200},
+ .write = efivar_create,
+};

-static struct subsys_attribute *var_subsys_attrs[] = {
- &var_subsys_attr_new_var,
- &var_subsys_attr_del_var,
- NULL,
+static struct bin_attribute var_subsys_attr_del_var = {
+ .attr = {.name = "del_var", .mode = 0200},
+ .write = efivar_delete,
};

/*
@@ -728,11 +718,16 @@ efivars_init(void)
* Now add attributes to allow creation of new vars
* and deletion of existing ones...
*/
-
- for (i = 0; (attr = var_subsys_attrs[i]) && !error; i++) {
- if (attr->show && attr->store)
- error = subsys_create_file(&vars_subsys, attr);
- }
+ error = sysfs_create_bin_file(&vars_subsys.kobj,
+ &var_subsys_attr_new_var);
+ if (error)
+ printk(KERN_ERR "efivars: unable to create new_var sysfs file"
+ " due to error %d\n", error);
+ error = sysfs_create_bin_file(&vars_subsys.kobj,
+ &var_subsys_attr_del_var);
+ if (error)
+ printk(KERN_ERR "efivars: unable to create del_var sysfs file"
+ " due to error %d\n", error);

/* Don't forget the systab entry */

--
1.5.3.8

2008-01-25 07:42:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 078/196] kobject: convert efivars to kobj_attr interface

This cleans up a lot of code and gets rid of a unneeded macro, and gets
us one step closer to deleting the deprecated subsys_attr code.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 35 ++++++++++++++---------------------
1 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 82183c2..ebc3853 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -129,13 +129,6 @@ struct efivar_attribute {
};


-#define EFI_ATTR(_name, _mode, _show, _store) \
-struct subsys_attribute efi_attr_##_name = { \
- .attr = {.name = __stringify(_name), .mode = _mode}, \
- .show = _show, \
- .store = _store, \
-};
-
#define EFIVAR_ATTR(_name, _mode, _show, _store) \
struct efivar_attribute efivar_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode}, \
@@ -540,12 +533,12 @@ static struct bin_attribute var_subsys_attr_del_var = {
* Let's not leave out systab information that snuck into
* the efivars driver
*/
-static ssize_t
-systab_read(struct kset *kset, char *buf)
+static ssize_t systab_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *str = buf;

- if (!kset || !buf)
+ if (!kobj || !buf)
return -EINVAL;

if (efi.mps != EFI_INVALID_TABLE_ADDR)
@@ -566,13 +559,19 @@ systab_read(struct kset *kset, char *buf)
return str - buf;
}

-static EFI_ATTR(systab, 0400, systab_read, NULL);
+static struct kobj_attribute efi_attr_systab =
+ __ATTR(systab, 0400, systab_show, NULL);

-static struct subsys_attribute *efi_subsys_attrs[] = {
- &efi_attr_systab,
+static struct attribute *efi_subsys_attrs[] = {
+ &efi_attr_systab.attr,
NULL, /* maybe more in the future? */
};

+static struct attribute_group efi_subsys_attr_group = {
+ .attrs = efi_subsys_attrs,
+};
+
+
static decl_subsys(vars, NULL);
static decl_subsys(efi, NULL);

@@ -651,9 +650,8 @@ efivars_init(void)
efi_status_t status = EFI_NOT_FOUND;
efi_guid_t vendor_guid;
efi_char16_t *variable_name;
- struct subsys_attribute *attr;
unsigned long variable_name_size = 1024;
- int i, error = 0;
+ int error = 0;

if (!efi_enabled)
return -ENODEV;
@@ -730,12 +728,7 @@ efivars_init(void)
" due to error %d\n", error);

/* Don't forget the systab entry */
-
- for (i = 0; (attr = efi_subsys_attrs[i]) && !error; i++) {
- if (attr->show)
- error = subsys_create_file(&efi_subsys, attr);
- }
-
+ error = sysfs_create_group(&efi_subsys.kobj, &efi_subsys_attr_group);
if (error)
printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
else
--
1.5.3.8

2008-01-25 07:42:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 079/196] firmware: export firmware_kset so that people can use that instead of the braindead firmware_register interface

Needed for future firmware subsystem cleanups.

In the end, the firmware_register/unregister functions will be deleted
entirely, but we need this symbol so that subsystems can migrate over.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/firmware.c | 3 ++-
include/linux/kobject.h | 2 ++
2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 6a4e494..c7f635b 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -15,7 +15,8 @@

#include "base.h"

-static struct kset *firmware_kset;
+struct kset *firmware_kset;
+EXPORT_SYMBOL_GPL(firmware_kset);

int firmware_register(struct kset *s)
{
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index e694261..29dc444 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -210,6 +210,8 @@ extern struct kset *kernel_kset;
extern struct kobject *hypervisor_kobj;
/* The global /sys/power/ kset for people to chain off of */
extern struct kset *power_kset;
+/* The global /sys/firmware/ kset for people to chain off of */
+extern struct kset *firmware_kset;

extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);
--
1.5.3.8

2008-01-25 07:43:32

by Greg KH

[permalink] [raw]
Subject: [PATCH 080/196] kset: convert efivars to use kset_create for the efi subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index ebc3853..018ca1c 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -573,7 +573,7 @@ static struct attribute_group efi_subsys_attr_group = {


static decl_subsys(vars, NULL);
-static decl_subsys(efi, NULL);
+static struct kset *efi_kset;

/*
* efivar_create_sysfs_entry()
@@ -668,15 +668,14 @@ efivars_init(void)
/*
* For now we'll register the efi subsys within this driver
*/
-
- error = firmware_register(&efi_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Firmware registration failed with error %d.\n", error);
+ efi_kset = kset_create_and_add("efi", NULL, &firmware_kset->kobj);
+ if (!efi_kset) {
+ printk(KERN_ERR "efivars: Firmware registration failed.\n");
+ error = -ENOMEM;
goto out_free;
}

- vars_subsys.kobj.kset = &efi_subsys;
+ vars_subsys.kobj.kset = efi_kset;

error = subsystem_register(&vars_subsys);

@@ -728,7 +727,7 @@ efivars_init(void)
" due to error %d\n", error);

/* Don't forget the systab entry */
- error = sysfs_create_group(&efi_subsys.kobj, &efi_subsys_attr_group);
+ error = sysfs_create_group(&efi_kset->kobj, &efi_subsys_attr_group);
if (error)
printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
else
@@ -737,7 +736,7 @@ efivars_init(void)
subsystem_unregister(&vars_subsys);

out_firmware_unregister:
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);

out_free:
kfree(variable_name);
@@ -758,7 +757,7 @@ efivars_exit(void)
}

subsystem_unregister(&vars_subsys);
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);
}

module_init(efivars_init);
--
1.5.3.8

2008-01-25 07:43:49

by Greg KH

[permalink] [raw]
Subject: [PATCH 081/196] kset: convert efivars to use kset_create for the vars sub-subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 018ca1c..e17cd81 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -572,7 +572,7 @@ static struct attribute_group efi_subsys_attr_group = {
};


-static decl_subsys(vars, NULL);
+static struct kset *vars_kset;
static struct kset *efi_kset;

/*
@@ -618,7 +618,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

kobject_set_name(&new_efivar->kobj, "%s", short_name);
- new_efivar->kobj.kset = &vars_subsys;
+ new_efivar->kobj.kset = vars_kset;
new_efivar->kobj.ktype = &efivar_ktype;
i = kobject_register(&new_efivar->kobj);
if (i) {
@@ -675,12 +675,10 @@ efivars_init(void)
goto out_free;
}

- vars_subsys.kobj.kset = efi_kset;
-
- error = subsystem_register(&vars_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Subsystem registration failed with error %d.\n", error);
+ vars_kset = kset_create_and_add("vars", NULL, &efi_kset->kobj);
+ if (!vars_kset) {
+ printk(KERN_ERR "efivars: Subsystem registration failed.\n");
+ error = -ENOMEM;
goto out_firmware_unregister;
}

@@ -715,12 +713,12 @@ efivars_init(void)
* Now add attributes to allow creation of new vars
* and deletion of existing ones...
*/
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_new_var);
if (error)
printk(KERN_ERR "efivars: unable to create new_var sysfs file"
" due to error %d\n", error);
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_del_var);
if (error)
printk(KERN_ERR "efivars: unable to create del_var sysfs file"
@@ -733,7 +731,7 @@ efivars_init(void)
else
goto out_free;

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);

out_firmware_unregister:
kset_unregister(efi_kset);
@@ -756,7 +754,7 @@ efivars_exit(void)
efivar_unregister(entry);
}

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);
kset_unregister(efi_kset);
}

--
1.5.3.8

2008-01-25 07:44:38

by Greg KH

[permalink] [raw]
Subject: [PATCH 001/196] Chinese: Add the known_regression URI to the HOWTO

From: Li Yang <[email protected]>

Update translation for commit be3884943674f8ee7656b1d8b71c087ec900c836.

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/HOWTO | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index 48fc67b..c8660da 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -218,6 +218,8 @@ kernel.org网站的pub/linux/kernel/v2.6/目录下找到它。它的开发遵循
时,一个新的-rc版本就会被发布。计划是每周都发布新的-rc版本。
- 这个过程一直持续下去直到内核被认为达到足够稳定的状态,持续时间大概是
6个星期。
+ - 以下地址跟踪了在每个-rc发布中发现的退步列表:
+ http://kernelnewbies.org/known_regressions

关于内核发布,值得一提的是Andrew Morton在linux-kernel邮件列表中如是说:
“没有人知道新内核何时会被发布,因为发布是根据已知bug的情况来决定
--
1.5.3.8

2008-01-25 07:44:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 002/196] Chinese: rephrase English introduction in HOWTO

From: Li Yang <[email protected]>

Rephrase the introduction as suggested by Jesper Juhl.

Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/HOWTO | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/zh_CN/HOWTO b/Documentation/zh_CN/HOWTO
index c8660da..79d1c3c 100644
--- a/Documentation/zh_CN/HOWTO
+++ b/Documentation/zh_CN/HOWTO
@@ -1,10 +1,10 @@
Chinese translated version of Documentation/HOWTO

If you have any comment or update to the content, please contact the
-original document maintainer directly. However, if you have problem
+original document maintainer directly. However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
-help. Contact the Chinese maintainer, if this translation is outdated
-or there is problem with translation.
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.

Maintainer: Greg Kroah-Hartman <[email protected]>
Chinese maintainer: Li Yang <[email protected]>
--
1.5.3.8

2008-01-25 07:45:22

by Greg KH

[permalink] [raw]
Subject: [PATCH 004/196] Chinese: add translation of SubmittingPatches

From: TripleX Chung <[email protected]>

Signed-off-by: TripleX Chung <[email protected]>
Signed-off-by: Li Yang <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/zh_CN/SubmittingPatches | 416 +++++++++++++++++++++++++++++++++
1 files changed, 416 insertions(+), 0 deletions(-)
create mode 100644 Documentation/zh_CN/SubmittingPatches

diff --git a/Documentation/zh_CN/SubmittingPatches b/Documentation/zh_CN/SubmittingPatches
new file mode 100644
index 0000000..985c92e
--- /dev/null
+++ b/Documentation/zh_CN/SubmittingPatches
@@ -0,0 +1,416 @@
+Chinese translated version of Documentation/SubmittingPatches
+
+If you have any comment or update to the content, please contact the
+original document maintainer directly. However, if you have a problem
+communicating in English you can also ask the Chinese maintainer for
+help. Contact the Chinese maintainer if this translation is outdated
+or if there is a problem with the translation.
+
+Chinese maintainer: TripleX Chung <[email protected]>
+---------------------------------------------------------------------
+Documentation/SubmittingPatches 的中文翻译
+
+如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
+交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+译存在问题,请联系中文版维护者。
+
+中文版维护者: 钟宇 TripleX Chung <[email protected]>
+中文版翻译者: 钟宇 TripleX Chung <[email protected]>
+中文版校译者: 李阳 Li Yang <[email protected]>
+ 王聪 Wang Cong <[email protected]>
+
+以下为正文
+---------------------------------------------------------------------
+
+ 如何让你的改动进入内核
+ 或者
+ 获得亲爱的 Linus Torvalds 的关注和处理
+----------------------------------
+
+对于想要将改动提交到 Linux 内核的个人或者公司来说,如果不熟悉“规矩”,
+提交的流程会让人畏惧。本文档收集了一系列建议,这些建议可以大大的提高你
+的改动被接受的机会。
+阅读 Documentation/SubmitChecklist 来获得在提交代码前需要检查的项目的列
+表。如果你在提交一个驱动程序,那么同时阅读一下
+Documentation/SubmittingDrivers 。
+
+
+--------------------------
+第一节 - 创建并发送你的改动
+--------------------------
+
+1) "diff -up"
+-----------
+
+使用 "diff -up" 或者 "diff -uprN" 来创建补丁。
+
+所有内核的改动,都是以补丁的形式呈现的,补丁由 diff(1) 生成。创建补丁的
+时候,要确认它是以 "unified diff" 格式创建的,这种格式由 diff(1) 的 '-u'
+参数生成。而且,请使用 '-p' 参数,那样会显示每个改动所在的C函数,使得
+产生的补丁容易读得多。补丁应该基于内核源代码树的根目录,而不是里边的任
+何子目录。
+为一个单独的文件创建补丁,一般来说这样做就够了:
+
+ SRCTREE= linux-2.6
+ MYFILE= drivers/net/mydriver.c
+
+ cd $SRCTREE
+ cp $MYFILE $MYFILE.orig
+ vi $MYFILE # make your change
+ cd ..
+ diff -up $SRCTREE/$MYFILE{.orig,} > /tmp/patch
+
+为多个文件创建补丁,你可以解开一个没有修改过的内核源代码树,然后和你自
+己的代码树之间做 diff 。例如:
+
+ MYSRC= /devel/linux-2.6
+
+ tar xvfz linux-2.6.12.tar.gz
+ mv linux-2.6.12 linux-2.6.12-vanilla
+ diff -uprN -X linux-2.6.12-vanilla/Documentation/dontdiff \
+ linux-2.6.12-vanilla $MYSRC > /tmp/patch
+
+"dontdiff" 是内核在编译的时候产生的文件的列表,列表中的文件在 diff(1)
+产生的补丁里会被跳过。"dontdiff" 文件被包含在2.6.12和之后版本的内核源代
+码树中。对于更早的内核版本,你可以从
+<http://www.xenotime.net/linux/doc/dontdiff> 获取它。
+确定你的补丁里没有包含任何不属于这次补丁提交的额外文件。记得在用diff(1)
+生成补丁之后,审阅一次补丁,以确保准确。
+如果你的改动很散乱,你应该研究一下如何将补丁分割成独立的部分,将改动分
+割成一系列合乎逻辑的步骤。这样更容易让其他内核开发者审核,如果你想你的
+补丁被接受,这是很重要的。下面这些脚本能够帮助你做这件事情:
+Quilt:
+http://savannah.nongnu.org/projects/quilt
+
+Andrew Morton 的补丁脚本:
+http://www.zip.com.au/~akpm/linux/patches/
+作为这些脚本的替代,quilt 是值得推荐的补丁管理工具(看上面的链接)。
+
+2)描述你的改动。
+描述你的改动包含的技术细节。
+
+要多具体就写多具体。最糟糕的描述可能是像下面这些语句:“更新了某驱动程
+序”,“修正了某驱动程序的bug”,或者“这个补丁包含了某子系统的修改,请
+使用。”
+
+如果你的描述开始变长,这表示你也许需要拆分你的补丁了,请看第3小节,
+继续。
+
+3)拆分你的改动
+
+将改动拆分,逻辑类似的放到同一个补丁文件里。
+
+例如,如果你的改动里同时有bug修正和性能优化,那么把这些改动才分到两个或
+者更多的补丁文件中。如果你的改动包含对API的修改,并且修改了驱动程序来适
+应这些新的API,那么把这些修改分成两个补丁。
+
+另一方面,如果你将一个单独的改动做成多个补丁文件,那么将它们合并成一个
+单独的补丁文件。这样一个逻辑上单独的改动只被包含在一个补丁文件里。
+
+如果有一个补丁依赖另外一个补丁来完成它的改动,那没问题。简单的在你的补
+丁描述里指出“这个补丁依赖某补丁”就好了。
+
+如果你不能将补丁浓缩成更少的文件,那么每次大约发送出15个,然后等待审查
+和整合。
+
+4)选择 e-mail 的收件人
+
+看一遍 MAINTAINERS 文件和源代码,看看你所的改动所在的内核子系统有没有指
+定的维护者。如果有,给他们发e-mail。
+
+如果没有找到维护者,或者维护者没有反馈,将你的补丁发送到内核开发者主邮
+件列表 [email protected]。大部分的内核开发者都跟踪这个邮件列
+表,可以评价你的改动。
+
+每次不要发送超过15个补丁到 vger 邮件列表!!!
+
+Linus Torvalds 是决定改动能否进入 Linux 内核的最终裁决者。他的 e-mail
+地址是 <[email protected]> 。他收到的 e-mail 很多,所以一般
+的说,最好别给他发 e-mail。
+
+那些修正bug,“显而易见”的修改或者是类似的只需要很少讨论的补丁可以直接
+发送或者CC给Linus。那些需要讨论或者没有很清楚的好处的补丁,一般先发送到
+linux-kernel邮件列表。只有当补丁被讨论得差不多了,才提交给Linus。
+
+5)选择CC( e-mail 抄送)列表
+
+除非你有理由不这样做,否则CC [email protected]
+
+除了 Linus 之外,其他内核开发者也需要注意到你的改动,这样他们才能评论你
+的改动并提供代码审查和建议。linux-kernel 是 Linux 内核开发者主邮件列表
+。其它的邮件列表为特定的子系统提供服务,比如 USB,framebuffer 设备,虚
+拟文件系统,SCSI 子系统,等等。查看 MAINTAINERS 文件来获得和你的改动有
+关的邮件列表。
+
+Majordomo lists of VGER.KERNEL.ORG at:
+ <http://vger.kernel.org/vger-lists.html>
+
+如果改动影响了用户空间和内核之间的接口,请给 MAN-PAGES 的维护者(列在
+MAITAINERS 文件里的)发送一个手册页(man-pages)补丁,或者至少通知一下改
+变,让一些信息有途径进入手册页。
+
+即使在第四步的时候,维护者没有作出回应,也要确认在修改他们的代码的时候
+,一直将维护者拷贝到CC列表中。
+
+对于小的补丁,你也许会CC到 Adrian Bunk 管理的搜集琐碎补丁的邮件列表
+(Trivial Patch Monkey)[email protected],那里专门收集琐碎的补丁。下面这样
+的补丁会被看作“琐碎的”补丁:
+ 文档的拼写修正。
+ 修正会影响到 grep(1) 的拼写。
+ 警告信息修正(频繁的打印无用的警告是不好的。)
+ 编译错误修正(代码逻辑的确是对的,只是编译有问题。)
+ 运行时修正(只要真的修正了错误。)
+ 移除使用了被废弃的函数/宏的代码(例如 check_region。)
+ 联系方式和文档修正。
+ 用可移植的代码替换不可移植的代码(即使在体系结构相关的代码中,既然有
+ 人拷贝,只要它是琐碎的)
+ 任何文件的作者/维护者对该文件的改动(例如 patch monkey 在重传模式下)
+
+URL: <http://www.kernel.org/pub/linux/kernel/people/bunk/trivial/>
+
+(译注,关于“琐碎补丁”的一些说明:因为原文的这一部分写得比较简单,所以不得不
+违例写一下译注。"trivial"这个英文单词的本意是“琐碎的,不重要的。”但是在这里
+有稍微有一些变化,例如对一些明显的NULL指针的修正,属于运行时修正,会被归类
+到琐碎补丁里。虽然NULL指针的修正很重要,但是这样的修正往往很小而且很容易得到
+检验,所以也被归入琐碎补丁。琐碎补丁更精确的归类应该是
+“simple, localized & easy to verify”,也就是说简单的,局部的和易于检验的。
[email protected]邮件列表的目的是针对这样的补丁,为提交者提供一个中心,来
+降低提交的门槛。)
+
+6)没有 MIME 编码,没有链接,没有压缩,没有附件,只有纯文本。
+
+Linus 和其他的内核开发者需要阅读和评论你提交的改动。对于内核开发者来说
+,可以“引用”你的改动很重要,使用一般的 e-mail 工具,他们就可以在你的
+代码的任何位置添加评论。
+
+因为这个原因,所有的提交的补丁都是 e-mail 中“内嵌”的。
+警告:如果你使用剪切-粘贴你的补丁,小心你的编辑器的自动换行功能破坏你的
+补丁。
+
+不要将补丁作为 MIME 编码的附件,不管是否压缩。很多流行的 e-mail 软件不
+是任何时候都将 MIME 编码的附件当作纯文本发送的,这会使得别人无法在你的
+代码中加评论。另外,MIME 编码的附件会让 Linus 多花一点时间来处理,这就
+降低了你的改动被接受的可能性。
+
+警告:一些邮件软件,比如 Mozilla 会将你的信息以如下格式发送:
+---- 邮件头 ----
+Content-Type: text/plain; charset=us-ascii; format=flowed
+---- 邮件头 ----
+问题在于 “format=flowed” 会让接收端的某些邮件软件将邮件中的制表符替换
+成空格以及做一些类似的替换。这样,你发送的时候看起来没问题的补丁就被破
+坏了。
+
+要修正这个问题,只需要将你的 mozilla 的 defaults/pref/mailnews.js 文件
+里的
+pref("mailnews.send_plaintext_flowed", false); // RFC 2646=======
+修改成
+pref("mailnews.display.disable_format_flowed_support", true);
+就可以了。
+
+7) e-mail 的大小
+
+给 Linus 发送补丁的时候,永远按照第6小节说的做。
+
+大的改动对邮件列表不合适,对某些维护者也不合适。如果你的补丁,在不压缩
+的情况下,超过了40kB,那么你最好将补丁放在一个能通过 internet 访问的服
+务器上,然后用指向你的补丁的 URL 替代。
+
+8) 指出你的内核版本
+
+在标题和在补丁的描述中,指出补丁对应的内核的版本,是很重要的。
+
+如果补丁不能干净的在最新版本的内核上打上,Linus 是不会接受它的。
+
+9) 不要气馁,继续提交。
+
+当你提交了改动以后,耐心地等待。如果 Linus 喜欢你的改动并且同意它,那么
+它将在下一个内核发布版本中出现。
+
+然而,如果你的改动没有出现在下一个版本的内核中,可能有若干原因。减少那
+些原因,修正错误,重新提交更新后的改动,是你自己的工作。
+
+Linus不给出任何评论就“丢弃”你的补丁是常见的事情。在系统中这样的事情很
+平常。如果他没有接受你的补丁,也许是由于以下原本:
+* 你的补丁不能在最新版本的内核上干净的打上。
+* 你的补丁在 linux-kernel 邮件列表中没有得到充分的讨论。
+* 风格问题(参照第2小节)
+* 邮件格式问题(重读本节)
+* 你的改动有技术问题。
+* 他收到了成吨的 e-mail,而你的在混乱中丢失了。
+* 你让人为难。
+
+有疑问的时候,在 linux-kernel 邮件列表上请求评论。
+
+10) 在标题上加上 PATCH 的字样
+
+Linus 和 linux-kernel 邮件列表的 e-mail 流量都很高,一个通常的约定是标
+题行以 [PATCH] 开头。这样可以让 Linus 和其他内核开发人员可以从 e-mail
+的讨论中很轻易的将补丁分辨出来。
+
+11)为你的工作签名
+
+为了加强对谁做了何事的追踪,尤其是对那些透过好几层的维护者的补丁,我们
+建议在发送出去的补丁上加一个 “sign-off” 的过程。
+
+"sign-off" 是在补丁的注释的最后的简单的一行文字,认证你编写了它或者其他
+人有权力将它作为开放源代码的补丁传递。规则很简单:如果你能认证如下信息
+:
+ 开发者来源证书 1.1
+ 对于本项目的贡献,我认证如下信息:
+ (a)这些贡献是完全或者部分的由我创建,我有权利以文件中指出
+ 的开放源代码许可证提交它;或者
+ (b)这些贡献基于以前的工作,据我所知,这些以前的工作受恰当的开放
+ 源代码许可证保护,而且,根据许可证,我有权提交修改后的贡献,
+ 无论是完全还是部分由我创造,这些贡献都使用同一个开放源代码许可证
+ (除非我被允许用其它的许可证),正如文件中指出的;或者
+ (c)这些贡献由认证(a),(b)或者(c)的人直接提供给我,而
+ 且我没有修改它。
+ (d)我理解并同意这个项目和贡献是公开的,贡献的记录(包括我
+ 一起提交的个人记录,包括 sign-off )被永久维护并且可以和这个项目
+ 或者开放源代码的许可证同步地再发行。
+ 那么加入这样一行:
+ Signed-off-by: Random J Developer <[email protected]>
+
+使用你的真名(抱歉,不能使用假名或者匿名。)
+
+有人在最后加上标签。现在这些东西会被忽略,但是你可以这样做,来标记公司
+内部的过程,或者只是指出关于 sign-off 的一些特殊细节。
+
+12)标准补丁格式
+
+标准的补丁,标题行是:
+ Subject: [PATCH 001/123] 子系统:一句话概述
+
+标准补丁的信体存在如下部分:
+
+ - 一个 "from" 行指出补丁作者。
+
+ - 一个空行
+
+ - 说明的主体,这些说明文字会被拷贝到描述该补丁的永久改动记录里。
+
+ - 一个由"---"构成的标记行
+
+ - 不合适放到改动记录里的额外的注解。
+
+ - 补丁本身(diff 输出)
+
+标题行的格式,使得对标题行按字母序排序非常的容易 - 很多 e-mail 客户端都
+可以支持 - 因为序列号是用零填充的,所以按数字排序和按字母排序是一样的。
+
+e-mail 标题中的“子系统”标识哪个内核子系统将被打补丁。
+
+e-mail 标题中的“一句话概述”扼要的描述 e-mail 中的补丁。“一句话概述”
+不应该是一个文件名。对于一个补丁系列(“补丁系列”指一系列的多个相关补
+丁),不要对每个补丁都使用同样的“一句话概述”。
+
+记住 e-mail 的“一句话概述”会成为该补丁的全局唯一标识。它会蔓延到 git
+的改动记录里。然后“一句话概述”会被用在开发者的讨论里,用来指代这个补
+丁。用户将希望通过 google 来搜索"一句话概述"来找到那些讨论这个补丁的文
+章。
+
+一些标题的例子:
+
+ Subject: [patch 2/5] ext2: improve scalability of bitmap searching
+ Subject: [PATCHv2 001/207] x86: fix eflags tracking
+
+"from" 行是信体里的最上面一行,具有如下格式:
+ From: Original Author <[email protected]>
+
+"from" 行指明在永久改动日志里,谁会被确认为作者。如果没有 "from" 行,那
+么邮件头里的 "From: " 行会被用来决定改动日志中的作者。
+
+说明的主题将会被提交到永久的源代码改动日志里,因此对那些早已经不记得和
+这个补丁相关的讨论细节的有能力的读者来说,是有意义的。
+
+"---" 标记行对于补丁处理工具要找到哪里是改动日志信息的结束,是不可缺少
+的。
+
+对于 "---" 标记之后的额外注解,一个好的用途就是用来写 diffstat,用来显
+示修改了什么文件和每个文件都增加和删除了多少行。diffstat 对于比较大的补
+丁特别有用。其余那些只是和时刻或者开发者相关的注解,不合适放到永久的改
+动日志里的,也应该放这里。
+使用 diffstat的选项 "-p 1 -w 70" 这样文件名就会从内核源代码树的目录开始
+,不会占用太宽的空间(很容易适合80列的宽度,也许会有一些缩进。)
+
+在后面的参考资料中能看到适当的补丁格式的更多细节。
+
+-------------------------------
+第二节 提示,建议和诀窍
+-------------------------------
+
+本节包含很多和提交到内核的代码有关的通常的"规则"。事情永远有例外...但是
+你必须真的有好的理由这样做。你可以把本节叫做Linus的计算机科学入门课。
+
+1) 读 Document/CodingStyle
+
+Nuff 说过,如果你的代码和这个偏离太多,那么它有可能会被拒绝,没有更多的
+审查,没有更多的评价。
+
+2) #ifdef 是丑陋的
+混杂了 ifdef 的代码难以阅读和维护。别这样做。作为替代,将你的 ifdef 放
+在头文件里,有条件地定义 "static inline" 函数,或者宏,在代码里用这些东
+西。让编译器把那些"空操作"优化掉。
+
+一个简单的例子,不好的代码:
+
+ dev = alloc_etherdev (sizeof(struct funky_private));
+ if (!dev)
+ return -ENODEV;
+ #ifdef CONFIG_NET_FUNKINESS
+ init_funky_net(dev);
+ #endif
+
+清理后的例子:
+
+(头文件里)
+ #ifndef CONFIG_NET_FUNKINESS
+ static inline void init_funky_net (struct net_device *d) {}
+ #endif
+
+(代码文件里)
+ dev = alloc_etherdev (sizeof(struct funky_private));
+ if (!dev)
+ return -ENODEV;
+ init_funky_net(dev);
+
+3) 'static inline' 比宏好
+
+Static inline 函数相比宏来说,是好得多的选择。Static inline 函数提供了
+类型安全,没有长度限制,没有格式限制,在 gcc 下开销和宏一样小。
+
+宏只在 static inline 函数不是最优的时候[在 fast paths 里有很少的独立的
+案例],或者不可能用 static inline 函数的时候[例如字符串分配]。
+应该用 'static inline' 而不是 'static __inline__', 'extern inline' 和
+'extern __inline__' 。
+
+4) 不要过度设计
+
+不要试图预计模糊的未来事情,这些事情也许有用也许没有用:"让事情尽可能的
+简单,而不是更简单"。
+
+----------------
+第三节 参考文献
+----------------
+
+Andrew Morton, "The perfect patch" (tpp).
+ <http://www.zip.com.au/~akpm/linux/patches/stuff/tpp.txt>
+
+Jeff Garzik, "Linux kernel patch submission format".
+ <http://linux.yyz.us/patch-format.html>
+
+Greg Kroah-Hartman, "How to piss off a kernel subsystem maintainer".
+ <http://www.kroah.com/log/2005/03/31/>
+ <http://www.kroah.com/log/2005/07/08/>
+ <http://www.kroah.com/log/2005/10/19/>
+ <http://www.kroah.com/log/2006/01/11/>
+
+NO!!!! No more huge patch bombs to [email protected] people!
+ <http://marc.theaimsgroup.com/?l=linux-kernel&m=112112749912944&w=2>
+
+Kernel Documentation/CodingStyle:
+ <http://sosdg.org/~coywolf/lxr/source/Documentation/CodingStyle>
+
+Linus Torvalds's mail on the canonical patch format:
+ <http://lkml.org/lkml/2005/4/7/183>
+--
--
1.5.3.8

2008-01-25 07:45:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 080/196] kset: convert efivars to use kset_create for the efi subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index ebc3853..018ca1c 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -573,7 +573,7 @@ static struct attribute_group efi_subsys_attr_group = {


static decl_subsys(vars, NULL);
-static decl_subsys(efi, NULL);
+static struct kset *efi_kset;

/*
* efivar_create_sysfs_entry()
@@ -668,15 +668,14 @@ efivars_init(void)
/*
* For now we'll register the efi subsys within this driver
*/
-
- error = firmware_register(&efi_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Firmware registration failed with error %d.\n", error);
+ efi_kset = kset_create_and_add("efi", NULL, &firmware_kset->kobj);
+ if (!efi_kset) {
+ printk(KERN_ERR "efivars: Firmware registration failed.\n");
+ error = -ENOMEM;
goto out_free;
}

- vars_subsys.kobj.kset = &efi_subsys;
+ vars_subsys.kobj.kset = efi_kset;

error = subsystem_register(&vars_subsys);

@@ -728,7 +727,7 @@ efivars_init(void)
" due to error %d\n", error);

/* Don't forget the systab entry */
- error = sysfs_create_group(&efi_subsys.kobj, &efi_subsys_attr_group);
+ error = sysfs_create_group(&efi_kset->kobj, &efi_subsys_attr_group);
if (error)
printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
else
@@ -737,7 +736,7 @@ efivars_init(void)
subsystem_unregister(&vars_subsys);

out_firmware_unregister:
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);

out_free:
kfree(variable_name);
@@ -758,7 +757,7 @@ efivars_exit(void)
}

subsystem_unregister(&vars_subsys);
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);
}

module_init(efivars_init);
--
1.5.3.8

2008-01-25 07:46:06

by Greg KH

[permalink] [raw]
Subject: [PATCH 081/196] kset: convert efivars to use kset_create for the vars sub-subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 018ca1c..e17cd81 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -572,7 +572,7 @@ static struct attribute_group efi_subsys_attr_group = {
};


-static decl_subsys(vars, NULL);
+static struct kset *vars_kset;
static struct kset *efi_kset;

/*
@@ -618,7 +618,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

kobject_set_name(&new_efivar->kobj, "%s", short_name);
- new_efivar->kobj.kset = &vars_subsys;
+ new_efivar->kobj.kset = vars_kset;
new_efivar->kobj.ktype = &efivar_ktype;
i = kobject_register(&new_efivar->kobj);
if (i) {
@@ -675,12 +675,10 @@ efivars_init(void)
goto out_free;
}

- vars_subsys.kobj.kset = efi_kset;
-
- error = subsystem_register(&vars_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Subsystem registration failed with error %d.\n", error);
+ vars_kset = kset_create_and_add("vars", NULL, &efi_kset->kobj);
+ if (!vars_kset) {
+ printk(KERN_ERR "efivars: Subsystem registration failed.\n");
+ error = -ENOMEM;
goto out_firmware_unregister;
}

@@ -715,12 +713,12 @@ efivars_init(void)
* Now add attributes to allow creation of new vars
* and deletion of existing ones...
*/
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_new_var);
if (error)
printk(KERN_ERR "efivars: unable to create new_var sysfs file"
" due to error %d\n", error);
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_del_var);
if (error)
printk(KERN_ERR "efivars: unable to create del_var sysfs file"
@@ -733,7 +731,7 @@ efivars_init(void)
else
goto out_free;

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);

out_firmware_unregister:
kset_unregister(efi_kset);
@@ -756,7 +754,7 @@ efivars_exit(void)
efivar_unregister(entry);
}

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);
kset_unregister(efi_kset);
}

--
1.5.3.8

2008-01-25 07:47:22

by Greg KH

[permalink] [raw]
Subject: [PATCH 080/196] kset: convert efivars to use kset_create for the efi subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index ebc3853..018ca1c 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -573,7 +573,7 @@ static struct attribute_group efi_subsys_attr_group = {


static decl_subsys(vars, NULL);
-static decl_subsys(efi, NULL);
+static struct kset *efi_kset;

/*
* efivar_create_sysfs_entry()
@@ -668,15 +668,14 @@ efivars_init(void)
/*
* For now we'll register the efi subsys within this driver
*/
-
- error = firmware_register(&efi_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Firmware registration failed with error %d.\n", error);
+ efi_kset = kset_create_and_add("efi", NULL, &firmware_kset->kobj);
+ if (!efi_kset) {
+ printk(KERN_ERR "efivars: Firmware registration failed.\n");
+ error = -ENOMEM;
goto out_free;
}

- vars_subsys.kobj.kset = &efi_subsys;
+ vars_subsys.kobj.kset = efi_kset;

error = subsystem_register(&vars_subsys);

@@ -728,7 +727,7 @@ efivars_init(void)
" due to error %d\n", error);

/* Don't forget the systab entry */
- error = sysfs_create_group(&efi_subsys.kobj, &efi_subsys_attr_group);
+ error = sysfs_create_group(&efi_kset->kobj, &efi_subsys_attr_group);
if (error)
printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
else
@@ -737,7 +736,7 @@ efivars_init(void)
subsystem_unregister(&vars_subsys);

out_firmware_unregister:
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);

out_free:
kfree(variable_name);
@@ -758,7 +757,7 @@ efivars_exit(void)
}

subsystem_unregister(&vars_subsys);
- firmware_unregister(&efi_subsys);
+ kset_unregister(efi_kset);
}

module_init(efivars_init);
--
1.5.3.8

2008-01-25 07:47:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 081/196] kset: convert efivars to use kset_create for the vars sub-subsystem.

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 018ca1c..e17cd81 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -572,7 +572,7 @@ static struct attribute_group efi_subsys_attr_group = {
};


-static decl_subsys(vars, NULL);
+static struct kset *vars_kset;
static struct kset *efi_kset;

/*
@@ -618,7 +618,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

kobject_set_name(&new_efivar->kobj, "%s", short_name);
- new_efivar->kobj.kset = &vars_subsys;
+ new_efivar->kobj.kset = vars_kset;
new_efivar->kobj.ktype = &efivar_ktype;
i = kobject_register(&new_efivar->kobj);
if (i) {
@@ -675,12 +675,10 @@ efivars_init(void)
goto out_free;
}

- vars_subsys.kobj.kset = efi_kset;
-
- error = subsystem_register(&vars_subsys);
-
- if (error) {
- printk(KERN_ERR "efivars: Subsystem registration failed with error %d.\n", error);
+ vars_kset = kset_create_and_add("vars", NULL, &efi_kset->kobj);
+ if (!vars_kset) {
+ printk(KERN_ERR "efivars: Subsystem registration failed.\n");
+ error = -ENOMEM;
goto out_firmware_unregister;
}

@@ -715,12 +713,12 @@ efivars_init(void)
* Now add attributes to allow creation of new vars
* and deletion of existing ones...
*/
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_new_var);
if (error)
printk(KERN_ERR "efivars: unable to create new_var sysfs file"
" due to error %d\n", error);
- error = sysfs_create_bin_file(&vars_subsys.kobj,
+ error = sysfs_create_bin_file(&vars_kset->kobj,
&var_subsys_attr_del_var);
if (error)
printk(KERN_ERR "efivars: unable to create del_var sysfs file"
@@ -733,7 +731,7 @@ efivars_init(void)
else
goto out_free;

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);

out_firmware_unregister:
kset_unregister(efi_kset);
@@ -756,7 +754,7 @@ efivars_exit(void)
efivar_unregister(entry);
}

- subsystem_unregister(&vars_subsys);
+ kset_unregister(vars_kset);
kset_unregister(efi_kset);
}

--
1.5.3.8

2008-01-25 07:47:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 082/196] kobject: convert arm/mach-omap1/pm.c to kobj_attr interface

This makes the code a bit simpler and and gets us one step closer to
deleting the deprecated subsys_attr code.

Cc: Kay Sievers <[email protected]>
Cc: Dirk Behme <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/arm/mach-omap1/pm.c | 22 ++++++++--------------
1 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 402113c..63edafb 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -69,14 +69,14 @@ static unsigned int mpui1610_sleep_save[MPUI1610_SLEEP_SAVE_SIZE];

static unsigned short enable_dyn_sleep = 1;

-static ssize_t omap_pm_sleep_while_idle_show(struct kset *kset, char *buf)
+static ssize_t idle_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
return sprintf(buf, "%hu\n", enable_dyn_sleep);
}

-static ssize_t omap_pm_sleep_while_idle_store(struct kset *kset,
- const char * buf,
- size_t n)
+static ssize_t idle_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char * buf, size_t n)
{
unsigned short value;
if (sscanf(buf, "%hu", &value) != 1 ||
@@ -88,14 +88,8 @@ static ssize_t omap_pm_sleep_while_idle_store(struct kset *kset,
return n;
}

-static struct subsys_attribute sleep_while_idle_attr = {
- .attr = {
- .name = __stringify(sleep_while_idle),
- .mode = 0644,
- },
- .show = omap_pm_sleep_while_idle_show,
- .store = omap_pm_sleep_while_idle_store,
-};
+static struct kobj_attribute sleep_while_idle_attr =
+ __ATTR(sleep_while_idle, 0644, idle_show, idle_store);

static void (*omap_sram_idle)(void) = NULL;
static void (*omap_sram_suspend)(unsigned long r0, unsigned long r1) = NULL;
@@ -725,9 +719,9 @@ static int __init omap_pm_init(void)
omap_pm_init_proc();
#endif

- error = subsys_create_file(power_kset, &sleep_while_idle_attr);
+ error = sysfs_create_file(&power_kset->kobj, &sleep_while_idle_attr);
if (error)
- printk(KERN_ERR "subsys_create_file failed: %d\n", error);
+ printk(KERN_ERR "sysfs_create_file failed: %d\n", error);

if (cpu_is_omap16xx()) {
/* configure LOW_PWR pin */
--
1.5.3.8

2008-01-25 07:48:25

by Greg KH

[permalink] [raw]
Subject: [PATCH 083/196] kobject: convert pseries/power.c to kobj_attr interface

This makes the code a bit simpler and and gets us one step closer to
deleting the deprecated subsys_attr code.

Cc: Kay Sievers <[email protected]>
Cc: Manish Ahuja <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/powerpc/platforms/pseries/power.c | 20 ++++++++------------
1 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index c36febe..90706cf 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -28,13 +28,15 @@

unsigned long rtas_poweron_auto; /* default and normal state is 0 */

-static ssize_t auto_poweron_show(struct kset *kset, char *buf)
+static ssize_t auto_poweron_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
return sprintf(buf, "%lu\n", rtas_poweron_auto);
}

-static ssize_t
-auto_poweron_store(struct kset *kset, const char *buf, size_t n)
+static ssize_t auto_poweron_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t n)
{
int ret;
unsigned long ups_restart;
@@ -47,14 +49,8 @@ auto_poweron_store(struct kset *kset, const char *buf, size_t n)
return -EINVAL;
}

-static struct subsys_attribute auto_poweron_attr = {
- .attr = {
- .name = __stringify(auto_poweron),
- .mode = 0644,
- },
- .show = auto_poweron_show,
- .store = auto_poweron_store,
-};
+static struct kobj_attribute auto_poweron_attr =
+ __ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);

#ifndef CONFIG_PM
struct kset *power_kset;
@@ -79,7 +75,7 @@ core_initcall(pm_init);
#else
static int __init apo_pm_init(void)
{
- return (subsys_create_file(power_kset, &auto_poweron_attr));
+ return (sysfs_create_file(&power_kset->kobj, &auto_poweron_attr));
}
__initcall(apo_pm_init);
#endif
--
1.5.3.8

2008-01-25 07:48:41

by Greg KH

[permalink] [raw]
Subject: [PATCH 084/196] kobject: convert s390 ipl.c to kobj_attr interface

This makes the code a bit simpler and and gets us one step closer to
deleting the deprecated subsys_attr code.

NOTE, this needs the next patch in the series in order to work properly.
This will build, but the sysfs files will not properly operate.

Thanks to Cornelia for the build fix on this patch.

Cc: Kay Sievers <[email protected]>
Cc: Michael Holzheu <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Volker Sameske <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/s390/kernel/ipl.c | 80 ++++++++++++++++++++++++++++-------------------
1 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index cae793a..50be9d0 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -162,22 +162,25 @@ EXPORT_SYMBOL_GPL(diag308);
/* SYSFS */

#define DEFINE_IPL_ATTR_RO(_prefix, _name, _format, _value) \
-static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \
+static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
+ struct kobj_attribute *attr, \
char *page) \
{ \
return sprintf(page, _format, _value); \
} \
-static struct subsys_attribute sys_##_prefix##_##_name##_attr = \
+static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
__ATTR(_name, S_IRUGO, sys_##_prefix##_##_name##_show, NULL);

#define DEFINE_IPL_ATTR_RW(_prefix, _name, _fmt_out, _fmt_in, _value) \
-static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \
+static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
+ struct kobj_attribute *attr, \
char *page) \
{ \
return sprintf(page, _fmt_out, \
(unsigned long long) _value); \
} \
-static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \
+static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
+ struct kobj_attribute *attr, \
const char *buf, size_t len) \
{ \
unsigned long long value; \
@@ -186,25 +189,27 @@ static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \
_value = value; \
return len; \
} \
-static struct subsys_attribute sys_##_prefix##_##_name##_attr = \
+static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
__ATTR(_name,(S_IRUGO | S_IWUSR), \
sys_##_prefix##_##_name##_show, \
sys_##_prefix##_##_name##_store);

#define DEFINE_IPL_ATTR_STR_RW(_prefix, _name, _fmt_out, _fmt_in, _value)\
-static ssize_t sys_##_prefix##_##_name##_show(struct kset *kset, \
+static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \
+ struct kobj_attribute *attr, \
char *page) \
{ \
return sprintf(page, _fmt_out, _value); \
} \
-static ssize_t sys_##_prefix##_##_name##_store(struct kset *kset, \
+static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
+ struct kobj_attribute *attr, \
const char *buf, size_t len) \
{ \
if (sscanf(buf, _fmt_in, _value) != 1) \
return -EINVAL; \
return len; \
} \
-static struct subsys_attribute sys_##_prefix##_##_name##_attr = \
+static struct kobj_attribute sys_##_prefix##_##_name##_attr = \
__ATTR(_name,(S_IRUGO | S_IWUSR), \
sys_##_prefix##_##_name##_show, \
sys_##_prefix##_##_name##_store);
@@ -270,14 +275,16 @@ void __init setup_ipl_info(void)
struct ipl_info ipl_info;
EXPORT_SYMBOL_GPL(ipl_info);

-static ssize_t ipl_type_show(struct kset *kset, char *page)
+static ssize_t ipl_type_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *page)
{
return sprintf(page, "%s\n", ipl_type_str(ipl_info.type));
}

-static struct subsys_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);
+static struct kobj_attribute sys_ipl_type_attr = __ATTR_RO(ipl_type);

-static ssize_t sys_ipl_device_show(struct kset *kset, char *page)
+static ssize_t sys_ipl_device_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
struct ipl_parameter_block *ipl = IPL_PARMBLOCK_START;

@@ -292,7 +299,7 @@ static ssize_t sys_ipl_device_show(struct kset *kset, char *page)
}
}

-static struct subsys_attribute sys_ipl_device_attr =
+static struct kobj_attribute sys_ipl_device_attr =
__ATTR(device, S_IRUGO, sys_ipl_device_show, NULL);

static ssize_t ipl_parameter_read(struct kobject *kobj, struct bin_attribute *attr,
@@ -367,7 +374,8 @@ static struct attribute_group ipl_fcp_attr_group = {

/* CCW ipl device attributes */

-static ssize_t ipl_ccw_loadparm_show(struct kset *kset, char *page)
+static ssize_t ipl_ccw_loadparm_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
char loadparm[LOADPARM_LEN + 1] = {};

@@ -379,7 +387,7 @@ static ssize_t ipl_ccw_loadparm_show(struct kset *kset, char *page)
return sprintf(page, "%s\n", loadparm);
}

-static struct subsys_attribute sys_ipl_ccw_loadparm_attr =
+static struct kobj_attribute sys_ipl_ccw_loadparm_attr =
__ATTR(loadparm, 0444, ipl_ccw_loadparm_show, NULL);

static struct attribute *ipl_ccw_attrs[] = {
@@ -465,7 +473,8 @@ static void reipl_get_ascii_loadparm(char *loadparm)
strstrip(loadparm);
}

-static ssize_t reipl_ccw_loadparm_show(struct kset *kset, char *page)
+static ssize_t reipl_ccw_loadparm_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
char buf[LOADPARM_LEN + 1];

@@ -473,7 +482,8 @@ static ssize_t reipl_ccw_loadparm_show(struct kset *kset, char *page)
return sprintf(page, "%s\n", buf);
}

-static ssize_t reipl_ccw_loadparm_store(struct kset *kset,
+static ssize_t reipl_ccw_loadparm_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
const char *buf, size_t len)
{
int i, lp_len;
@@ -500,7 +510,7 @@ static ssize_t reipl_ccw_loadparm_store(struct kset *kset,
return len;
}

-static struct subsys_attribute sys_reipl_ccw_loadparm_attr =
+static struct kobj_attribute sys_reipl_ccw_loadparm_attr =
__ATTR(loadparm, 0644, reipl_ccw_loadparm_show,
reipl_ccw_loadparm_store);

@@ -568,13 +578,15 @@ static int reipl_set_type(enum ipl_type type)
return 0;
}

-static ssize_t reipl_type_show(struct kset *kset, char *page)
+static ssize_t reipl_type_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
return sprintf(page, "%s\n", ipl_type_str(reipl_type));
}

-static ssize_t reipl_type_store(struct kset *kset, const char *buf,
- size_t len)
+static ssize_t reipl_type_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t len)
{
int rc = -EINVAL;

@@ -587,7 +599,7 @@ static ssize_t reipl_type_store(struct kset *kset, const char *buf,
return (rc != 0) ? rc : len;
}

-static struct subsys_attribute reipl_type_attr =
+static struct kobj_attribute reipl_type_attr =
__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);

static decl_subsys(reipl, NULL);
@@ -663,13 +675,15 @@ static int dump_set_type(enum dump_type type)
return 0;
}

-static ssize_t dump_type_show(struct kset *kset, char *page)
+static ssize_t dump_type_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
return sprintf(page, "%s\n", dump_type_str(dump_type));
}

-static ssize_t dump_type_store(struct kset *kset, const char *buf,
- size_t len)
+static ssize_t dump_type_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t len)
{
int rc = -EINVAL;

@@ -682,7 +696,7 @@ static ssize_t dump_type_store(struct kset *kset, const char *buf,
return (rc != 0) ? rc : len;
}

-static struct subsys_attribute dump_type_attr =
+static struct kobj_attribute dump_type_attr =
__ATTR(dump_type, 0644, dump_type_show, dump_type_store);

static decl_subsys(dump, NULL);
@@ -695,13 +709,15 @@ static decl_subsys(shutdown_actions, NULL);

/* on panic */

-static ssize_t on_panic_show(struct kset *kset, char *page)
+static ssize_t on_panic_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *page)
{
return sprintf(page, "%s\n", shutdown_action_str(on_panic_action));
}

-static ssize_t on_panic_store(struct kset *kset, const char *buf,
- size_t len)
+static ssize_t on_panic_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t len)
{
if (strncmp(buf, SHUTDOWN_REIPL_STR, strlen(SHUTDOWN_REIPL_STR)) == 0)
on_panic_action = SHUTDOWN_REIPL;
@@ -717,7 +733,7 @@ static ssize_t on_panic_store(struct kset *kset, const char *buf,
return len;
}

-static struct subsys_attribute on_panic_attr =
+static struct kobj_attribute on_panic_attr =
__ATTR(on_panic, 0644, on_panic_show, on_panic_store);

void do_reipl(void)
@@ -961,7 +977,7 @@ static int __init reipl_init(void)
rc = firmware_register(&reipl_subsys);
if (rc)
return rc;
- rc = subsys_create_file(&reipl_subsys, &reipl_type_attr);
+ rc = sysfs_create_file(&reipl_subsys.kobj, &reipl_type_attr.attr);
if (rc) {
firmware_unregister(&reipl_subsys);
return rc;
@@ -1050,7 +1066,7 @@ static int __init dump_init(void)
rc = firmware_register(&dump_subsys);
if (rc)
return rc;
- rc = subsys_create_file(&dump_subsys, &dump_type_attr);
+ rc = sysfs_create_file(&dump_subsys.kobj, &dump_type_attr.attr);
if (rc) {
firmware_unregister(&dump_subsys);
return rc;
@@ -1072,7 +1088,7 @@ static int __init shutdown_actions_init(void)
rc = firmware_register(&shutdown_actions_subsys);
if (rc)
return rc;
- rc = subsys_create_file(&shutdown_actions_subsys, &on_panic_attr);
+ rc = sysfs_create_file(&shutdown_actions_subsys.kobj, &on_panic_attr.attr);
if (rc) {
firmware_unregister(&shutdown_actions_subsys);
return rc;
--
1.5.3.8

2008-01-25 07:49:04

by Greg KH

[permalink] [raw]
Subject: [PATCH 085/196] kset: convert s390 ipl.c to use kset_create

Dynamically create the kset instead of declaring it statically.
This makes the kobject attributes now work properly that I broke in the
previous patch.

Cc: Kay Sievers <[email protected]>
Cc: Michael Holzheu <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Volker Sameske <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/s390/kernel/ipl.c | 73 ++++++++++++++++++++++++-----------------------
1 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index 50be9d0..c8179fc 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -426,7 +426,7 @@ static struct attribute_group ipl_unknown_attr_group = {
.attrs = ipl_unknown_attrs,
};

-static decl_subsys(ipl, NULL);
+static struct kset *ipl_kset;

/*
* reipl section
@@ -602,7 +602,7 @@ static ssize_t reipl_type_store(struct kobject *kobj,
static struct kobj_attribute reipl_type_attr =
__ATTR(reipl_type, 0644, reipl_type_show, reipl_type_store);

-static decl_subsys(reipl, NULL);
+static struct kset *reipl_kset;

/*
* dump section
@@ -699,13 +699,13 @@ static ssize_t dump_type_store(struct kobject *kobj,
static struct kobj_attribute dump_type_attr =
__ATTR(dump_type, 0644, dump_type_show, dump_type_store);

-static decl_subsys(dump, NULL);
+static struct kset *dump_kset;

/*
* Shutdown actions section
*/

-static decl_subsys(shutdown_actions, NULL);
+static struct kset *shutdown_actions_kset;

/* on panic */

@@ -830,23 +830,23 @@ static int __init ipl_register_fcp_files(void)
{
int rc;

- rc = sysfs_create_group(&ipl_subsys.kobj,
+ rc = sysfs_create_group(&ipl_kset->kobj,
&ipl_fcp_attr_group);
if (rc)
goto out;
- rc = sysfs_create_bin_file(&ipl_subsys.kobj,
+ rc = sysfs_create_bin_file(&ipl_kset->kobj,
&ipl_parameter_attr);
if (rc)
goto out_ipl_parm;
- rc = sysfs_create_bin_file(&ipl_subsys.kobj,
+ rc = sysfs_create_bin_file(&ipl_kset->kobj,
&ipl_scp_data_attr);
if (!rc)
goto out;

- sysfs_remove_bin_file(&ipl_subsys.kobj, &ipl_parameter_attr);
+ sysfs_remove_bin_file(&ipl_kset->kobj, &ipl_parameter_attr);

out_ipl_parm:
- sysfs_remove_group(&ipl_subsys.kobj, &ipl_fcp_attr_group);
+ sysfs_remove_group(&ipl_kset->kobj, &ipl_fcp_attr_group);
out:
return rc;
}
@@ -855,12 +855,12 @@ static int __init ipl_init(void)
{
int rc;

- rc = firmware_register(&ipl_subsys);
- if (rc)
- return rc;
+ ipl_kset = kset_create_and_add("ipl", NULL, &firmware_kset->kobj);
+ if (!ipl_kset)
+ return -ENOMEM;
switch (ipl_info.type) {
case IPL_TYPE_CCW:
- rc = sysfs_create_group(&ipl_subsys.kobj,
+ rc = sysfs_create_group(&ipl_kset->kobj,
&ipl_ccw_attr_group);
break;
case IPL_TYPE_FCP:
@@ -868,16 +868,16 @@ static int __init ipl_init(void)
rc = ipl_register_fcp_files();
break;
case IPL_TYPE_NSS:
- rc = sysfs_create_group(&ipl_subsys.kobj,
+ rc = sysfs_create_group(&ipl_kset->kobj,
&ipl_nss_attr_group);
break;
default:
- rc = sysfs_create_group(&ipl_subsys.kobj,
+ rc = sysfs_create_group(&ipl_kset->kobj,
&ipl_unknown_attr_group);
break;
}
if (rc)
- firmware_unregister(&ipl_subsys);
+ kset_unregister(ipl_kset);
return rc;
}

@@ -899,7 +899,7 @@ static int __init reipl_nss_init(void)

if (!MACHINE_IS_VM)
return 0;
- rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_nss_attr_group);
+ rc = sysfs_create_group(&reipl_kset->kobj, &reipl_nss_attr_group);
if (rc)
return rc;
strncpy(reipl_nss_name, kernel_nss_name, NSS_NAME_SIZE + 1);
@@ -914,7 +914,7 @@ static int __init reipl_ccw_init(void)
reipl_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
if (!reipl_block_ccw)
return -ENOMEM;
- rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_ccw_attr_group);
+ rc = sysfs_create_group(&reipl_kset->kobj, &reipl_ccw_attr_group);
if (rc) {
free_page((unsigned long)reipl_block_ccw);
return rc;
@@ -952,7 +952,7 @@ static int __init reipl_fcp_init(void)
reipl_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
if (!reipl_block_fcp)
return -ENOMEM;
- rc = sysfs_create_group(&reipl_subsys.kobj, &reipl_fcp_attr_group);
+ rc = sysfs_create_group(&reipl_kset->kobj, &reipl_fcp_attr_group);
if (rc) {
free_page((unsigned long)reipl_block_fcp);
return rc;
@@ -974,12 +974,12 @@ static int __init reipl_init(void)
{
int rc;

- rc = firmware_register(&reipl_subsys);
- if (rc)
- return rc;
- rc = sysfs_create_file(&reipl_subsys.kobj, &reipl_type_attr.attr);
+ reipl_kset = kset_create_and_add("reipl", NULL, &firmware_kset->kobj);
+ if (!reipl_kset)
+ return -ENOMEM;
+ rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
if (rc) {
- firmware_unregister(&reipl_subsys);
+ kset_unregister(reipl_kset);
return rc;
}
rc = reipl_ccw_init();
@@ -1004,7 +1004,7 @@ static int __init dump_ccw_init(void)
dump_block_ccw = (void *) get_zeroed_page(GFP_KERNEL);
if (!dump_block_ccw)
return -ENOMEM;
- rc = sysfs_create_group(&dump_subsys.kobj, &dump_ccw_attr_group);
+ rc = sysfs_create_group(&dump_kset->kobj, &dump_ccw_attr_group);
if (rc) {
free_page((unsigned long)dump_block_ccw);
return rc;
@@ -1028,7 +1028,7 @@ static int __init dump_fcp_init(void)
dump_block_fcp = (void *) get_zeroed_page(GFP_KERNEL);
if (!dump_block_fcp)
return -ENOMEM;
- rc = sysfs_create_group(&dump_subsys.kobj, &dump_fcp_attr_group);
+ rc = sysfs_create_group(&dump_kset->kobj, &dump_fcp_attr_group);
if (rc) {
free_page((unsigned long)dump_block_fcp);
return rc;
@@ -1063,12 +1063,12 @@ static int __init dump_init(void)
{
int rc;

- rc = firmware_register(&dump_subsys);
- if (rc)
- return rc;
- rc = sysfs_create_file(&dump_subsys.kobj, &dump_type_attr.attr);
+ dump_kset = kset_create_and_add("dump", NULL, &firmware_kset->kobj);
+ if (!dump_kset)
+ return -ENOMEM;
+ rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr);
if (rc) {
- firmware_unregister(&dump_subsys);
+ kset_unregister(dump_kset);
return rc;
}
rc = dump_ccw_init();
@@ -1085,12 +1085,13 @@ static int __init shutdown_actions_init(void)
{
int rc;

- rc = firmware_register(&shutdown_actions_subsys);
- if (rc)
- return rc;
- rc = sysfs_create_file(&shutdown_actions_subsys.kobj, &on_panic_attr.attr);
+ shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
+ &firmware_kset->kobj);
+ if (!shutdown_actions_kset)
+ return -ENOMEM;
+ rc = sysfs_create_file(&shutdown_actions_kset->kobj, &on_panic_attr);
if (rc) {
- firmware_unregister(&shutdown_actions_subsys);
+ kset_unregister(shutdown_actions_kset);
return rc;
}
atomic_notifier_chain_register(&panic_notifier_list,
--
1.5.3.8

2008-01-25 07:49:35

by Greg KH

[permalink] [raw]
Subject: [PATCH 086/196] kobject: convert parisc/pdc_stable to kobj_attr interface

This makes the code a bit simpler and and gets us one step closer to
deleting the deprecated subsys_attr code.

NOTE, this needs the next patch in the series in order to work properly.
This will build, but the sysfs files will not properly operate.

Cc: Kay Sievers <[email protected]>
Cc: Thibaut VARENE <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Grant Grundler <[email protected]>
Cc: Kyle McMartin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/parisc/pdc_stable.c | 147 ++++++++++++++++++++----------------------
1 files changed, 70 insertions(+), 77 deletions(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 1382be6..e1b9cba 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -120,7 +120,7 @@ struct pdcspath_entry pdcspath_entry_##_name = { \
};

#define PDCS_ATTR(_name, _mode, _show, _store) \
-struct subsys_attribute pdcs_attr_##_name = { \
+struct kobj_attribute pdcs_attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode}, \
.show = _show, \
.store = _store, \
@@ -523,15 +523,15 @@ static struct pdcspath_entry *pdcspath_entries[] = {

/**
* pdcs_size_read - Stable Storage size output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*/
-static ssize_t
-pdcs_size_read(struct kset *kset, char *buf)
+static ssize_t pdcs_size_read(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
{
char *out = buf;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

/* show the size of the stable storage */
@@ -542,17 +542,17 @@ pdcs_size_read(struct kset *kset, char *buf)

/**
* pdcs_auto_read - Stable Storage autoboot/search flag output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
* @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
*/
-static ssize_t
-pdcs_auto_read(struct kset *kset, char *buf, int knob)
+static ssize_t pdcs_auto_read(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf, int knob)
{
char *out = buf;
struct pdcspath_entry *pathentry;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

/* Current flags are stored in primary boot path entry */
@@ -568,40 +568,37 @@ pdcs_auto_read(struct kset *kset, char *buf, int knob)

/**
* pdcs_autoboot_read - Stable Storage autoboot flag output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*/
-static inline ssize_t
-pdcs_autoboot_read(struct kset *kset, char *buf)
+static ssize_t pdcs_autoboot_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return pdcs_auto_read(kset, buf, PF_AUTOBOOT);
+ return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT);
}

/**
* pdcs_autosearch_read - Stable Storage autoboot flag output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*/
-static inline ssize_t
-pdcs_autosearch_read(struct kset *kset, char *buf)
+static ssize_t pdcs_autosearch_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
- return pdcs_auto_read(kset, buf, PF_AUTOSEARCH);
+ return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH);
}

/**
* pdcs_timer_read - Stable Storage timer count output (in seconds).
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*
* The value of the timer field correponds to a number of seconds in powers of 2.
*/
-static ssize_t
-pdcs_timer_read(struct kset *kset, char *buf)
+static ssize_t pdcs_timer_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;
struct pdcspath_entry *pathentry;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

/* Current flags are stored in primary boot path entry */
@@ -618,15 +615,14 @@ pdcs_timer_read(struct kset *kset, char *buf)

/**
* pdcs_osid_read - Stable Storage OS ID register output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*/
-static ssize_t
-pdcs_osid_read(struct kset *kset, char *buf)
+static ssize_t pdcs_osid_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

out += sprintf(out, "%s dependent data (0x%.4x)\n",
@@ -637,18 +633,17 @@ pdcs_osid_read(struct kset *kset, char *buf)

/**
* pdcs_osdep1_read - Stable Storage OS-Dependent data area 1 output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*
* This can hold 16 bytes of OS-Dependent data.
*/
-static ssize_t
-pdcs_osdep1_read(struct kset *kset, char *buf)
+static ssize_t pdcs_osdep1_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;
u32 result[4];

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK)
@@ -664,18 +659,17 @@ pdcs_osdep1_read(struct kset *kset, char *buf)

/**
* pdcs_diagnostic_read - Stable Storage Diagnostic register output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*
* I have NFC how to interpret the content of that register ;-).
*/
-static ssize_t
-pdcs_diagnostic_read(struct kset *kset, char *buf)
+static ssize_t pdcs_diagnostic_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;
u32 result;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

/* get diagnostic */
@@ -689,18 +683,17 @@ pdcs_diagnostic_read(struct kset *kset, char *buf)

/**
* pdcs_fastsize_read - Stable Storage FastSize register output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*
* This register holds the amount of system RAM to be tested during boot sequence.
*/
-static ssize_t
-pdcs_fastsize_read(struct kset *kset, char *buf)
+static ssize_t pdcs_fastsize_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;
u32 result;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

/* get fast-size */
@@ -718,13 +711,12 @@ pdcs_fastsize_read(struct kset *kset, char *buf)

/**
* pdcs_osdep2_read - Stable Storage OS-Dependent data area 2 output.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The output buffer to write to.
*
* This can hold pdcs_size - 224 bytes of OS-Dependent data, when available.
*/
-static ssize_t
-pdcs_osdep2_read(struct kset *kset, char *buf)
+static ssize_t pdcs_osdep2_read(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
{
char *out = buf;
unsigned long size;
@@ -736,7 +728,7 @@ pdcs_osdep2_read(struct kset *kset, char *buf)

size = pdcs_size - 224;

- if (!kset || !buf)
+ if (!buf)
return -EINVAL;

for (i=0; i<size; i+=4) {
@@ -751,7 +743,6 @@ pdcs_osdep2_read(struct kset *kset, char *buf)

/**
* pdcs_auto_write - This function handles autoboot/search flag modifying.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The input buffer to read from.
* @count: The number of bytes to be read.
* @knob: The PF_AUTOBOOT or PF_AUTOSEARCH flag
@@ -760,8 +751,9 @@ pdcs_osdep2_read(struct kset *kset, char *buf)
* We expect a precise syntax:
* \"n\" (n == 0 or 1) to toggle AutoBoot Off or On
*/
-static ssize_t
-pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob)
+static ssize_t pdcs_auto_write(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf,
+ size_t count, int knob)
{
struct pdcspath_entry *pathentry;
unsigned char flags;
@@ -771,7 +763,7 @@ pdcs_auto_write(struct kset *kset, const char *buf, size_t count, int knob)
if (!capable(CAP_SYS_ADMIN))
return -EACCES;

- if (!kset || !buf || !count)
+ if (!buf || !count)
return -EINVAL;

/* We'll use a local copy of buf */
@@ -826,7 +818,6 @@ parse_error:

/**
* pdcs_autoboot_write - This function handles autoboot flag modifying.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The input buffer to read from.
* @count: The number of bytes to be read.
*
@@ -834,15 +825,15 @@ parse_error:
* We expect a precise syntax:
* \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
*/
-static inline ssize_t
-pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count)
+static ssize_t pdcs_autoboot_write(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
- return pdcs_auto_write(kset, buf, count, PF_AUTOBOOT);
+ return pdcs_auto_write(kset, attr, buf, count, PF_AUTOBOOT);
}

/**
* pdcs_autosearch_write - This function handles autosearch flag modifying.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The input buffer to read from.
* @count: The number of bytes to be read.
*
@@ -850,15 +841,15 @@ pdcs_autoboot_write(struct kset *kset, const char *buf, size_t count)
* We expect a precise syntax:
* \"n\" (n == 0 or 1) to toggle AutoSearch Off or On
*/
-static inline ssize_t
-pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count)
+static ssize_t pdcs_autosearch_write(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
- return pdcs_auto_write(kset, buf, count, PF_AUTOSEARCH);
+ return pdcs_auto_write(kset, attr, buf, count, PF_AUTOSEARCH);
}

/**
* pdcs_osdep1_write - Stable Storage OS-Dependent data area 1 input.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The input buffer to read from.
* @count: The number of bytes to be read.
*
@@ -866,15 +857,16 @@ pdcs_autosearch_write(struct kset *kset, const char *buf, size_t count)
* write approach. It's up to userspace to deal with it when constructing
* its input buffer.
*/
-static ssize_t
-pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)
+static ssize_t pdcs_osdep1_write(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
u8 in[16];

if (!capable(CAP_SYS_ADMIN))
return -EACCES;

- if (!kset || !buf || !count)
+ if (!buf || !count)
return -EINVAL;

if (unlikely(pdcs_osid != OS_ID_LINUX))
@@ -895,7 +887,6 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)

/**
* pdcs_osdep2_write - Stable Storage OS-Dependent data area 2 input.
- * @kset: An allocated and populated struct kset. We don't use it tho.
* @buf: The input buffer to read from.
* @count: The number of bytes to be read.
*
@@ -903,8 +894,9 @@ pdcs_osdep1_write(struct kset *kset, const char *buf, size_t count)
* byte-by-byte write approach. It's up to userspace to deal with it when
* constructing its input buffer.
*/
-static ssize_t
-pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count)
+static ssize_t pdcs_osdep2_write(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
{
unsigned long size;
unsigned short i;
@@ -913,7 +905,7 @@ pdcs_osdep2_write(struct kset *kset, const char *buf, size_t count)
if (!capable(CAP_SYS_ADMIN))
return -EACCES;

- if (!kset || !buf || !count)
+ if (!buf || !count)
return -EINVAL;

if (unlikely(pdcs_size <= 224))
@@ -951,19 +943,23 @@ static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL);
static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL);
static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write);

-static struct subsys_attribute *pdcs_subsys_attrs[] = {
- &pdcs_attr_size,
- &pdcs_attr_autoboot,
- &pdcs_attr_autosearch,
- &pdcs_attr_timer,
- &pdcs_attr_osid,
- &pdcs_attr_osdep1,
- &pdcs_attr_diagnostic,
- &pdcs_attr_fastsize,
- &pdcs_attr_osdep2,
+static struct attribute *pdcs_subsys_attrs[] = {
+ &pdcs_attr_size.attr,
+ &pdcs_attr_autoboot.attr,
+ &pdcs_attr_autosearch.attr,
+ &pdcs_attr_timer.attr,
+ &pdcs_attr_osid.attr,
+ &pdcs_attr_osdep1.attr,
+ &pdcs_attr_diagnostic.attr,
+ &pdcs_attr_fastsize.attr,
+ &pdcs_attr_osdep2.attr,
NULL,
};

+static struct attribute_group pdcs_attr_group = {
+ .attrs = pdcs_subsys_attrs,
+};
+
static decl_subsys(paths, NULL);
static decl_subsys(stable, NULL);

@@ -1042,8 +1038,7 @@ pdcs_unregister_pathentries(void)
static int __init
pdc_stable_init(void)
{
- struct subsys_attribute *attr;
- int i, rc = 0, error = 0;
+ int rc = 0, error = 0;
u32 result;

/* find the size of the stable storage */
@@ -1068,10 +1063,8 @@ pdc_stable_init(void)
goto fail_firmreg;

/* Don't forget the root entries */
- for (i = 0; (attr = pdcs_subsys_attrs[i]) && !error; i++)
- if (attr->show)
- error = subsys_create_file(&stable_subsys, attr);
-
+ error = sysfs_create_group(&stable_subsys.kobj, pdcs_attr_group);
+
/* register the paths subsys as a subsystem of stable subsys */
paths_subsys.kobj.kset = &stable_subsys;
if ((rc = subsystem_register(&paths_subsys)))
--
1.5.3.8

2008-01-25 07:49:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 087/196] kset: convert parisc/pdc_stable.c to use kset_create

Dynamically create the kset instead of declaring it statically.
This makes the kobject attributes now work properly that I broke in the
previous patch.

Cc: Kay Sievers <[email protected]>
Cc: Thibaut VARENE <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Grant Grundler <[email protected]>
Cc: Kyle McMartin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/parisc/pdc_stable.c | 38 +++++++++++++++++++++-----------------
1 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index e1b9cba..4444834 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -960,8 +960,8 @@ static struct attribute_group pdcs_attr_group = {
.attrs = pdcs_subsys_attrs,
};

-static decl_subsys(paths, NULL);
-static decl_subsys(stable, NULL);
+static struct kset *stable_kset;
+static struct kset *paths_kset;

/**
* pdcs_register_pathentries - Prepares path entries kobjects for sysfs usage.
@@ -993,7 +993,7 @@ pdcs_register_pathentries(void)

if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
return err;
- entry->kobj.kset = &paths_subsys;
+ entry->kobj.kset = paths_kset;
entry->kobj.ktype = &ktype_pdcspath;
if ((err = kobject_register(&entry->kobj)))
return err;
@@ -1058,19 +1058,24 @@ pdc_stable_init(void)
/* the actual result is 16 bits away */
pdcs_osid = (u16)(result >> 16);

- /* For now we'll register the stable subsys within this driver */
- if ((rc = firmware_register(&stable_subsys)))
+ /* For now we'll register the stable kset within this driver */
+ stable_kset = kset_create_and_add("stable", NULL, &firmware_kset->kobj);
+ if (!stable_kset) {
+ rc = -ENOMEM;
goto fail_firmreg;
+ }

/* Don't forget the root entries */
- error = sysfs_create_group(&stable_subsys.kobj, pdcs_attr_group);
+ error = sysfs_create_group(&stable_kset->kobj, pdcs_attr_group);

- /* register the paths subsys as a subsystem of stable subsys */
- paths_subsys.kobj.kset = &stable_subsys;
- if ((rc = subsystem_register(&paths_subsys)))
- goto fail_subsysreg;
+ /* register the paths kset as a child of the stable kset */
+ paths_kset = kset_create_and_add("paths", NULL, &stable_kset->kobj);
+ if (!paths_kset) {
+ rc = -ENOMEM;
+ goto fail_ksetreg;
+ }

- /* now we create all "files" for the paths subsys */
+ /* now we create all "files" for the paths kset */
if ((rc = pdcs_register_pathentries()))
goto fail_pdcsreg;

@@ -1078,10 +1083,10 @@ pdc_stable_init(void)

fail_pdcsreg:
pdcs_unregister_pathentries();
- subsystem_unregister(&paths_subsys);
+ kset_unregister(paths_kset);

-fail_subsysreg:
- firmware_unregister(&stable_subsys);
+fail_ksetreg:
+ kset_unregister(stable_kset);

fail_firmreg:
printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1092,9 +1097,8 @@ static void __exit
pdc_stable_exit(void)
{
pdcs_unregister_pathentries();
- subsystem_unregister(&paths_subsys);
-
- firmware_unregister(&stable_subsys);
+ kset_unregister(paths_kset);
+ kset_unregister(stable_kset);
}


--
1.5.3.8

2008-01-25 07:50:43

by Greg KH

[permalink] [raw]
Subject: [PATCH 088/196] Driver Core: kill subsys_attribute and default sysfs ops

From: Kay Sievers <[email protected]>

Remove the no longer needed subsys_attributes, they are all converted to
the more sensical kobj_attributes.

There is no longer a magic fallback in sysfs attribute operations, all
kobjects which create simple attributes need explicitely a ktype
assigned, which tells the core what was intended here.

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/sysfs/file.c | 63 +++++++---------------------------------------
include/linux/kobject.h | 9 ------
lib/kobject.c | 21 ---------------
3 files changed, 10 insertions(+), 83 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 387a636..8acf82b 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -20,43 +20,6 @@

#include "sysfs.h"

-#define to_sattr(a) container_of(a,struct subsys_attribute, attr)
-
-/*
- * Subsystem file operations.
- * These operations allow subsystems to have files that can be
- * read/written.
- */
-static ssize_t
-subsys_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
-{
- struct kset *kset = to_kset(kobj);
- struct subsys_attribute * sattr = to_sattr(attr);
- ssize_t ret = -EIO;
-
- if (sattr->show)
- ret = sattr->show(kset, page);
- return ret;
-}
-
-static ssize_t
-subsys_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * page, size_t count)
-{
- struct kset *kset = to_kset(kobj);
- struct subsys_attribute * sattr = to_sattr(attr);
- ssize_t ret = -EIO;
-
- if (sattr->store)
- ret = sattr->store(kset, page, count);
- return ret;
-}
-
-static struct sysfs_ops subsys_sysfs_ops = {
- .show = subsys_attr_show,
- .store = subsys_attr_store,
-};
-
/*
* There's one sysfs_buffer for each open file and one
* sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -354,29 +317,23 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
{
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
- struct sysfs_buffer * buffer;
- struct sysfs_ops * ops = NULL;
- int error;
+ struct sysfs_buffer *buffer;
+ struct sysfs_ops *ops;
+ int error = -EACCES;

/* need attr_sd for attr and ops, its parent for kobj */
if (!sysfs_get_active_two(attr_sd))
return -ENODEV;

- /* if the kobject has no ktype, then we assume that it is a subsystem
- * itself, and use ops for it.
- */
- if (kobj->ktype)
+ /* every kobject with an attribute needs a ktype assigned */
+ if (kobj->ktype && kobj->ktype->sysfs_ops)
ops = kobj->ktype->sysfs_ops;
- else
- ops = &subsys_sysfs_ops;
-
- error = -EACCES;
-
- /* No sysfs operations, either from having no subsystem,
- * or the subsystem have no operations.
- */
- if (!ops)
+ else {
+ printk(KERN_ERR "missing sysfs attribute operations for "
+ "kobject: %s\n", kobject_name(kobj));
+ WARN_ON(1);
goto err_out;
+ }

/* File needs write support.
* The inode's perms must say it's ok,
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 29dc444..29841bb 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -216,15 +216,6 @@ extern struct kset *firmware_kset;
extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);

-struct subsys_attribute {
- struct attribute attr;
- ssize_t (*show)(struct kset *, char *);
- ssize_t (*store)(struct kset *, const char *, size_t);
-};
-
-extern int __must_check subsys_create_file(struct kset *,
- struct subsys_attribute *);
-
#if defined(CONFIG_HOTPLUG)
int kobject_uevent(struct kobject *kobj, enum kobject_action action);
int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
diff --git a/lib/kobject.c b/lib/kobject.c
index 99f6354..c742ac2 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -810,26 +810,6 @@ void subsystem_unregister(struct kset *s)
kset_unregister(s);
}

-/**
- * subsystem_create_file - export sysfs attribute file.
- * @s: subsystem.
- * @a: subsystem attribute descriptor.
- */
-
-int subsys_create_file(struct kset *s, struct subsys_attribute *a)
-{
- int error = 0;
-
- if (!s || !a)
- return -EINVAL;
-
- if (kset_get(s)) {
- error = sysfs_create_file(&s->kobj, &a->attr);
- kset_put(s);
- }
- return error;
-}
-
static void kset_release(struct kobject *kobj)
{
struct kset *kset = container_of(kobj, struct kset, kobj);
@@ -927,4 +907,3 @@ EXPORT_SYMBOL(kset_unregister);

EXPORT_SYMBOL(subsystem_register);
EXPORT_SYMBOL(subsystem_unregister);
-EXPORT_SYMBOL(subsys_create_file);
--
1.5.3.8

2008-01-25 07:50:59

by Greg KH

[permalink] [raw]
Subject: [PATCH 089/196] kset: convert edd to use kset_create

Dynamically create the kset instead of declaring it statically.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/edd.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index fc567fa..f07f370 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -631,7 +631,7 @@ static struct kobj_type edd_ktype = {
.default_attrs = def_attrs,
};

-static decl_subsys(edd, NULL);
+static struct kset *edd_kset;


/**
@@ -723,7 +723,7 @@ edd_device_register(struct edd_device *edev, int i)
edd_dev_set_info(edev, i);
kobject_set_name(&edev->kobj, "int13_dev%02x",
0x80 + i);
- edev->kobj.kset = &edd_subsys;
+ edev->kobj.kset = edd_kset;
edev->kobj.ktype = &edd_ktype;
error = kobject_register(&edev->kobj);
if (!error)
@@ -756,9 +756,9 @@ edd_init(void)
return 1;
}

- rc = firmware_register(&edd_subsys);
- if (rc)
- return rc;
+ edd_kset = kset_create_and_add("edd", NULL, &firmware_kset->kobj);
+ if (!edd_kset)
+ return -ENOMEM;

for (i = 0; i < edd_num_devices() && !rc; i++) {
edev = kzalloc(sizeof (*edev), GFP_KERNEL);
@@ -774,7 +774,7 @@ edd_init(void)
}

if (rc)
- firmware_unregister(&edd_subsys);
+ kset_unregister(edd_kset);
return rc;
}

@@ -788,7 +788,7 @@ edd_exit(void)
if ((edev = edd_devices[i]))
edd_device_unregister(edev);
}
- firmware_unregister(&edd_subsys);
+ kset_unregister(edd_kset);
}

late_initcall(edd_init);
--
1.5.3.8

2008-01-25 07:51:29

by Greg KH

[permalink] [raw]
Subject: [PATCH 090/196] kobject: convert /sys/firmware/acpi/ to use kobject_create

We don't need a kset here, a simple kobject will do just fine, so
dynamically create the kobject and use it.

Cc: Kay Sievers <[email protected]>
Cc: Len Brown <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/acpi/bus.c | 11 ++++++-----
drivers/acpi/system.c | 2 +-
include/acpi/acpi_bus.h | 2 +-
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 7c172d9..e550da6 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -743,7 +743,7 @@ static int __init acpi_bus_init(void)
return -ENODEV;
}

-decl_subsys(acpi, NULL);
+struct kobject *acpi_kobj;

static int __init acpi_init(void)
{
@@ -755,10 +755,11 @@ static int __init acpi_init(void)
return -ENODEV;
}

- result = firmware_register(&acpi_subsys);
- if (result < 0)
- printk(KERN_WARNING "%s: firmware_register error: %d\n",
- __FUNCTION__, result);
+ acpi_kobj = kobject_create_and_add("acpi", &firmware_kset->kobj);
+ if (!acpi_kobj) {
+ printk(KERN_WARNING "%s: kset create error\n", __FUNCTION__);
+ acpi_kobj = NULL;
+ }

result = acpi_bus_init();

diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index edee280..c22b93a 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -135,7 +135,7 @@ static int acpi_system_sysfs_init(void)
int table_index = 0;
int result;

- tables_kobj.parent = &acpi_subsys.kobj;
+ tables_kobj.parent = acpi_kobj;
kobject_set_name(&tables_kobj, "tables");
result = kobject_register(&tables_kobj);
if (result)
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 7b74b60..fb7171b 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -319,7 +319,7 @@ struct acpi_bus_event {
u32 data;
};

-extern struct kset acpi_subsys;
+extern struct kobject *acpi_kobj;
extern int acpi_bus_generate_netlink_event(const char*, const char*, u8, int);
/*
* External Functions
--
1.5.3.8

2008-01-25 07:51:48

by Greg KH

[permalink] [raw]
Subject: [PATCH 091/196] firmware: remove firmware_(un)register()

These functions are no longer called or needed, so we can remove them.

As I rewrote the whole firmware.c file, add my copyright.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/firmware.c | 19 ++-----------------
include/linux/device.h | 5 -----
2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index c7f635b..9efff48 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -3,11 +3,11 @@
*
* Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
+ * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2007 Novell Inc.
*
* This file is released under the GPLv2
- *
*/
-
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/init.h>
@@ -18,18 +18,6 @@
struct kset *firmware_kset;
EXPORT_SYMBOL_GPL(firmware_kset);

-int firmware_register(struct kset *s)
-{
- s->kobj.kset = firmware_kset;
- s->kobj.ktype = NULL;
- return subsystem_register(s);
-}
-
-void firmware_unregister(struct kset *s)
-{
- subsystem_unregister(s);
-}
-
int __init firmware_init(void)
{
firmware_kset = kset_create_and_add("firmware", NULL, NULL);
@@ -37,6 +25,3 @@ int __init firmware_init(void)
return -ENOMEM;
return 0;
}
-
-EXPORT_SYMBOL_GPL(firmware_register);
-EXPORT_SYMBOL_GPL(firmware_unregister);
diff --git a/include/linux/device.h b/include/linux/device.h
index 110ace0..a3b3ff1 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -555,11 +555,6 @@ extern void device_shutdown(void);
/* drivers/base/sys.c */
extern void sysdev_shutdown(void);

-
-/* drivers/base/firmware.c */
-extern int __must_check firmware_register(struct kset *);
-extern void firmware_unregister(struct kset *);
-
/* debugging and troubleshooting/diagnostic helpers. */
extern const char *dev_driver_string(struct device *dev);
#define dev_printk(level, dev, format, arg...) \
--
1.5.3.8

2008-01-25 07:52:16

by Greg KH

[permalink] [raw]
Subject: [PATCH 092/196] firmware: change firmware_kset to firmware_kobj

There is no firmware "subsystem" it's just a directory in /sys that
other portions of the kernel want to hook into. So make it a kobject
not a kset to help alivate anyone who tries to do some odd kset-like
things with this.

Cc: Kay Sievers <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/s390/kernel/ipl.c | 8 ++++----
drivers/acpi/bus.c | 2 +-
drivers/base/firmware.c | 8 ++++----
drivers/firmware/edd.c | 2 +-
drivers/firmware/efivars.c | 2 +-
drivers/parisc/pdc_stable.c | 2 +-
include/linux/kobject.h | 4 ++--
7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index c8179fc..b97694f 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -855,7 +855,7 @@ static int __init ipl_init(void)
{
int rc;

- ipl_kset = kset_create_and_add("ipl", NULL, &firmware_kset->kobj);
+ ipl_kset = kset_create_and_add("ipl", NULL, firmware_kobj);
if (!ipl_kset)
return -ENOMEM;
switch (ipl_info.type) {
@@ -974,7 +974,7 @@ static int __init reipl_init(void)
{
int rc;

- reipl_kset = kset_create_and_add("reipl", NULL, &firmware_kset->kobj);
+ reipl_kset = kset_create_and_add("reipl", NULL, firmware_kobj);
if (!reipl_kset)
return -ENOMEM;
rc = sysfs_create_file(&reipl_kset->kobj, &reipl_type_attr.attr);
@@ -1063,7 +1063,7 @@ static int __init dump_init(void)
{
int rc;

- dump_kset = kset_create_and_add("dump", NULL, &firmware_kset->kobj);
+ dump_kset = kset_create_and_add("dump", NULL, firmware_kobj);
if (!dump_kset)
return -ENOMEM;
rc = sysfs_create_file(&dump_kset->kobj, &dump_type_attr);
@@ -1086,7 +1086,7 @@ static int __init shutdown_actions_init(void)
int rc;

shutdown_actions_kset = kset_create_and_add("shutdown_actions", NULL,
- &firmware_kset->kobj);
+ firmware_kobj);
if (!shutdown_actions_kset)
return -ENOMEM;
rc = sysfs_create_file(&shutdown_actions_kset->kobj, &on_panic_attr);
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index e550da6..1b4cf98 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -755,7 +755,7 @@ static int __init acpi_init(void)
return -ENODEV;
}

- acpi_kobj = kobject_create_and_add("acpi", &firmware_kset->kobj);
+ acpi_kobj = kobject_create_and_add("acpi", firmware_kobj);
if (!acpi_kobj) {
printk(KERN_WARNING "%s: kset create error\n", __FUNCTION__);
acpi_kobj = NULL;
diff --git a/drivers/base/firmware.c b/drivers/base/firmware.c
index 9efff48..1138155 100644
--- a/drivers/base/firmware.c
+++ b/drivers/base/firmware.c
@@ -15,13 +15,13 @@

#include "base.h"

-struct kset *firmware_kset;
-EXPORT_SYMBOL_GPL(firmware_kset);
+struct kobject *firmware_kobj;
+EXPORT_SYMBOL_GPL(firmware_kobj);

int __init firmware_init(void)
{
- firmware_kset = kset_create_and_add("firmware", NULL, NULL);
- if (!firmware_kset)
+ firmware_kobj = kobject_create_and_add("firmware", NULL);
+ if (!firmware_kobj)
return -ENOMEM;
return 0;
}
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index f07f370..ddcc957 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -756,7 +756,7 @@ edd_init(void)
return 1;
}

- edd_kset = kset_create_and_add("edd", NULL, &firmware_kset->kobj);
+ edd_kset = kset_create_and_add("edd", NULL, firmware_kobj);
if (!edd_kset)
return -ENOMEM;

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index e17cd81..d1ad481 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -668,7 +668,7 @@ efivars_init(void)
/*
* For now we'll register the efi subsys within this driver
*/
- efi_kset = kset_create_and_add("efi", NULL, &firmware_kset->kobj);
+ efi_kset = kset_create_and_add("efi", NULL, firmware_kobj);
if (!efi_kset) {
printk(KERN_ERR "efivars: Firmware registration failed.\n");
error = -ENOMEM;
diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 4444834..ef1a353 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -1059,7 +1059,7 @@ pdc_stable_init(void)
pdcs_osid = (u16)(result >> 16);

/* For now we'll register the stable kset within this driver */
- stable_kset = kset_create_and_add("stable", NULL, &firmware_kset->kobj);
+ stable_kset = kset_create_and_add("stable", NULL, firmware_kobj);
if (!stable_kset) {
rc = -ENOMEM;
goto fail_firmreg;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 29841bb..673623f 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -210,8 +210,8 @@ extern struct kset *kernel_kset;
extern struct kobject *hypervisor_kobj;
/* The global /sys/power/ kset for people to chain off of */
extern struct kset *power_kset;
-/* The global /sys/firmware/ kset for people to chain off of */
-extern struct kset *firmware_kset;
+/* The global /sys/firmware/ kobject for people to chain off of */
+extern struct kobject *firmware_kobj;

extern int __must_check subsystem_register(struct kset *);
extern void subsystem_unregister(struct kset *);
--
1.5.3.8

2008-01-25 07:52:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 093/196] kset: convert ocfs2 to use kset_create

Dynamically create the kset instead of declaring it statically.

Also use the new kobj_attribute which cleans up this file a _lot_.

Cc: Kay Sievers <[email protected]>
Cc: Mark Fasheh <[email protected]>
Cc: Kurt Hackel <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ocfs2/cluster/masklog.c | 4 +-
fs/ocfs2/cluster/sys.c | 83 +++++++++++--------------------------------
2 files changed, 23 insertions(+), 64 deletions(-)

diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index dead319..23c732f 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -146,7 +146,7 @@ static struct kset mlog_kset = {
.kobj = {.ktype = &mlog_ktype},
};

-int mlog_sys_init(struct kset *o2cb_subsys)
+int mlog_sys_init(struct kset *o2cb_kset)
{
int i = 0;

@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys)
mlog_attr_ptrs[i] = NULL;

kobject_set_name(&mlog_kset.kobj, "logmask");
- mlog_kset.kobj.kset = o2cb_subsys;
+ mlog_kset.kobj.kset = o2cb_kset;
return kset_register(&mlog_kset);
}

diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 880d013..a4b0773 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -28,96 +28,55 @@
#include <linux/module.h>
#include <linux/kobject.h>
#include <linux/sysfs.h>
+#include <linux/fs.h>

#include "ocfs2_nodemanager.h"
#include "masklog.h"
#include "sys.h"

-struct o2cb_attribute {
- struct attribute attr;
- ssize_t (*show)(char *buf);
- ssize_t (*store)(const char *buf, size_t count);
-};
-
-#define O2CB_ATTR(_name, _mode, _show, _store) \
-struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
-
-#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)

-static ssize_t o2cb_interface_revision_show(char *buf)
+static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
{
return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
}
-
-static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL);
+static struct kobj_attribute attr_version =
+ __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL);

static struct attribute *o2cb_attrs[] = {
- &o2cb_attr_interface_revision.attr,
+ &attr_version.attr,
NULL,
};

-static ssize_t
-o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer);
-static ssize_t
-o2cb_store(struct kobject * kobj, struct attribute * attr,
- const char * buffer, size_t count);
-static struct sysfs_ops o2cb_sysfs_ops = {
- .show = o2cb_show,
- .store = o2cb_store,
+static struct attribute_group o2cb_attr_group = {
+ .attrs = o2cb_attrs,
};

-static struct kobj_type o2cb_subsys_type = {
- .default_attrs = o2cb_attrs,
- .sysfs_ops = &o2cb_sysfs_ops,
-};
-
-/* gives us o2cb_subsys */
-static decl_subsys(o2cb, NULL);
-
-static ssize_t
-o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
-{
- struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
- struct kset *sbs = to_kset(kobj);
-
- BUG_ON(sbs != &o2cb_subsys);
-
- if (o2cb_attr->show)
- return o2cb_attr->show(buffer);
- return -EIO;
-}
-
-static ssize_t
-o2cb_store(struct kobject * kobj, struct attribute * attr,
- const char * buffer, size_t count)
-{
- struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
- struct kset *sbs = to_kset(kobj);
-
- BUG_ON(sbs != &o2cb_subsys);
-
- if (o2cb_attr->store)
- return o2cb_attr->store(buffer, count);
- return -EIO;
-}
+static struct kset *o2cb_kset;

void o2cb_sys_shutdown(void)
{
mlog_sys_shutdown();
- subsystem_unregister(&o2cb_subsys);
+ kset_unregister(o2cb_kset);
}

int o2cb_sys_init(void)
{
int ret;

- o2cb_subsys.kobj.ktype = &o2cb_subsys_type;
- ret = subsystem_register(&o2cb_subsys);
+ o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
+ if (!o2cb_kset)
+ return -ENOMEM;
+
+ ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
if (ret)
- return ret;
+ goto error;

- ret = mlog_sys_init(&o2cb_subsys);
+ ret = mlog_sys_init(o2cb_kset);
if (ret)
- subsystem_unregister(&o2cb_subsys);
+ goto error;
+ return 0;
+error:
+ kset_unregister(o2cb_kset);
return ret;
}
--
1.5.3.8

2008-01-25 07:52:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 094/196] kset: convert block_subsys to use kset_create

Dynamically create the kset instead of declaring it statically. We also
rename block_subsys to block_kset to catch all users of this symbol
with a build error instead of an easy-to-ignore build warning.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/genhd.c | 34 ++++++++++++++++------------------
fs/partitions/check.c | 6 +++---
2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 32227b7..69aa738 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -17,7 +17,8 @@
#include <linux/buffer_head.h>
#include <linux/mutex.h>

-struct kset block_subsys;
+struct kset *block_kset;
+static struct kset_uevent_ops block_uevent_ops;
static DEFINE_MUTEX(block_subsys_lock);

/*
@@ -221,7 +222,7 @@ void __init printk_all_partitions(void)

mutex_lock(&block_subsys_lock);
/* For each block device... */
- list_for_each_entry(sgp, &block_subsys.list, kobj.entry) {
+ list_for_each_entry(sgp, &block_kset->list, kobj.entry) {
char buf[BDEVNAME_SIZE];
/*
* Don't show empty devices or things that have been surpressed
@@ -270,7 +271,7 @@ static void *part_start(struct seq_file *part, loff_t *pos)
loff_t l = *pos;

mutex_lock(&block_subsys_lock);
- list_for_each(p, &block_subsys.list)
+ list_for_each(p, &block_kset->list)
if (!l--)
return list_entry(p, struct gendisk, kobj.entry);
return NULL;
@@ -280,7 +281,7 @@ static void *part_next(struct seq_file *part, void *v, loff_t *pos)
{
struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
++*pos;
- return p==&block_subsys.list ? NULL :
+ return p==&block_kset->list ? NULL :
list_entry(p, struct gendisk, kobj.entry);
}

@@ -295,7 +296,7 @@ static int show_partition(struct seq_file *part, void *v)
int n;
char buf[BDEVNAME_SIZE];

- if (&sgp->kobj.entry == block_subsys.list.next)
+ if (&sgp->kobj.entry == block_kset->list.next)
seq_puts(part, "major minor #blocks name\n\n");

/* Don't show non-partitionable removeable devices or empty devices */
@@ -345,15 +346,14 @@ static struct kobject *base_probe(dev_t dev, int *part, void *data)

static int __init genhd_device_init(void)
{
- int err;
-
bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
blk_dev_init();
- err = subsystem_register(&block_subsys);
- if (err < 0)
- printk(KERN_WARNING "%s: subsystem_register error: %d\n",
- __FUNCTION__, err);
- return err;
+ block_kset = kset_create_and_add("block", &block_uevent_ops, NULL);
+ if (!block_kset) {
+ printk(KERN_WARNING "%s: kset_create error\n", __FUNCTION__);
+ return -ENOMEM;
+ }
+ return 0;
}

subsys_initcall(genhd_device_init);
@@ -584,8 +584,6 @@ static struct kset_uevent_ops block_uevent_ops = {
.uevent = block_uevent,
};

-decl_subsys(block, &block_uevent_ops);
-
/*
* aggregate disk stat collector. Uses the same stats that the sysfs
* entries do, above, but makes them available through one seq_file.
@@ -603,7 +601,7 @@ static void *diskstats_start(struct seq_file *part, loff_t *pos)
struct list_head *p;

mutex_lock(&block_subsys_lock);
- list_for_each(p, &block_subsys.list)
+ list_for_each(p, &block_kset->list)
if (!k--)
return list_entry(p, struct gendisk, kobj.entry);
return NULL;
@@ -613,7 +611,7 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
{
struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
++*pos;
- return p==&block_subsys.list ? NULL :
+ return p==&block_kset->list ? NULL :
list_entry(p, struct gendisk, kobj.entry);
}

@@ -629,7 +627,7 @@ static int diskstats_show(struct seq_file *s, void *v)
int n = 0;

/*
- if (&sgp->kobj.entry == block_subsys.kset.list.next)
+ if (&sgp->kobj.entry == block_kset->list.next)
seq_puts(s, "major minor name"
" rio rmerge rsect ruse wio wmerge "
"wsect wuse running use aveq"
@@ -721,7 +719,7 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
}
}
disk->minors = minors;
- disk->kobj.kset = &block_subsys;
+ disk->kobj.kset = block_kset;
disk->kobj.ktype = &ktype_block;
kobject_init(&disk->kobj);
rand_initialize_disk(disk);
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 69685bb..9184215 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -316,7 +316,7 @@ static struct attribute * default_attrs[] = {
NULL,
};

-extern struct kset block_subsys;
+extern struct kset *block_kset;

static void part_release(struct kobject *kobj)
{
@@ -393,7 +393,7 @@ void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len,
kobject_add(&p->kobj);
if (!disk->part_uevent_suppress)
kobject_uevent(&p->kobj, KOBJ_ADD);
- sysfs_create_link(&p->kobj, &block_subsys.kobj, "subsystem");
+ sysfs_create_link(&p->kobj, &block_kset->kobj, "subsystem");
if (flags & ADDPART_FLAG_WHOLEDISK) {
static struct attribute addpartattr = {
.name = "whole_disk",
@@ -448,7 +448,7 @@ static int disk_sysfs_symlinks(struct gendisk *disk)
goto err_out_dev_link;
}

- err = sysfs_create_link(&disk->kobj, &block_subsys.kobj,
+ err = sysfs_create_link(&disk->kobj, &block_kset->kobj,
"subsystem");
if (err)
goto err_out_disk_name_lnk;
--
1.5.3.8

2008-01-25 07:53:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 095/196] kset: remove decl_subsys macro

This macro is no longer used. ksets should be created dynamically with
a call to kset_create_and_add() not declared statically.

Yes, there are 5 remaining static struct kset usages in the kernel tree,
but they will be fixed up soon.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/class.c | 11 +++++++++--
include/linux/kobject.h | 6 ------
2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index d8a92c6..304f90e 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -453,8 +453,15 @@ static struct kset_uevent_ops class_uevent_ops = {
.uevent = class_uevent,
};

-static decl_subsys(class_obj, &class_uevent_ops);
-
+/*
+ * DO NOT copy how this is created, kset_create_and_add() should be
+ * called, but this is a hold-over from the old-way and will be deleted
+ * entirely soon.
+ */
+static struct kset class_obj_subsys = {
+ .kobj = { .k_name = "class_obj", },
+ .uevent_ops = &class_uevent_ops,
+};

static int class_device_add_attrs(struct class_device * cd)
{
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 673623f..9da3523 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -198,12 +198,6 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);
#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }


-#define decl_subsys(_name,_uevent_ops) \
-struct kset _name##_subsys = { \
- .kobj = { .k_name = __stringify(_name) }, \
- .uevent_ops =_uevent_ops, \
-}
-
/* The global /sys/kernel/ kset for people to chain off of */
extern struct kset *kernel_kset;
/* The global /sys/hypervisor/ kobject for people to chain off of */
--
1.5.3.8

2008-01-25 07:53:46

by Greg KH

[permalink] [raw]
Subject: [PATCH 096/196] kobject: convert kernel_kset to be a kobject

kernel_kset does not need to be a kset, but a much simpler kobject now
that we have kobj_attributes.

We also rename kernel_kset to kernel_kobj to catch all users of this
symbol with a build error instead of an easy-to-ignore build warning.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/configfs/mount.c | 2 +-
fs/debugfs/inode.c | 2 +-
fs/dlm/lockspace.c | 2 +-
fs/gfs2/locking/dlm/sysfs.c | 2 +-
include/linux/kobject.h | 4 ++--
kernel/ksysfs.c | 18 +++++++++---------
kernel/user.c | 2 +-
mm/slub.c | 3 +--
security/inode.c | 2 +-
9 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index c4ee7f0..54bf0db 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -140,7 +140,7 @@ static int __init configfs_init(void)
if (!configfs_dir_cachep)
goto out;

- config_kobj = kobject_create_and_add("config", &kernel_kset->kobj);
+ config_kobj = kobject_create_and_add("config", kernel_kobj);
if (!config_kobj) {
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 5ce92c3..97f6381 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -432,7 +432,7 @@ static int __init debugfs_init(void)
{
int retval;

- debug_kobj = kobject_create_and_add("debug", &kernel_kset->kobj);
+ debug_kobj = kobject_create_and_add("debug", kernel_kobj);
if (!debug_kobj)
return -EINVAL;

diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 0828beb..e64b0dc 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -223,7 +223,7 @@ int dlm_lockspace_init(void)
INIT_LIST_HEAD(&lslist);
spin_lock_init(&lslist_lock);

- dlm_kset = kset_create_and_add("dlm", NULL, &kernel_kset->kobj);
+ dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj);
if (!dlm_kset) {
printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
return -ENOMEM;
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index 1a92b6f..e5a4fbf 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -219,7 +219,7 @@ void gdlm_kobject_release(struct gdlm_ls *ls)

int gdlm_sysfs_init(void)
{
- gdlm_kset = kset_create_and_add("lock_dlm", NULL, &kernel_kset->kobj);
+ gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
if (!gdlm_kset) {
printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
return -ENOMEM;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 9da3523..0930efd 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -198,8 +198,8 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);
#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }


-/* The global /sys/kernel/ kset for people to chain off of */
-extern struct kset *kernel_kset;
+/* The global /sys/kernel/ kobject for people to chain off of */
+extern struct kobject *kernel_kobj;
/* The global /sys/hypervisor/ kobject for people to chain off of */
extern struct kobject *hypervisor_kobj;
/* The global /sys/power/ kset for people to chain off of */
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 45e6465..1081aff 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -101,8 +101,8 @@ static struct bin_attribute notes_attr = {
.read = &notes_read,
};

-struct kset *kernel_kset;
-EXPORT_SYMBOL_GPL(kernel_kset);
+struct kobject *kernel_kobj;
+EXPORT_SYMBOL_GPL(kernel_kobj);

static struct attribute * kernel_attrs[] = {
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
@@ -125,18 +125,18 @@ static int __init ksysfs_init(void)
{
int error;

- kernel_kset = kset_create_and_add("kernel", NULL, NULL);
- if (!kernel_kset) {
+ kernel_kobj = kobject_create_and_add("kernel", NULL);
+ if (!kernel_kobj) {
error = -ENOMEM;
goto exit;
}
- error = sysfs_create_group(&kernel_kset->kobj, &kernel_attr_group);
+ error = sysfs_create_group(kernel_kobj, &kernel_attr_group);
if (error)
goto kset_exit;

if (notes_size > 0) {
notes_attr.size = notes_size;
- error = sysfs_create_bin_file(&kernel_kset->kobj, &notes_attr);
+ error = sysfs_create_bin_file(kernel_kobj, &notes_attr);
if (error)
goto group_exit;
}
@@ -150,11 +150,11 @@ static int __init ksysfs_init(void)

notes_exit:
if (notes_size > 0)
- sysfs_remove_bin_file(&kernel_kset->kobj, &notes_attr);
+ sysfs_remove_bin_file(kernel_kobj, &notes_attr);
group_exit:
- sysfs_remove_group(&kernel_kset->kobj, &kernel_attr_group);
+ sysfs_remove_group(kernel_kobj, &kernel_attr_group);
kset_exit:
- kset_unregister(kernel_kset);
+ kobject_unregister(kernel_kobj);
exit:
return error;
}
diff --git a/kernel/user.c b/kernel/user.c
index 5a106f3..7f17e6e 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -201,7 +201,7 @@ done:
*/
int __init uids_sysfs_init(void)
{
- uids_kset = kset_create_and_add("uids", NULL, &kernel_kset->kobj);
+ uids_kset = kset_create_and_add("uids", NULL, kernel_kobj);
if (!uids_kset)
return -ENOMEM;

diff --git a/mm/slub.c b/mm/slub.c
index b6c7946..d26177f 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4091,8 +4091,7 @@ static int __init slab_sysfs_init(void)
struct kmem_cache *s;
int err;

- slab_kset = kset_create_and_add("slab", &slab_uevent_ops,
- &kernel_kset->kobj);
+ slab_kset = kset_create_and_add("slab", &slab_uevent_ops, kernel_kobj);
if (!slab_kset) {
printk(KERN_ERR "Cannot register slab subsystem.\n");
return -ENOSYS;
diff --git a/security/inode.c b/security/inode.c
index dbe040a..def0cc1 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -321,7 +321,7 @@ static int __init securityfs_init(void)
{
int retval;

- security_kobj = kobject_create_and_add("security", &kernel_kset->kobj);
+ security_kobj = kobject_create_and_add("security", kernel_kobj);
if (!security_kobj)
return -EINVAL;

--
1.5.3.8

2008-01-25 07:54:05

by Greg KH

[permalink] [raw]
Subject: [PATCH 097/196] kobject: remove subsystem_(un)register functions

These functions are no longer used and are the last remants of the old
subsystem crap. So delete them for good.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 6 +++---
drivers/base/class.c | 4 ++--
include/linux/kobject.h | 3 ---
lib/kobject.c | 13 -------------
4 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6796d3e..871607b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -854,7 +854,7 @@ int bus_register(struct bus_type * bus)
bus->subsys.kobj.kset = bus_kset;
bus->subsys.kobj.ktype = &bus_ktype;

- retval = subsystem_register(&bus->subsys);
+ retval = kset_register(&bus->subsys);
if (retval)
goto out;

@@ -900,7 +900,7 @@ bus_drivers_fail:
bus_devices_fail:
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
- subsystem_unregister(&bus->subsys);
+ kset_unregister(&bus->subsys);
out:
return retval;
}
@@ -920,7 +920,7 @@ void bus_unregister(struct bus_type * bus)
kset_unregister(bus->drivers_kset);
kset_unregister(bus->devices_kset);
bus_remove_file(bus, &bus_attr_uevent);
- subsystem_unregister(&bus->subsys);
+ kset_unregister(&bus->subsys);
}

int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 304f90e..3ffcda7 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -152,7 +152,7 @@ int class_register(struct class * cls)
cls->subsys.kobj.kset = class_kset;
cls->subsys.kobj.ktype = &class_ktype;

- error = subsystem_register(&cls->subsys);
+ error = kset_register(&cls->subsys);
if (!error) {
error = add_class_attrs(class_get(cls));
class_put(cls);
@@ -164,7 +164,7 @@ void class_unregister(struct class * cls)
{
pr_debug("device class '%s': unregistering\n", cls->name);
remove_class_attrs(cls);
- subsystem_unregister(&cls->subsys);
+ kset_unregister(&cls->subsys);
}

static void class_create_release(struct class *cls)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 0930efd..78c851b 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -207,9 +207,6 @@ extern struct kset *power_kset;
/* The global /sys/firmware/ kobject for people to chain off of */
extern struct kobject *firmware_kobj;

-extern int __must_check subsystem_register(struct kset *);
-extern void subsystem_unregister(struct kset *);
-
#if defined(CONFIG_HOTPLUG)
int kobject_uevent(struct kobject *kobj, enum kobject_action action);
int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
diff --git a/lib/kobject.c b/lib/kobject.c
index c742ac2..7919c32 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -800,16 +800,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
return ret;
}

-int subsystem_register(struct kset *s)
-{
- return kset_register(s);
-}
-
-void subsystem_unregister(struct kset *s)
-{
- kset_unregister(s);
-}
-
static void kset_release(struct kobject *kobj)
{
struct kset *kset = container_of(kobj, struct kset, kobj);
@@ -904,6 +894,3 @@ EXPORT_SYMBOL(kobject_del);

EXPORT_SYMBOL(kset_register);
EXPORT_SYMBOL(kset_unregister);
-
-EXPORT_SYMBOL(subsystem_register);
-EXPORT_SYMBOL(subsystem_unregister);
--
1.5.3.8

2008-01-25 07:54:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 098/196] kobject: clean up rpadlpar horrid sysfs abuse

rpadlpar pci hotplug driver was doing some pretty bad stuff with the
sysfs files. This cleans up the logic to be sane and gets rid of the
gratuitous kset that is not needed for a simple directory like this.

Note, this patch is not even build tested, let alone run-time tested.
Someone with access to this hardware and can test would be greatly
appreciated.

Cc: Kay Sievers <[email protected]>
Cc: John Rose <[email protected]>
Cc: Badari Pulavarty <[email protected]>
Cc: Kamalesh Babulal <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pci/hotplug/rpadlpar_sysfs.c | 112 +++++++++++++---------------------
1 files changed, 43 insertions(+), 69 deletions(-)

diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index 5c3ddb6..9cde367 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -23,44 +23,13 @@

#define MAX_DRC_NAME_LEN 64

-/* Store return code of dlpar operation in attribute struct */
-struct dlpar_io_attr {
- int rc;
- struct attribute attr;
- ssize_t (*store)(struct dlpar_io_attr *dlpar_attr, const char *buf,
- size_t nbytes);
-};

-/* Common show callback for all attrs, display the return code
- * of the dlpar op */
-static ssize_t
-dlpar_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
-{
- struct dlpar_io_attr *dlpar_attr = container_of(attr,
- struct dlpar_io_attr, attr);
- return sprintf(buf, "%d\n", dlpar_attr->rc);
-}
-
-static ssize_t
-dlpar_attr_store(struct kobject * kobj, struct attribute * attr,
- const char *buf, size_t nbytes)
-{
- struct dlpar_io_attr *dlpar_attr = container_of(attr,
- struct dlpar_io_attr, attr);
- return dlpar_attr->store ?
- dlpar_attr->store(dlpar_attr, buf, nbytes) : -EIO;
-}
-
-static struct sysfs_ops dlpar_attr_sysfs_ops = {
- .show = dlpar_attr_show,
- .store = dlpar_attr_store,
-};
-
-static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
- const char *buf, size_t nbytes)
+static ssize_t add_slot_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t nbytes)
{
char drc_name[MAX_DRC_NAME_LEN];
char *end;
+ int rc;

if (nbytes >= MAX_DRC_NAME_LEN)
return 0;
@@ -72,15 +41,25 @@ static ssize_t add_slot_store(struct dlpar_io_attr *dlpar_attr,
end = &drc_name[nbytes];
*end = '\0';

- dlpar_attr->rc = dlpar_add_slot(drc_name);
+ rc = dlpar_add_slot(drc_name);
+ if (rc)
+ return rc;

return nbytes;
}

-static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
- const char *buf, size_t nbytes)
+static ssize_t add_slot_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "0\n");
+}
+
+static ssize_t remove_slot_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t nbytes)
{
char drc_name[MAX_DRC_NAME_LEN];
+ int rc;
char *end;

if (nbytes >= MAX_DRC_NAME_LEN)
@@ -93,22 +72,24 @@ static ssize_t remove_slot_store(struct dlpar_io_attr *dlpar_attr,
end = &drc_name[nbytes];
*end = '\0';

- dlpar_attr->rc = dlpar_remove_slot(drc_name);
+ rc = dlpar_remove_slot(drc_name);
+ if (rc)
+ return rc;

return nbytes;
}

-static struct dlpar_io_attr add_slot_attr = {
- .rc = 0,
- .attr = { .name = ADD_SLOT_ATTR_NAME, .mode = 0644, },
- .store = add_slot_store,
-};
+static ssize_t remove_slot_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "0\n");
+}

-static struct dlpar_io_attr remove_slot_attr = {
- .rc = 0,
- .attr = { .name = REMOVE_SLOT_ATTR_NAME, .mode = 0644},
- .store = remove_slot_store,
-};
+static struct kobj_attribute add_slot_attr =
+ __ATTR(ADD_SLOT_ATTR_NAME, 0644, add_slot_show, add_slot_store);
+
+static struct kobj_attribute remove_slot_attr =
+ __ATTR(REMOVE_SLOT_ATTR_NAME, 0644, remove_slot_show, remove_slot_store);

static struct attribute *default_attrs[] = {
&add_slot_attr.attr,
@@ -116,36 +97,29 @@ static struct attribute *default_attrs[] = {
NULL,
};

-static void dlpar_io_release(struct kobject *kobj)
-{
- /* noop */
- return;
-}
-
-struct kobj_type ktype_dlpar_io = {
- .release = dlpar_io_release,
- .sysfs_ops = &dlpar_attr_sysfs_ops,
- .default_attrs = default_attrs,
+static struct attribute_group dlpar_attr_group = {
+ .attrs = default_attrs,
};

-struct kset dlpar_io_kset = {
- .kobj = {.ktype = &ktype_dlpar_io,
- .parent = &pci_hotplug_slots_kset->kobj},
-};
+static struct kobject *dlpar_kobj;

int dlpar_sysfs_init(void)
{
- kobject_set_name(&dlpar_io_kset.kobj, DLPAR_KOBJ_NAME);
- if (kset_register(&dlpar_io_kset)) {
- printk(KERN_ERR "rpadlpar_io: cannot register kset for %s\n",
- kobject_name(&dlpar_io_kset.kobj));
+ int error;
+
+ dlpar_kobj = kobject_create_and_add(DLPAR_KOBJ_NAME,
+ &pci_hotplug_slots_kset->kobj);
+ if (!dlpar_kobj)
return -EINVAL;
- }

- return 0;
+ error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
+ if (error)
+ kobject_unregister(dlpar_kobj);
+ return error;
}

void dlpar_sysfs_exit(void)
{
- kset_unregister(&dlpar_io_kset);
+ sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
+ kobject_unregister(dlpar_kobj);
}
--
1.5.3.8

2008-01-25 07:54:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 099/196] kobject: convert ecryptfs to use kobject_create

Using a kset for this trivial directory is an overkill.

Cc: Kay Sievers <[email protected]>
Cc: Mike Halcrow <[email protected]>
Cc: Phillip Hellewell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/ecryptfs/main.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index d984eac..4f13321 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,7 +734,7 @@ static int ecryptfs_init_kmem_caches(void)
return 0;
}

-static struct kset *ecryptfs_kset;
+static struct kobject *ecryptfs_kobj;

static ssize_t version_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buff)
@@ -757,17 +757,17 @@ static int do_sysfs_registration(void)
{
int rc;

- ecryptfs_kset = kset_create_and_add("ecryptfs", NULL, fs_kobj);
- if (!ecryptfs_kset) {
+ ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
+ if (!ecryptfs_kobj) {
printk(KERN_ERR "Unable to create ecryptfs kset\n");
rc = -ENOMEM;
goto out;
}
- rc = sysfs_create_group(&ecryptfs_kset->kobj, &attr_group);
+ rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
if (rc) {
printk(KERN_ERR
"Unable to create ecryptfs version attributes\n");
- kset_unregister(ecryptfs_kset);
+ kobject_unregister(ecryptfs_kobj);
}
out:
return rc;
@@ -775,8 +775,8 @@ out:

static void do_sysfs_unregistration(void)
{
- sysfs_remove_group(&ecryptfs_kset->kobj, &attr_group);
- kset_unregister(ecryptfs_kset);
+ sysfs_remove_group(ecryptfs_kobj, &attr_group);
+ kobject_unregister(ecryptfs_kobj);
}

static int __init ecryptfs_init(void)
--
1.5.3.8

2008-01-25 07:55:13

by Greg KH

[permalink] [raw]
Subject: [PATCH 100/196] kobject: convert efivars to use kobject_create

Using a kset for this simple directory is an overkill.

Cc: Kay Sievers <[email protected]>
Cc: Matt Domsch <[email protected]>
Cc: Matt Tolentino <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index d1ad481..7f9f086 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -573,7 +573,7 @@ static struct attribute_group efi_subsys_attr_group = {


static struct kset *vars_kset;
-static struct kset *efi_kset;
+static struct kobject *efi_kobj;

/*
* efivar_create_sysfs_entry()
@@ -665,17 +665,15 @@ efivars_init(void)
printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
EFIVARS_DATE);

- /*
- * For now we'll register the efi subsys within this driver
- */
- efi_kset = kset_create_and_add("efi", NULL, firmware_kobj);
- if (!efi_kset) {
+ /* For now we'll register the efi directory at /sys/firmware/efi */
+ efi_kobj = kobject_create_and_add("efi", firmware_kobj);
+ if (!efi_kobj) {
printk(KERN_ERR "efivars: Firmware registration failed.\n");
error = -ENOMEM;
goto out_free;
}

- vars_kset = kset_create_and_add("vars", NULL, &efi_kset->kobj);
+ vars_kset = kset_create_and_add("vars", NULL, efi_kobj);
if (!vars_kset) {
printk(KERN_ERR "efivars: Subsystem registration failed.\n");
error = -ENOMEM;
@@ -725,7 +723,7 @@ efivars_init(void)
" due to error %d\n", error);

/* Don't forget the systab entry */
- error = sysfs_create_group(&efi_kset->kobj, &efi_subsys_attr_group);
+ error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
if (error)
printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
else
@@ -734,7 +732,7 @@ efivars_init(void)
kset_unregister(vars_kset);

out_firmware_unregister:
- kset_unregister(efi_kset);
+ kobject_unregister(efi_kobj);

out_free:
kfree(variable_name);
@@ -755,7 +753,7 @@ efivars_exit(void)
}

kset_unregister(vars_kset);
- kset_unregister(efi_kset);
+ kobject_unregister(efi_kobj);
}

module_init(efivars_init);
--
1.5.3.8

2008-01-25 07:55:51

by Greg KH

[permalink] [raw]
Subject: [PATCH 101/196] kobject: convert parisc/pdc_stable to use kobject_create

Using a kset for this simple directory is an overkill.

Cc: Kay Sievers <[email protected]>
Cc: Thibaut VARENE <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Grant Grundler <[email protected]>
Cc: Kyle McMartin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/parisc/pdc_stable.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index ef1a353..880b10b 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -960,7 +960,7 @@ static struct attribute_group pdcs_attr_group = {
.attrs = pdcs_subsys_attrs,
};

-static struct kset *stable_kset;
+static struct kobject *stable_kobj;
static struct kset *paths_kset;

/**
@@ -1058,18 +1058,18 @@ pdc_stable_init(void)
/* the actual result is 16 bits away */
pdcs_osid = (u16)(result >> 16);

- /* For now we'll register the stable kset within this driver */
- stable_kset = kset_create_and_add("stable", NULL, firmware_kobj);
- if (!stable_kset) {
+ /* For now we'll register the directory at /sys/firmware/stable */
+ stable_kobj = kobject_create_and_add("stable", firmware_kobj);
+ if (!stable_kobj) {
rc = -ENOMEM;
goto fail_firmreg;
}

/* Don't forget the root entries */
- error = sysfs_create_group(&stable_kset->kobj, pdcs_attr_group);
+ error = sysfs_create_group(stable_kobj, pdcs_attr_group);

/* register the paths kset as a child of the stable kset */
- paths_kset = kset_create_and_add("paths", NULL, &stable_kset->kobj);
+ paths_kset = kset_create_and_add("paths", NULL, stable_kobj);
if (!paths_kset) {
rc = -ENOMEM;
goto fail_ksetreg;
@@ -1086,7 +1086,7 @@ fail_pdcsreg:
kset_unregister(paths_kset);

fail_ksetreg:
- kset_unregister(stable_kset);
+ kobject_unregister(stable_kobj);

fail_firmreg:
printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1098,7 +1098,7 @@ pdc_stable_exit(void)
{
pdcs_unregister_pathentries();
kset_unregister(paths_kset);
- kset_unregister(stable_kset);
+ kobject_unregister(stable_kobj);
}


--
1.5.3.8

2008-01-25 07:56:19

by Greg KH

[permalink] [raw]
Subject: [PATCH 102/196] driver core: clean up shutdown.c

shutdown.c had some stuff it did not need, including a duplicate extern
in the power.h file. This cleans up all of that.


Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/power/power.h | 7 -------
drivers/base/power/shutdown.c | 5 -----
2 files changed, 0 insertions(+), 12 deletions(-)

diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 10c2084..6f0dfca 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -1,10 +1,3 @@
-/*
- * shutdown.c
- */
-
-extern void device_shutdown(void);
-
-
#ifdef CONFIG_PM_SLEEP

/*
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index f51cbc1..5b6bc16 100644
--- a/drivers/base/power/shutdown.c
+++ b/drivers/base/power/shutdown.c
@@ -12,10 +12,6 @@
#include <asm/semaphore.h>

#include "../base.h"
-#include "power.h"
-
-#define to_dev(node) container_of(node, struct device, kobj.entry)
-

/**
* We handle system devices differently - we suspend and shut them
@@ -45,4 +41,3 @@ void device_shutdown(void)
}
}
}
-
--
1.5.3.8

2008-01-25 07:56:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 103/196] driver core: clean up device_shutdown

device_shutdown does not need to be in a separate file. Move it into
the driver core file where it belongs.

This also moves us one more step closer to making devices_kset static,
now only the crazy sysdevs are keeping that from happening...

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 20 ++++++++++++++++++-
drivers/base/power/Makefile | 1 -
drivers/base/power/shutdown.c | 43 -----------------------------------------
3 files changed, 19 insertions(+), 45 deletions(-)
delete mode 100644 drivers/base/power/shutdown.c

diff --git a/drivers/base/core.c b/drivers/base/core.c
index d2de2d5..b3a931f 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1415,5 +1415,23 @@ out:
put_device(dev);
return error;
}
-
EXPORT_SYMBOL_GPL(device_move);
+
+/**
+ * device_shutdown - call ->shutdown() on each device to shutdown.
+ */
+void device_shutdown(void)
+{
+ struct device * dev, *devn;
+
+ list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
+ kobj.entry) {
+ if (dev->bus && dev->bus->shutdown) {
+ dev_dbg(dev, "shutdown\n");
+ dev->bus->shutdown(dev);
+ } else if (dev->driver && dev->driver->shutdown) {
+ dev_dbg(dev, "shutdown\n");
+ dev->driver->shutdown(dev);
+ }
+ }
+}
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile
index 44504e6..06a86fe 100644
--- a/drivers/base/power/Makefile
+++ b/drivers/base/power/Makefile
@@ -1,4 +1,3 @@
-obj-y := shutdown.o
obj-$(CONFIG_PM) += sysfs.o
obj-$(CONFIG_PM_SLEEP) += main.o
obj-$(CONFIG_PM_TRACE) += trace.o
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
deleted file mode 100644
index 5b6bc16..0000000
--- a/drivers/base/power/shutdown.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * shutdown.c - power management functions for the device tree.
- *
- * Copyright (c) 2002-3 Patrick Mochel
- * 2002-3 Open Source Development Lab
- *
- * This file is released under the GPLv2
- *
- */
-
-#include <linux/device.h>
-#include <asm/semaphore.h>
-
-#include "../base.h"
-
-/**
- * We handle system devices differently - we suspend and shut them
- * down last and resume them first. That way, we don't do anything stupid like
- * shutting down the interrupt controller before any devices..
- *
- * Note that there are not different stages for power management calls -
- * they only get one called once when interrupts are disabled.
- */
-
-
-/**
- * device_shutdown - call ->shutdown() on each device to shutdown.
- */
-void device_shutdown(void)
-{
- struct device * dev, *devn;
-
- list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
- kobj.entry) {
- if (dev->bus && dev->bus->shutdown) {
- dev_dbg(dev, "shutdown\n");
- dev->bus->shutdown(dev);
- } else if (dev->driver && dev->driver->shutdown) {
- dev_dbg(dev, "shutdown\n");
- dev->driver->shutdown(dev);
- }
- }
-}
--
1.5.3.8

2008-01-25 07:57:04

by Greg KH

[permalink] [raw]
Subject: [PATCH 104/196] driver core: make /sys/power a kobject

/sys/power should not be a kset, that's overkill. This patch renames it
to power_kset and fixes up all usages of it in the tree.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/arm/mach-omap1/pm.c | 2 +-
arch/powerpc/platforms/pseries/power.c | 10 +++++-----
include/linux/kobject.h | 4 ++--
kernel/power/disk.c | 2 +-
kernel/power/main.c | 8 ++++----
5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/arm/mach-omap1/pm.c b/arch/arm/mach-omap1/pm.c
index 63edafb..d9805e3 100644
--- a/arch/arm/mach-omap1/pm.c
+++ b/arch/arm/mach-omap1/pm.c
@@ -719,7 +719,7 @@ static int __init omap_pm_init(void)
omap_pm_init_proc();
#endif

- error = sysfs_create_file(&power_kset->kobj, &sleep_while_idle_attr);
+ error = sysfs_create_file(power_kobj, &sleep_while_idle_attr);
if (error)
printk(KERN_ERR "sysfs_create_file failed: %d\n", error);

diff --git a/arch/powerpc/platforms/pseries/power.c b/arch/powerpc/platforms/pseries/power.c
index 90706cf..e95fc15 100644
--- a/arch/powerpc/platforms/pseries/power.c
+++ b/arch/powerpc/platforms/pseries/power.c
@@ -53,7 +53,7 @@ static struct kobj_attribute auto_poweron_attr =
__ATTR(auto_poweron, 0644, auto_poweron_show, auto_poweron_store);

#ifndef CONFIG_PM
-struct kset *power_kset;
+struct kobject *power_kobj;

static struct attribute *g[] = {
&auto_poweron_attr.attr,
@@ -66,16 +66,16 @@ static struct attribute_group attr_group = {

static int __init pm_init(void)
{
- power_kset = kset_create_and_add("power", NULL, NULL);
- if (!power_kset)
+ power_kobj = kobject_create_and_add("power", NULL);
+ if (!power_kobj)
return -ENOMEM;
- return sysfs_create_group(&power_kset->kobj, &attr_group);
+ return sysfs_create_group(power_kobj, &attr_group);
}
core_initcall(pm_init);
#else
static int __init apo_pm_init(void)
{
- return (sysfs_create_file(&power_kset->kobj, &auto_poweron_attr));
+ return (sysfs_create_file(power_kobj, &auto_poweron_attr));
}
__initcall(apo_pm_init);
#endif
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 78c851b..bb68684 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -202,8 +202,8 @@ extern struct kobject * kset_find_obj(struct kset *, const char *);
extern struct kobject *kernel_kobj;
/* The global /sys/hypervisor/ kobject for people to chain off of */
extern struct kobject *hypervisor_kobj;
-/* The global /sys/power/ kset for people to chain off of */
-extern struct kset *power_kset;
+/* The global /sys/power/ kobject for people to chain off of */
+extern struct kobject *power_kobj;
/* The global /sys/firmware/ kobject for people to chain off of */
extern struct kobject *firmware_kobj;

diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index ef5aa2c..b138b43 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -714,7 +714,7 @@ static struct attribute_group attr_group = {

static int __init pm_disk_init(void)
{
- return sysfs_create_group(&power_kset->kobj, &attr_group);
+ return sysfs_create_group(power_kobj, &attr_group);
}

core_initcall(pm_disk_init);
diff --git a/kernel/power/main.c b/kernel/power/main.c
index b813949..efc0836 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -276,7 +276,7 @@ EXPORT_SYMBOL(pm_suspend);

#endif /* CONFIG_SUSPEND */

-struct kset *power_kset;
+struct kobject *power_kobj;

/**
* state - control system power state.
@@ -389,10 +389,10 @@ static struct attribute_group attr_group = {

static int __init pm_init(void)
{
- power_kset = kset_create_and_add("power", NULL, NULL);
- if (!power_kset)
+ power_kobj = kobject_create_and_add("power", NULL);
+ if (!power_kobj)
return -ENOMEM;
- return sysfs_create_group(&power_kset->kobj, &attr_group);
+ return sysfs_create_group(power_kobj, &attr_group);
}

core_initcall(pm_init);
--
1.5.3.8

2008-01-25 07:57:34

by Greg KH

[permalink] [raw]
Subject: [PATCH 105/196] kobject: grab the kset reference in kobject_add, not kobject_init

kobject_init should not be grabing any references, but only initializing
the object. This patch fixes this, and makes the lock hold-time shorter
for when a kset is present in the kobject.

The current kernel tree has been audited to verify that this change
should be safe.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 7919c32..4d52b6f 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -133,7 +133,6 @@ void kobject_init(struct kobject * kobj)
return;
kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry);
- kobj->kset = kset_get(kobj->kset);
}


@@ -184,7 +183,7 @@ int kobject_add(struct kobject * kobj)
kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );

if (kobj->kset) {
- spin_lock(&kobj->kset->list_lock);
+ kobj->kset = kset_get(kobj->kset);

if (!parent) {
parent = kobject_get(&kobj->kset->kobj);
@@ -196,7 +195,8 @@ int kobject_add(struct kobject * kobj)
kobject_get(parent);
}

- list_add_tail(&kobj->entry,&kobj->kset->list);
+ spin_lock(&kobj->kset->list_lock);
+ list_add_tail(&kobj->entry, &kobj->kset->list);
spin_unlock(&kobj->kset->list_lock);
kobj->parent = parent;
}
--
1.5.3.8

2008-01-25 07:57:50

by Greg KH

[permalink] [raw]
Subject: [PATCH 106/196] kobject: clean up debugging messages

The kobject debugging messages are a mess. This provides a unified
message that makes them actually useful.

The format for new kobject debug messages should be:
kobject: 'KOBJECT_NAME' (ADDRESS): FUNCTION_NAME: message.\n

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 23 +++++++++++++++--------
lib/kobject_uevent.c | 20 ++++++++++++++------
2 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 4d52b6f..1015f74 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -95,7 +95,8 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
*(path + --length) = '/';
}

- pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
+ pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
+ kobj, __FUNCTION__,path);
}

/**
@@ -171,15 +172,17 @@ int kobject_add(struct kobject * kobj)
if (!kobj->k_name)
kobject_set_name(kobj, "NO_NAME");
if (!*kobj->k_name) {
- pr_debug("kobject attempted to be registered with no name!\n");
+ pr_debug("kobject (%p) attempted to be registered with no "
+ "name!\n", kobj);
WARN_ON(1);
kobject_put(kobj);
return -EINVAL;
}
parent = kobject_get(kobj->parent);

- pr_debug("kobject %s: registering. parent: %s, set: %s\n",
- kobject_name(kobj), parent ? kobject_name(parent) : "<NULL>",
+ pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
+ kobject_name(kobj), kobj, __FUNCTION__,
+ parent ? kobject_name(parent) : "<NULL>",
kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );

if (kobj->kset) {
@@ -560,7 +563,8 @@ void kobject_unregister(struct kobject * kobj)
{
if (!kobj)
return;
- pr_debug("kobject %s: unregistering\n",kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kobject_uevent(kobj, KOBJ_REMOVE);
kobject_del(kobj);
kobject_put(kobj);
@@ -589,7 +593,8 @@ static void kobject_cleanup(struct kobject *kobj)
struct kobject * parent = kobj->parent;
const char *name = kobj->k_name;

- pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
if (t && t->release) {
t->release(kobj);
/* If we have a release function, we can guess that this was
@@ -621,7 +626,8 @@ void kobject_put(struct kobject * kobj)

static void dynamic_kobj_release(struct kobject *kobj)
{
- pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kfree(kobj);
}

@@ -803,7 +809,8 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
static void kset_release(struct kobject *kobj)
{
struct kset *kset = container_of(kobj, struct kset, kobj);
- pr_debug("kset %s: now freed\n", kobject_name(kobj));
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
kfree(kset);
}

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 5886147..51dc4d2 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -98,7 +98,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
int i = 0;
int retval = 0;

- pr_debug("%s\n", __FUNCTION__);
+ pr_debug("kobject: '%s' (%p): %s\n",
+ kobject_name(kobj), kobj, __FUNCTION__);

/* search the kset we belong to */
top_kobj = kobj;
@@ -106,7 +107,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
top_kobj = top_kobj->parent;

if (!top_kobj->kset) {
- pr_debug("kobject attempted to send uevent without kset!\n");
+ pr_debug("kobject: '%s' (%p): %s: attempted to send uevent "
+ "without kset!\n", kobject_name(kobj), kobj,
+ __FUNCTION__);
return -EINVAL;
}

@@ -116,7 +119,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
/* skip the event, if the filter returns zero. */
if (uevent_ops && uevent_ops->filter)
if (!uevent_ops->filter(kset, kobj)) {
- pr_debug("kobject filter function caused the event to drop!\n");
+ pr_debug("kobject: '%s' (%p): %s: filter function "
+ "caused the event to drop!\n",
+ kobject_name(kobj), kobj, __FUNCTION__);
return 0;
}

@@ -126,7 +131,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
else
subsystem = kobject_name(&kset->kobj);
if (!subsystem) {
- pr_debug("unset subsystem caused the event to drop!\n");
+ pr_debug("kobject: '%s' (%p): %s: unset subsystem caused the "
+ "event to drop!\n", kobject_name(kobj), kobj,
+ __FUNCTION__);
return 0;
}

@@ -166,8 +173,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
if (uevent_ops && uevent_ops->uevent) {
retval = uevent_ops->uevent(kset, kobj, env);
if (retval) {
- pr_debug ("%s - uevent() returned %d\n",
- __FUNCTION__, retval);
+ pr_debug("kobject: '%s' (%p): %s: uevent() returned "
+ "%d\n", kobject_name(kobj), kobj,
+ __FUNCTION__, retval);
goto exit;
}
}
--
1.5.3.8

2008-01-25 07:58:16

by Greg KH

[permalink] [raw]
Subject: [PATCH 107/196] UIO: fix kobject usage

The uio kobject code is "wierd". This patch should hopefully fix it up
to be sane and not leak memory anymore.


Cc: Kay Sievers <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Benedikt Spranger <[email protected]>
Signed-off-by: Hans J. Koch <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/uio/uio.c | 91 +++++++++++++++++++++++---------------------
include/linux/uio_driver.h | 6 ++-
2 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 606aae7..acc387d 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -34,7 +34,7 @@ struct uio_device {
wait_queue_head_t wait;
int vma_count;
struct uio_info *info;
- struct kset map_attr_kset;
+ struct kobject *map_dir;
};

static int uio_major;
@@ -51,47 +51,48 @@ static struct uio_class {
* attributes
*/

-static struct attribute attr_addr = {
- .name = "addr",
- .mode = S_IRUGO,
+struct uio_map {
+ struct kobject kobj;
+ struct uio_mem *mem;
};
+#define to_map(map) container_of(map, struct uio_map, kobj)

-static struct attribute attr_size = {
- .name = "size",
- .mode = S_IRUGO,
-};

-static struct attribute* map_attrs[] = {
- &attr_addr, &attr_size, NULL
-};
-
-static ssize_t map_attr_show(struct kobject *kobj, struct attribute *attr,
+static ssize_t map_attr_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
- struct uio_mem *mem = container_of(kobj, struct uio_mem, kobj);
+ struct uio_map *map = to_map(kobj);
+ struct uio_mem *mem = map->mem;

- if (strncmp(attr->name,"addr",4) == 0)
+ if (strncmp(attr->attr.name, "addr", 4) == 0)
return sprintf(buf, "0x%lx\n", mem->addr);

- if (strncmp(attr->name,"size",4) == 0)
+ if (strncmp(attr->attr.name, "size", 4) == 0)
return sprintf(buf, "0x%lx\n", mem->size);

return -ENODEV;
}

-static void map_attr_release(struct kobject *kobj)
-{
- /* TODO ??? */
-}
+static struct kobj_attribute attr_attribute =
+ __ATTR(addr, S_IRUGO, map_attr_show, NULL);
+static struct kobj_attribute size_attribute =
+ __ATTR(size, S_IRUGO, map_attr_show, NULL);

-static struct sysfs_ops map_attr_ops = {
- .show = map_attr_show,
+static struct attribute *attrs[] = {
+ &attr_attribute.attr,
+ &size_attribute.attr,
+ NULL, /* need to NULL terminate the list of attributes */
};

+static void map_release(struct kobject *kobj)
+{
+ struct uio_map *map = to_map(kobj);
+ kfree(map);
+}
+
static struct kobj_type map_attr_type = {
- .release = map_attr_release,
- .sysfs_ops = &map_attr_ops,
- .default_attrs = map_attrs,
+ .release = map_release,
+ .default_attrs = attrs,
};

static ssize_t show_name(struct device *dev,
@@ -148,6 +149,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
int mi;
int map_found = 0;
struct uio_mem *mem;
+ struct uio_map *map;

ret = sysfs_create_group(&idev->dev->kobj, &uio_attr_grp);
if (ret)
@@ -159,31 +161,34 @@ static int uio_dev_add_attributes(struct uio_device *idev)
break;
if (!map_found) {
map_found = 1;
- kobject_set_name(&idev->map_attr_kset.kobj,"maps");
- idev->map_attr_kset.kobj.ktype = &map_attr_type;
- idev->map_attr_kset.kobj.parent = &idev->dev->kobj;
- ret = kset_register(&idev->map_attr_kset);
- if (ret)
- goto err_remove_group;
+ idev->map_dir = kobject_create_and_add("maps",
+ &idev->dev->kobj);
+ if (!idev->map_dir)
+ goto err;
}
- kobject_init(&mem->kobj);
- kobject_set_name(&mem->kobj,"map%d",mi);
- mem->kobj.parent = &idev->map_attr_kset.kobj;
- mem->kobj.kset = &idev->map_attr_kset;
- ret = kobject_add(&mem->kobj);
+ map = kzalloc(sizeof(*map), GFP_KERNEL);
+ if (!map)
+ goto err;
+ kobject_init_ng(&map->kobj, &map_attr_type);
+ map->mem = mem;
+ mem->map = map;
+ ret = kobject_add_ng(&map->kobj, idev->map_dir, "map%d", mi);
+ if (ret)
+ goto err;
+ ret = kobject_uevent(&map->kobj, KOBJ_ADD);
if (ret)
- goto err_remove_maps;
+ goto err;
}

return 0;

-err_remove_maps:
+err:
for (mi--; mi>=0; mi--) {
mem = &idev->info->mem[mi];
- kobject_unregister(&mem->kobj);
+ map = mem->map;
+ kobject_unregister(&map->kobj);
}
- kset_unregister(&idev->map_attr_kset); /* Needed ? */
-err_remove_group:
+ kobject_unregister(idev->map_dir);
sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
err_group:
dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
@@ -198,9 +203,9 @@ static void uio_dev_del_attributes(struct uio_device *idev)
mem = &idev->info->mem[mi];
if (mem->size == 0)
break;
- kobject_unregister(&mem->kobj);
+ kobject_unregister(&mem->map->kobj);
}
- kset_unregister(&idev->map_attr_kset);
+ kobject_unregister(idev->map_dir);
sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
}

diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index 44c28e9..973386d 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -18,20 +18,22 @@
#include <linux/fs.h>
#include <linux/interrupt.h>

+struct uio_map;
+
/**
* struct uio_mem - description of a UIO memory region
- * @kobj: kobject for this mapping
* @addr: address of the device's memory
* @size: size of IO
* @memtype: type of memory addr points to
* @internal_addr: ioremap-ped version of addr, for driver internal use
+ * @map: for use by the UIO core only.
*/
struct uio_mem {
- struct kobject kobj;
unsigned long addr;
unsigned long size;
int memtype;
void __iomem *internal_addr;
+ struct uio_map *map;
};

#define MAX_UIO_MAPS 5
--
1.5.3.8

2008-01-25 07:58:38

by Greg KH

[permalink] [raw]
Subject: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add

The kobject in the bridge code is only used for registering with sysfs,
not for any lifespan rules. This patch changes it to be only a pointer
and use the simpler api for this kind of thing.

Cc: Stephen Hemminger <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
net/bridge/br_if.c | 2 +-
net/bridge/br_private.h | 2 +-
net/bridge/br_sysfs_br.c | 14 ++++----------
net/bridge/br_sysfs_if.c | 2 +-
4 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 935784f..dadec94 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)
struct net_bridge *br = p->br;
struct net_device *dev = p->dev;

- sysfs_remove_link(&br->ifobj, dev->name);
+ sysfs_remove_link(br->ifobj, dev->name);

dev_set_promiscuity(dev, -1);

diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index f666f7b..c11b554 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -124,7 +124,7 @@ struct net_bridge
struct timer_list tcn_timer;
struct timer_list topology_change_timer;
struct timer_list gc_timer;
- struct kobject ifobj;
+ struct kobject *ifobj;
};

extern struct notifier_block br_device_notifier;
diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 3312e8f..4e7f91f 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev)
goto out2;
}

-
- kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR);
- br->ifobj.ktype = NULL;
- br->ifobj.kset = NULL;
- br->ifobj.parent = brobj;
-
- err = kobject_register(&br->ifobj);
- if (err) {
+ br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
+ if (!br->ifobj) {
pr_info("%s: can't add kobject (directory) %s/%s\n",
- __FUNCTION__, dev->name, kobject_name(&br->ifobj));
+ __FUNCTION__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
goto out3;
}
return 0;
@@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)
struct kobject *kobj = &dev->dev.kobj;
struct net_bridge *br = netdev_priv(dev);

- kobject_unregister(&br->ifobj);
+ kobject_unregister(br->ifobj);
sysfs_remove_bin_file(kobj, &bridge_forward);
sysfs_remove_group(kobj, &bridge_group);
}
diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
index 79db51f..02b2d50 100644
--- a/net/bridge/br_sysfs_if.c
+++ b/net/bridge/br_sysfs_if.c
@@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p)
goto out2;
}

- err= sysfs_create_link(&br->ifobj, &p->kobj, p->dev->name);
+ err = sysfs_create_link(br->ifobj, &p->kobj, p->dev->name);
out2:
return err;
}
--
1.5.3.8

2008-01-25 07:58:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 109/196] Kobject: change GFS2 to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Steven Whitehouse <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/dlm/lockspace.c | 26 ++++----------------------
fs/gfs2/locking/dlm/sysfs.c | 13 +++----------
fs/gfs2/sys.c | 10 +++-------
3 files changed, 10 insertions(+), 39 deletions(-)

diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index e64b0dc..b750f13 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -168,23 +168,6 @@ static struct kobj_type dlm_ktype = {

static struct kset *dlm_kset;

-static int kobject_setup(struct dlm_ls *ls)
-{
- char lsname[DLM_LOCKSPACE_LEN];
- int error;
-
- memset(lsname, 0, DLM_LOCKSPACE_LEN);
- snprintf(lsname, DLM_LOCKSPACE_LEN, "%s", ls->ls_name);
-
- error = kobject_set_name(&ls->ls_kobj, "%s", lsname);
- if (error)
- return error;
-
- ls->ls_kobj.kset = dlm_kset;
- ls->ls_kobj.ktype = &dlm_ktype;
- return 0;
-}
-
static int do_uevent(struct dlm_ls *ls, int in)
{
int error;
@@ -545,13 +528,12 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
goto out_delist;
}

- error = kobject_setup(ls);
- if (error)
- goto out_stop;
-
- error = kobject_register(&ls->ls_kobj);
+ ls->ls_kobj.kset = dlm_kset;
+ error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
+ "%s", ls->ls_name);
if (error)
goto out_stop;
+ kobject_uevent(&ls->ls_kobj, KOBJ_ADD);

/* let kobject handle freeing of ls if there's an error */
do_unreg = 1;
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index e5a4fbf..a7336b9 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -195,19 +195,12 @@ int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
{
int error;

- error = kobject_set_name(&ls->kobj, "%s", "lock_module");
- if (error) {
- log_error("can't set kobj name %d", error);
- return error;
- }
-
ls->kobj.kset = gdlm_kset;
- ls->kobj.ktype = &gdlm_ktype;
- ls->kobj.parent = fskobj;
-
- error = kobject_register(&ls->kobj);
+ error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
+ "lock_module");
if (error)
log_error("can't register kobj %d", error);
+ kobject_uevent(&ls->kobj, KOBJ_ADD);

return error;
}
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 44cfaae..8d9cd5b 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -494,13 +494,8 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
int error;

sdp->sd_kobj.kset = gfs2_kset;
- sdp->sd_kobj.ktype = &gfs2_ktype;
-
- error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name);
- if (error)
- goto fail;
-
- error = kobject_register(&sdp->sd_kobj);
+ error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
+ "%s", sdp->sd_table_name);
if (error)
goto fail;

@@ -520,6 +515,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
if (error)
goto fail_args;

+ kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
return 0;

fail_args:
--
1.5.3.8

2008-01-25 07:59:31

by Greg KH

[permalink] [raw]
Subject: [PATCH 110/196] Kobject: change drivers/infiniband to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Roland Dreier <[email protected]>
Cc: Sean Hefty <[email protected]>
Cc: Hal Rosenstock <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/infiniband/core/sysfs.c | 35 +++++++++--------------------------
include/rdma/ib_verbs.h | 2 +-
2 files changed, 10 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 3d40506..aa81129 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -508,19 +508,10 @@ static int add_port(struct ib_device *device, int port_num)

p->ibdev = device;
p->port_num = port_num;
- p->kobj.ktype = &port_type;

- p->kobj.parent = kobject_get(&device->ports_parent);
- if (!p->kobj.parent) {
- ret = -EBUSY;
- goto err;
- }
-
- ret = kobject_set_name(&p->kobj, "%d", port_num);
- if (ret)
- goto err_put;
-
- ret = kobject_register(&p->kobj);
+ ret = kobject_init_and_add(&p->kobj, &port_type,
+ kobject_get(device->ports_parent),
+ "%d", port_num);
if (ret)
goto err_put;

@@ -549,6 +540,7 @@ static int add_port(struct ib_device *device, int port_num)

list_add_tail(&p->kobj.entry, &device->port_list);

+ kobject_uevent(&p->kobj, KOBJ_ADD);
return 0;

err_free_pkey:
@@ -570,9 +562,7 @@ err_remove_pma:
sysfs_remove_group(&p->kobj, &pma_group);

err_put:
- kobject_put(&device->ports_parent);
-
-err:
+ kobject_put(device->ports_parent);
kfree(p);
return ret;
}
@@ -694,16 +684,9 @@ int ib_device_register_sysfs(struct ib_device *device)
goto err_unregister;
}

- device->ports_parent.parent = kobject_get(&class_dev->kobj);
- if (!device->ports_parent.parent) {
- ret = -EBUSY;
- goto err_unregister;
- }
- ret = kobject_set_name(&device->ports_parent, "ports");
- if (ret)
- goto err_put;
- ret = kobject_register(&device->ports_parent);
- if (ret)
+ device->ports_parent = kobject_create_and_add("ports",
+ kobject_get(&class_dev->kobj));
+ if (!device->ports_parent)
goto err_put;

if (device->node_type == RDMA_NODE_IB_SWITCH) {
@@ -758,7 +741,7 @@ void ib_device_unregister_sysfs(struct ib_device *device)
kobject_unregister(p);
}

- kobject_unregister(&device->ports_parent);
+ kobject_unregister(device->ports_parent);
class_device_unregister(&device->class_dev);
}

diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index 11f3960..cfbd38f 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -1026,7 +1026,7 @@ struct ib_device {

struct module *owner;
struct class_device class_dev;
- struct kobject ports_parent;
+ struct kobject *ports_parent;
struct list_head port_list;

enum {
--
1.5.3.8

2008-01-25 08:03:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 184/196] Driver Core: constify the name passed to platform_device_register_simple

From: Stephen Rothwell <[email protected]>

This name is just passed to platform_device_alloc which has its parameter
declared const.

Signed-off-by: Stephen Rothwell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/platform.c | 2 +-
include/linux/platform_device.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index bdd59e8..48d5db4 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -360,7 +360,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
* the Linux driver model. In particular, when such drivers are built
* as modules, they can't be "hotplugged".
*/
-struct platform_device *platform_device_register_simple(char *name, int id,
+struct platform_device *platform_device_register_simple(const char *name, int id,
struct resource *res, unsigned int num)
{
struct platform_device *pdev;
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index e808043..3261681 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -35,7 +35,7 @@ extern struct resource *platform_get_resource_byname(struct platform_device *, u
extern int platform_get_irq_byname(struct platform_device *, char *);
extern int platform_add_devices(struct platform_device **, int);

-extern struct platform_device *platform_device_register_simple(char *, int id,
+extern struct platform_device *platform_device_register_simple(const char *, int id,
struct resource *, unsigned int);

extern struct platform_device *platform_device_alloc(const char *name, int id);
--
1.5.3.8

2008-01-25 08:03:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 154/196] Driver core: fix race in __device_release_driver

From: Alan Stern <[email protected]>

This patch (as1013) was suggested by David Woodhouse; it fixes a race
in the driver core. If a device is unregistered at the same time as
its driver is unloaded, the driver's code pages may be unmapped while
the remove method is still running. The calls to get_driver() and
put_driver() were intended to prevent this, but they don't work if the
driver's module count has already dropped to 0.

Instead, the patch keeps the device on the driver's list until after
the remove method has returned. This forces the necessary
synchronization to occur.

Signed-off-by: Alan Stern <[email protected]>
Signed-off-by: David Woodhouse <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/dd.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 5492264..b0726eb 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -289,11 +289,10 @@ static void __device_release_driver(struct device * dev)
{
struct device_driver * drv;

- drv = get_driver(dev->driver);
+ drv = dev->driver;
if (drv) {
driver_sysfs_remove(dev);
sysfs_remove_link(&dev->kobj, "driver");
- klist_remove(&dev->knode_driver);

if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -306,7 +305,7 @@ static void __device_release_driver(struct device * dev)
drv->remove(dev);
devres_release_all(dev);
dev->driver = NULL;
- put_driver(drv);
+ klist_remove(&dev->knode_driver);
}
}

--
1.5.3.8

2008-01-25 08:04:01

by Greg KH

[permalink] [raw]
Subject: [PATCH 113/196] Kobject: change drivers/cpufreq/cpufreq.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Dominik Brodowski <[email protected]>
Cc: Ashok Raj <[email protected]>
Cc: Jacob Shin <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/cpufreq/cpufreq.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 79581fa..9e102af 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -828,11 +828,8 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));

/* prepare interface data */
- policy->kobj.parent = &sys_dev->kobj;
- policy->kobj.ktype = &ktype_cpufreq;
- kobject_set_name(&policy->kobj, "cpufreq");
-
- ret = kobject_register(&policy->kobj);
+ ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, &sys_dev->kobj,
+ "cpufreq");
if (ret) {
unlock_policy_rwsem_write(cpu);
goto err_out_driver_exit;
@@ -902,6 +899,7 @@ static int cpufreq_add_dev (struct sys_device * sys_dev)
goto err_out_unregister;
}

+ kobject_uevent(&policy->kobj, KOBJ_ADD);
module_put(cpufreq_driver->owner);
dprintk("initialization complete\n");
cpufreq_debug_enable_ratelimit();
--
1.5.3.8

2008-01-25 08:04:33

by Greg KH

[permalink] [raw]
Subject: [PATCH 163/196] Kobject: remove kobject_add() as no one uses it anymore

The old kobject_add() function is on longer in use, so let us remove it
from the public scope (kset mess in the kobject.c file still uses it,
but that can be cleaned up later very simply.)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 1 -
lib/kobject.c | 22 ++++++++--------------
2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index bb68684..8b0aa71 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -80,7 +80,6 @@ static inline const char * kobject_name(const struct kobject * kobj)

extern void kobject_init(struct kobject *);
extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
-extern int __must_check kobject_add(struct kobject *);
extern int __must_check kobject_add_ng(struct kobject *kobj,
struct kobject *parent,
const char *fmt, ...);
diff --git a/lib/kobject.c b/lib/kobject.c
index 493e991..d04789f 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -144,7 +144,7 @@ void kobject_init(struct kobject * kobj)
* Remove the kobject from the kset list and decrement
* its parent's refcount.
* This is separated out, so we can use it in both
- * kobject_del() and kobject_add() on error.
+ * kobject_del() and kobject_add_internal() on error.
*/

static void unlink(struct kobject * kobj)
@@ -161,12 +161,7 @@ static void unlink(struct kobject * kobj)
kobject_put(parent);
}

-/**
- * kobject_add - add an object to the hierarchy.
- * @kobj: object.
- */
-
-int kobject_add(struct kobject * kobj)
+static int kobject_add_internal(struct kobject *kobj)
{
int error = 0;
struct kobject * parent;
@@ -215,13 +210,13 @@ int kobject_add(struct kobject * kobj)

/* be noisy on error issues */
if (error == -EEXIST)
- printk(KERN_ERR "kobject_add failed for %s with "
+ printk(KERN_ERR "%s failed for %s with "
"-EEXIST, don't try to register things with "
"the same name in the same directory.\n",
- kobject_name(kobj));
+ __FUNCTION__, kobject_name(kobj));
else
- printk(KERN_ERR "kobject_add failed for %s (%d)\n",
- kobject_name(kobj), error);
+ printk(KERN_ERR "%s failed for %s (%d)\n",
+ __FUNCTION__, kobject_name(kobj), error);
dump_stack();
}

@@ -351,7 +346,7 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
return retval;
}
kobj->parent = parent;
- return kobject_add(kobj);
+ return kobject_add_internal(kobj);
}

/**
@@ -742,7 +737,7 @@ struct sysfs_ops kobj_sysfs_ops = {

int kset_add(struct kset * k)
{
- return kobject_add(&k->kobj);
+ return kobject_add_internal(&k->kobj);
}


@@ -897,7 +892,6 @@ EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
EXPORT_SYMBOL(kobject_put);
-EXPORT_SYMBOL(kobject_add);
EXPORT_SYMBOL(kobject_del);

EXPORT_SYMBOL(kset_register);
--
1.5.3.8

2008-01-25 08:04:48

by Greg KH

[permalink] [raw]
Subject: [PATCH 134/196] Kobject: convert kernel/user.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/user.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/kernel/user.c b/kernel/user.c
index 7f17e6e..ab4fd70 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -181,13 +181,12 @@ static int uids_user_create(struct user_struct *up)
int error;

memset(kobj, 0, sizeof(struct kobject));
- kobj->ktype = &uids_ktype;
kobj->kset = uids_kset;
- kobject_init(kobj);
- kobject_set_name(&up->kobj, "%d", up->uid);
- error = kobject_add(kobj);
- if (error)
+ error = kobject_init_and_add(kobj, &uids_ktype, NULL, "%d", up->uid);
+ if (error) {
+ kobject_put(kobj);
goto done;
+ }

kobject_uevent(kobj, KOBJ_ADD);
done:
--
1.5.3.8

2008-01-25 08:05:13

by Greg KH

[permalink] [raw]
Subject: [PATCH 170/196] Modules: remove unneeded release function

Now that kobjects properly clean up their name structures, no matter if
they have a release function or not, we can drop this empty module
kobject release function too (it was needed prior to this because of the
way we handled static kobject names, we based the fact that if a release
function was present, then we could safely free the name string, now we
are more smart about things and only free names we have previously set.)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/params.c | 10 ----------
1 files changed, 0 insertions(+), 10 deletions(-)

diff --git a/kernel/params.c b/kernel/params.c
index 1078b14..b4da950 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -694,18 +694,8 @@ static struct kset_uevent_ops module_uevent_ops = {
struct kset *module_kset;
int module_sysfs_initialized;

-static void module_release(struct kobject *kobj)
-{
- /*
- * Stupid empty release function to allow the memory for the kobject to
- * be properly cleaned up. This will not need to be present for 2.6.25
- * with the upcoming kobject core rework.
- */
-}
-
struct kobj_type module_ktype = {
.sysfs_ops = &module_sysfs_ops,
- .release = module_release,
};

/*
--
1.5.3.8

2008-01-25 08:05:50

by Greg KH

[permalink] [raw]
Subject: [PATCH 192/196] spi: use class iteration api

From: Dave Young <[email protected]>

Convert to use the class iteration api.

Signed-off-by: Dave Young <[email protected]>
Acked-by: David Brownell <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/spi/spi.c | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 93e9de4..682a6a4 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -485,6 +485,15 @@ void spi_unregister_master(struct spi_master *master)
}
EXPORT_SYMBOL_GPL(spi_unregister_master);

+static int __spi_master_match(struct device *dev, void *data)
+{
+ struct spi_master *m;
+ u16 *bus_num = data;
+
+ m = container_of(dev, struct spi_master, dev);
+ return m->bus_num == *bus_num;
+}
+
/**
* spi_busnum_to_master - look up master associated with bus_num
* @bus_num: the master's bus number
@@ -499,17 +508,12 @@ struct spi_master *spi_busnum_to_master(u16 bus_num)
{
struct device *dev;
struct spi_master *master = NULL;
- struct spi_master *m;
-
- down(&spi_master_class.sem);
- list_for_each_entry(dev, &spi_master_class.children, node) {
- m = container_of(dev, struct spi_master, dev);
- if (m->bus_num == bus_num) {
- master = spi_master_get(m);
- break;
- }
- }
- up(&spi_master_class.sem);
+
+ dev = class_find_device(&spi_master_class, &bus_num,
+ __spi_master_match);
+ if (dev)
+ master = container_of(dev, struct spi_master, dev);
+ /* reference got in class_find_device */
return master;
}
EXPORT_SYMBOL_GPL(spi_busnum_to_master);
--
1.5.3.8

2008-01-25 08:06:16

by Greg KH

[permalink] [raw]
Subject: [PATCH 189/196] power supply : use class iteration api

From: Dave Young <[email protected]>

Convert to use the class iteration api.

Signed-off-by: Dave Young <[email protected]>
Cc: Anton Vorontsov <[email protected]>
Cc: David Woodhouse <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/power/apm_power.c | 116 +++++++++++++++++++++---------------
drivers/power/power_supply_core.c | 74 ++++++++++++-----------
2 files changed, 107 insertions(+), 83 deletions(-)

diff --git a/drivers/power/apm_power.c b/drivers/power/apm_power.c
index bbf3ee1..7e29b90 100644
--- a/drivers/power/apm_power.c
+++ b/drivers/power/apm_power.c
@@ -13,6 +13,7 @@
#include <linux/power_supply.h>
#include <linux/apm-emulation.h>

+static DEFINE_MUTEX(apm_mutex);
#define PSY_PROP(psy, prop, val) psy->get_property(psy, \
POWER_SUPPLY_PROP_##prop, val)

@@ -23,67 +24,86 @@

static struct power_supply *main_battery;

-static void find_main_battery(void)
-{
- struct device *dev;
- struct power_supply *bat = NULL;
- struct power_supply *max_charge_bat = NULL;
- struct power_supply *max_energy_bat = NULL;
+struct find_bat_param {
+ struct power_supply *main;
+ struct power_supply *bat;
+ struct power_supply *max_charge_bat;
+ struct power_supply *max_energy_bat;
union power_supply_propval full;
- int max_charge = 0;
- int max_energy = 0;
+ int max_charge;
+ int max_energy;
+};

- main_battery = NULL;
+static int __find_main_battery(struct device *dev, void *data)
+{
+ struct find_bat_param *bp = (struct find_bat_param *)data;

- list_for_each_entry(dev, &power_supply_class->devices, node) {
- bat = dev_get_drvdata(dev);
+ bp->bat = dev_get_drvdata(dev);

- if (bat->use_for_apm) {
- /* nice, we explicitly asked to report this battery. */
- main_battery = bat;
- return;
- }
+ if (bp->bat->use_for_apm) {
+ /* nice, we explicitly asked to report this battery. */
+ bp->main = bp->bat;
+ return 1;
+ }

- if (!PSY_PROP(bat, CHARGE_FULL_DESIGN, &full) ||
- !PSY_PROP(bat, CHARGE_FULL, &full)) {
- if (full.intval > max_charge) {
- max_charge_bat = bat;
- max_charge = full.intval;
- }
- } else if (!PSY_PROP(bat, ENERGY_FULL_DESIGN, &full) ||
- !PSY_PROP(bat, ENERGY_FULL, &full)) {
- if (full.intval > max_energy) {
- max_energy_bat = bat;
- max_energy = full.intval;
- }
+ if (!PSY_PROP(bp->bat, CHARGE_FULL_DESIGN, &bp->full) ||
+ !PSY_PROP(bp->bat, CHARGE_FULL, &bp->full)) {
+ if (bp->full.intval > bp->max_charge) {
+ bp->max_charge_bat = bp->bat;
+ bp->max_charge = bp->full.intval;
+ }
+ } else if (!PSY_PROP(bp->bat, ENERGY_FULL_DESIGN, &bp->full) ||
+ !PSY_PROP(bp->bat, ENERGY_FULL, &bp->full)) {
+ if (bp->full.intval > bp->max_energy) {
+ bp->max_energy_bat = bp->bat;
+ bp->max_energy = bp->full.intval;
}
}
+ return 0;
+}
+
+static void find_main_battery(void)
+{
+ struct find_bat_param bp;
+ int error;
+
+ memset(&bp, 0, sizeof(struct find_bat_param));
+ main_battery = NULL;
+ bp.main = main_battery;
+
+ error = class_for_each_device(power_supply_class, &bp,
+ __find_main_battery);
+ if (error) {
+ main_battery = bp.main;
+ return;
+ }

- if ((max_energy_bat && max_charge_bat) &&
- (max_energy_bat != max_charge_bat)) {
+ if ((bp.max_energy_bat && bp.max_charge_bat) &&
+ (bp.max_energy_bat != bp.max_charge_bat)) {
/* try guess battery with more capacity */
- if (!PSY_PROP(max_charge_bat, VOLTAGE_MAX_DESIGN, &full)) {
- if (max_energy > max_charge * full.intval)
- main_battery = max_energy_bat;
+ if (!PSY_PROP(bp.max_charge_bat, VOLTAGE_MAX_DESIGN,
+ &bp.full)) {
+ if (bp.max_energy > bp.max_charge * bp.full.intval)
+ main_battery = bp.max_energy_bat;
else
- main_battery = max_charge_bat;
- } else if (!PSY_PROP(max_energy_bat, VOLTAGE_MAX_DESIGN,
- &full)) {
- if (max_charge > max_energy / full.intval)
- main_battery = max_charge_bat;
+ main_battery = bp.max_charge_bat;
+ } else if (!PSY_PROP(bp.max_energy_bat, VOLTAGE_MAX_DESIGN,
+ &bp.full)) {
+ if (bp.max_charge > bp.max_energy / bp.full.intval)
+ main_battery = bp.max_charge_bat;
else
- main_battery = max_energy_bat;
+ main_battery = bp.max_energy_bat;
} else {
/* give up, choice any */
- main_battery = max_energy_bat;
+ main_battery = bp.max_energy_bat;
}
- } else if (max_charge_bat) {
- main_battery = max_charge_bat;
- } else if (max_energy_bat) {
- main_battery = max_energy_bat;
+ } else if (bp.max_charge_bat) {
+ main_battery = bp.max_charge_bat;
+ } else if (bp.max_energy_bat) {
+ main_battery = bp.max_energy_bat;
} else {
/* give up, try the last if any */
- main_battery = bat;
+ main_battery = bp.bat;
}
}

@@ -207,10 +227,10 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
union power_supply_propval status;
union power_supply_propval capacity, time_to_full, time_to_empty;

- down(&power_supply_class->sem);
+ mutex_lock(&apm_mutex);
find_main_battery();
if (!main_battery) {
- up(&power_supply_class->sem);
+ mutex_unlock(&apm_mutex);
return;
}

@@ -278,7 +298,7 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)
}
}

- up(&power_supply_class->sem);
+ mutex_unlock(&apm_mutex);
}

static int __init apm_battery_init(void)
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index a63b75c..03d6a38 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -20,28 +20,29 @@

struct class *power_supply_class;

+static int __power_supply_changed_work(struct device *dev, void *data)
+{
+ struct power_supply *psy = (struct power_supply *)data;
+ struct power_supply *pst = dev_get_drvdata(dev);
+ int i;
+
+ for (i = 0; i < psy->num_supplicants; i++)
+ if (!strcmp(psy->supplied_to[i], pst->name)) {
+ if (pst->external_power_changed)
+ pst->external_power_changed(pst);
+ }
+ return 0;
+}
+
static void power_supply_changed_work(struct work_struct *work)
{
struct power_supply *psy = container_of(work, struct power_supply,
changed_work);
- int i;

dev_dbg(psy->dev, "%s\n", __FUNCTION__);

- for (i = 0; i < psy->num_supplicants; i++) {
- struct device *dev;
-
- down(&power_supply_class->sem);
- list_for_each_entry(dev, &power_supply_class->devices, node) {
- struct power_supply *pst = dev_get_drvdata(dev);
-
- if (!strcmp(psy->supplied_to[i], pst->name)) {
- if (pst->external_power_changed)
- pst->external_power_changed(pst);
- }
- }
- up(&power_supply_class->sem);
- }
+ class_for_each_device(power_supply_class, psy,
+ __power_supply_changed_work);

power_supply_update_leds(psy);

@@ -55,32 +56,35 @@ void power_supply_changed(struct power_supply *psy)
schedule_work(&psy->changed_work);
}

-int power_supply_am_i_supplied(struct power_supply *psy)
+static int __power_supply_am_i_supplied(struct device *dev, void *data)
{
union power_supply_propval ret = {0,};
- struct device *dev;
-
- down(&power_supply_class->sem);
- list_for_each_entry(dev, &power_supply_class->devices, node) {
- struct power_supply *epsy = dev_get_drvdata(dev);
- int i;
-
- for (i = 0; i < epsy->num_supplicants; i++) {
- if (!strcmp(epsy->supplied_to[i], psy->name)) {
- if (epsy->get_property(epsy,
- POWER_SUPPLY_PROP_ONLINE, &ret))
- continue;
- if (ret.intval)
- goto out;
- }
+ struct power_supply *psy = (struct power_supply *)data;
+ struct power_supply *epsy = dev_get_drvdata(dev);
+ int i;
+
+ for (i = 0; i < epsy->num_supplicants; i++) {
+ if (!strcmp(epsy->supplied_to[i], psy->name)) {
+ if (epsy->get_property(epsy,
+ POWER_SUPPLY_PROP_ONLINE, &ret))
+ continue;
+ if (ret.intval)
+ return ret.intval;
}
}
-out:
- up(&power_supply_class->sem);
+ return 0;
+}
+
+int power_supply_am_i_supplied(struct power_supply *psy)
+{
+ int error;
+
+ error = class_for_each_device(power_supply_class, psy,
+ __power_supply_am_i_supplied);

- dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, ret.intval);
+ dev_dbg(psy->dev, "%s %d\n", __FUNCTION__, error);

- return ret.intval;
+ return error;
}

int power_supply_register(struct device *parent, struct power_supply *psy)
--
1.5.3.8

2008-01-25 08:06:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 182/196] sysfs: make SYSFS_DEPRECATED depend on SYSFS

From: Randy Dunlap <[email protected]>

Make SYSFS_DEPRECATED depend on SYSFS since files that check
CONFIG_SYSFS_DEPRECATED don't check for CONFIG_SYSFS first.
Also don't prompt user about SYSFS_DEPRECATED if SYSFS=n.

Signed-off-by: Randy Dunlap <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
init/Kconfig | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/init/Kconfig b/init/Kconfig
index b9d11a8..f5becd2 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -363,6 +363,7 @@ config CGROUP_CPUACCT

config SYSFS_DEPRECATED
bool "Create deprecated sysfs files"
+ depends on SYSFS
default y
help
This option creates deprecated symlinks such as the
--
1.5.3.8

2008-01-25 08:06:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 177/196] kobject: remove old, outdated documentation.

As we are replacing the documentation, it's easier to do this in a two
stage pass, delete the old file and add the new one.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/kobject.txt | 289 ---------------------------------------------
1 files changed, 0 insertions(+), 289 deletions(-)
delete mode 100644 Documentation/kobject.txt

diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
deleted file mode 100644
index ca86a88..0000000
--- a/Documentation/kobject.txt
+++ /dev/null
@@ -1,289 +0,0 @@
-The kobject Infrastructure
-
-Patrick Mochel <[email protected]>
-
-Updated: 3 June 2003
-
-
-Copyright (c) 2003 Patrick Mochel
-Copyright (c) 2003 Open Source Development Labs
-
-
-0. Introduction
-
-The kobject infrastructure performs basic object management that larger
-data structures and subsystems can leverage, rather than reimplement
-similar functionality. This functionality primarily concerns:
-
-- Object reference counting.
-- Maintaining lists (sets) of objects.
-- Object set locking.
-- Userspace representation.
-
-The infrastructure consists of a number of object types to support
-this functionality. Their programming interfaces are described below
-in detail, and briefly here:
-
-- kobjects a simple object.
-- kset a set of objects of a certain type.
-- ktype a set of helpers for objects of a common type.
-
-
-The kobject infrastructure maintains a close relationship with the
-sysfs filesystem. Each kobject that is registered with the kobject
-core receives a directory in sysfs. Attributes about the kobject can
-then be exported. Please see Documentation/filesystems/sysfs.txt for
-more information.
-
-The kobject infrastructure provides a flexible programming interface,
-and allows kobjects and ksets to be used without being registered
-(i.e. with no sysfs representation). This is also described later.
-
-
-1. kobjects
-
-1.1 Description
-
-
-struct kobject is a simple data type that provides a foundation for
-more complex object types. It provides a set of basic fields that
-almost all complex data types share. kobjects are intended to be
-embedded in larger data structures and replace fields they duplicate.
-
-1.2 Definition
-
-struct kobject {
- const char * k_name;
- struct kref kref;
- struct list_head entry;
- struct kobject * parent;
- struct kset * kset;
- struct kobj_type * ktype;
- struct sysfs_dirent * sd;
- wait_queue_head_t poll;
-};
-
-void kobject_init(struct kobject *);
-int kobject_add(struct kobject *);
-int kobject_register(struct kobject *);
-
-void kobject_del(struct kobject *);
-void kobject_unregister(struct kobject *);
-
-struct kobject * kobject_get(struct kobject *);
-void kobject_put(struct kobject *);
-
-
-1.3 kobject Programming Interface
-
-kobjects may be dynamically added and removed from the kobject core
-using kobject_register() and kobject_unregister(). Registration
-includes inserting the kobject in the list of its dominant kset and
-creating a directory for it in sysfs.
-
-Alternatively, one may use a kobject without adding it to its kset's list
-or exporting it via sysfs, by simply calling kobject_init(). An
-initialized kobject may later be added to the object hierarchy by
-calling kobject_add(). An initialized kobject may be used for
-reference counting.
-
-Note: calling kobject_init() then kobject_add() is functionally
-equivalent to calling kobject_register().
-
-When a kobject is unregistered, it is removed from its kset's list,
-removed from the sysfs filesystem, and its reference count is decremented.
-List and sysfs removal happen in kobject_del(), and may be called
-manually. kobject_put() decrements the reference count, and may also
-be called manually.
-
-A kobject's reference count may be incremented with kobject_get(),
-which returns a valid reference to a kobject; and decremented with
-kobject_put(). An object's reference count may only be incremented if
-it is already positive.
-
-When a kobject's reference count reaches 0, the method struct
-kobj_type::release() (which the kobject's kset points to) is called.
-This allows any memory allocated for the object to be freed.
-
-
-NOTE!!!
-
-It is _imperative_ that you supply a destructor for dynamically
-allocated kobjects to free them if you are using kobject reference
-counts. The reference count controls the lifetime of the object.
-If it goes to 0, then it is assumed that the object will
-be freed and cannot be used.
-
-More importantly, you must free the object there, and not immediately
-after an unregister call. If someone else is referencing the object
-(e.g. through a sysfs file), they will obtain a reference to the
-object, assume it's valid and operate on it. If the object is
-unregistered and freed in the meantime, the operation will then
-reference freed memory and go boom.
-
-This can be prevented, in the simplest case, by defining a release
-method and freeing the object from there only. Note that this will not
-secure reference count/object management models that use a dual
-reference count or do other wacky things with the reference count
-(like the networking layer).
-
-
-1.4 sysfs
-
-Each kobject receives a directory in sysfs. This directory is created
-under the kobject's parent directory.
-
-If a kobject does not have a parent when it is registered, its parent
-becomes its dominant kset.
-
-If a kobject does not have a parent nor a dominant kset, its directory
-is created at the top-level of the sysfs partition.
-
-
-
-2. ksets
-
-2.1 Description
-
-A kset is a set of kobjects that are embedded in the same type.
-
-
-struct kset {
- struct kobj_type * ktype;
- struct list_head list;
- struct kobject kobj;
- struct kset_uevent_ops * uevent_ops;
-};
-
-
-void kset_init(struct kset * k);
-int kset_add(struct kset * k);
-int kset_register(struct kset * k);
-void kset_unregister(struct kset * k);
-
-struct kset * kset_get(struct kset * k);
-void kset_put(struct kset * k);
-
-struct kobject * kset_find_obj(struct kset *, char *);
-
-
-The type that the kobjects are embedded in is described by the ktype
-pointer.
-
-A kset contains a kobject itself, meaning that it may be registered in
-the kobject hierarchy and exported via sysfs. More importantly, the
-kset may be embedded in a larger data type, and may be part of another
-kset (of that object type).
-
-For example, a block device is an object (struct gendisk) that is
-contained in a set of block devices. It may also contain a set of
-partitions (struct hd_struct) that have been found on the device. The
-following code snippet illustrates how to express this properly.
-
- struct gendisk * disk;
- ...
- disk->kset.kobj.kset = &block_kset;
- disk->kset.ktype = &partition_ktype;
- kset_register(&disk->kset);
-
-- The kset that the disk's embedded object belongs to is the
- block_kset, and is pointed to by disk->kset.kobj.kset.
-
-- The type of objects on the disk's _subordinate_ list are partitions,
- and is set in disk->kset.ktype.
-
-- The kset is then registered, which handles initializing and adding
- the embedded kobject to the hierarchy.
-
-
-2.2 kset Programming Interface
-
-All kset functions, except kset_find_obj(), eventually forward the
-calls to their embedded kobjects after performing kset-specific
-operations. ksets offer a similar programming model to kobjects: they
-may be used after they are initialized, without registering them in
-the hierarchy.
-
-kset_find_obj() may be used to locate a kobject with a particular
-name. The kobject, if found, is returned.
-
-There are also some helper functions which names point to the formerly
-existing "struct subsystem", whose functions have been taken over by
-ksets.
-
-
-decl_subsys(name,type,uevent_ops)
-
-Declares a kset named '<name>_subsys' of type <type> with
-uevent_ops <uevent_ops>. For example,
-
-decl_subsys(devices, &ktype_device, &device_uevent_ops);
-
-is equivalent to doing:
-
-struct kset devices_subsys = {
- .ktype = &ktype_devices,
- .uevent_ops = &device_uevent_ops,
-};
-kobject_set_name(&devices_subsys, name);
-
-The objects that are registered with a subsystem that use the
-subsystem's default list must have their kset ptr set properly. These
-objects may have embedded kobjects or ksets. The
-following helper makes setting the kset easier:
-
-
-kobj_set_kset_s(obj,subsys)
-
-- Assumes that obj->kobj exists, and is a struct kobject.
-- Sets the kset of that kobject to the kset <subsys>.
-
-int subsystem_register(struct kset *s);
-void subsystem_unregister(struct kset *s);
-
-These are just wrappers around the respective kset_* functions.
-
-2.3 sysfs
-
-ksets are represented in sysfs when their embedded kobjects are
-registered. They follow the same rules of parenting, with one
-exception. If a kset does not have a parent, nor is its embedded
-kobject part of another kset, the kset's parent becomes its dominant
-subsystem.
-
-If the kset does not have a parent, its directory is created at the
-sysfs root. This should only happen when the kset registered is
-embedded in a subsystem itself.
-
-
-3. struct ktype
-
-3.1. Description
-
-struct kobj_type {
- void (*release)(struct kobject *);
- struct sysfs_ops * sysfs_ops;
- struct attribute ** default_attrs;
-};
-
-
-Object types require specific functions for converting between the
-generic object and the more complex type. struct kobj_type provides
-the object-specific fields, which include:
-
-- release: Called when the kobject's reference count reaches 0. This
- should convert the object to the more complex type and free it.
-
-- sysfs_ops: Provides conversion functions for sysfs access. Please
- see the sysfs documentation for more information.
-
-- default_attrs: Default attributes to be exported via sysfs when the
- object is registered.Note that the last attribute has to be
- initialized to NULL ! You can find a complete implementation
- in block/genhd.c
-
-
-Instances of struct kobj_type are not registered; only referenced by
-the kset. A kobj_type may be referenced by an arbitrary number of
-ksets, as there may be disparate sets of identical objects.
-
--
1.5.3.8

2008-01-25 08:07:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 124/196] Kobject: change arch/ia64/kernel/topology.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Tony Luck <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/ia64/kernel/topology.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index 14261fe..c4311e3 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -354,17 +354,16 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
if (unlikely(retval < 0))
return retval;

- all_cpu_cache_info[cpu].kobj.parent = &sys_dev->kobj;
- kobject_set_name(&all_cpu_cache_info[cpu].kobj, "%s", "cache");
- all_cpu_cache_info[cpu].kobj.ktype = &cache_ktype_percpu_entry;
- retval = kobject_register(&all_cpu_cache_info[cpu].kobj);
+ retval = kobject_init_and_add(&all_cpu_cache_info[cpu].kobj,
+ &cache_ktype_percpu_entry, &sys_dev->kobj,
+ "%s", "cache");

for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++) {
this_object = LEAF_KOBJECT_PTR(cpu,i);
- this_object->kobj.parent = &all_cpu_cache_info[cpu].kobj;
- kobject_set_name(&(this_object->kobj), "index%1lu", i);
- this_object->kobj.ktype = &cache_ktype;
- retval = kobject_register(&(this_object->kobj));
+ retval = kobject_init_and_add(&(this_object->kobj),
+ &cache_ktype,
+ &all_cpu_cache_info[cpu].kobj,
+ "index%1lu", i);
if (unlikely(retval)) {
for (j = 0; j < i; j++) {
kobject_unregister(
@@ -374,7 +373,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
cpu_cache_sysfs_exit(cpu);
break;
}
+ kobject_uevent(&(this_object->kobj), KOBJ_ADD);
}
+ kobject_uevent(&all_cpu_cache_info[cpu].kobj, KOBJ_ADD);
return retval;
}

--
1.5.3.8

2008-01-25 08:07:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 153/196] Kobject: change drivers/base/bus to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 10 ++++------
1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 937fc10..aea5793 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -643,15 +643,12 @@ int bus_add_driver(struct device_driver *drv)
if (!priv)
return -ENOMEM;

- error = kobject_set_name(&priv->kobj, "%s", drv->name);
- if (error)
- goto out_put_bus;
- priv->kobj.kset = bus->p->drivers_kset;
- priv->kobj.ktype = &driver_ktype;
klist_init(&priv->klist_devices, NULL, NULL);
priv->driver = drv;
drv->p = priv;
- error = kobject_register(&priv->kobj);
+ priv->kobj.kset = bus->p->drivers_kset;
+ error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
+ "%s", drv->name);
if (error)
goto out_put_bus;

@@ -681,6 +678,7 @@ int bus_add_driver(struct device_driver *drv)
__FUNCTION__, drv->name);
}

+ kobject_uevent(&priv->kobj, KOBJ_ADD);
return error;
out_unregister:
kobject_unregister(&priv->kobj);
--
1.5.3.8

2008-01-25 08:08:24

by Greg KH

[permalink] [raw]
Subject: [PATCH 190/196] rtc: use class iteration api

From: Dave Young <[email protected]>

Convert to use the class iteration api.

Signed-off-by: Dave Young <[email protected]>
Cc: Alessandro Zummo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/rtc/interface.c | 22 ++++++++++++----------
1 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index f1e00ff..7e3ad4f 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -251,20 +251,23 @@ void rtc_update_irq(struct rtc_device *rtc,
}
EXPORT_SYMBOL_GPL(rtc_update_irq);

+static int __rtc_match(struct device *dev, void *data)
+{
+ char *name = (char *)data;
+
+ if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0)
+ return 1;
+ return 0;
+}
+
struct rtc_device *rtc_class_open(char *name)
{
struct device *dev;
struct rtc_device *rtc = NULL;

- down(&rtc_class->sem);
- list_for_each_entry(dev, &rtc_class->devices, node) {
- if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0) {
- dev = get_device(dev);
- if (dev)
- rtc = to_rtc_device(dev);
- break;
- }
- }
+ dev = class_find_device(rtc_class, name, __rtc_match);
+ if (dev)
+ rtc = to_rtc_device(dev);

if (rtc) {
if (!try_module_get(rtc->owner)) {
@@ -272,7 +275,6 @@ struct rtc_device *rtc_class_open(char *name)
rtc = NULL;
}
}
- up(&rtc_class->sem);

return rtc;
}
--
1.5.3.8

2008-01-25 08:08:40

by Greg KH

[permalink] [raw]
Subject: [PATCH 188/196] ieee1394: use class iteration api

From: Dave Young <[email protected]>

Convert to use the class iteration api.

Signed-off-by: Dave Young <[email protected]>
Cc: Stefan Richter <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/ieee1394/nodemgr.c | 314 +++++++++++++++++++++++++-------------------
1 files changed, 176 insertions(+), 138 deletions(-)

diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 90dc75b..511e432 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -727,33 +727,31 @@ static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)

static DEFINE_MUTEX(nodemgr_serialize_remove_uds);

+static int __match_ne(struct device *dev, void *data)
+{
+ struct unit_directory *ud;
+ struct node_entry *ne = (struct node_entry *)data;
+
+ ud = container_of(dev, struct unit_directory, unit_dev);
+ return ud->ne == ne;
+}
+
static void nodemgr_remove_uds(struct node_entry *ne)
{
struct device *dev;
- struct unit_directory *tmp, *ud;
-
- /* Iteration over nodemgr_ud_class.devices has to be protected by
- * nodemgr_ud_class.sem, but device_unregister() will eventually
- * take nodemgr_ud_class.sem too. Therefore pick out one ud at a time,
- * release the semaphore, and then unregister the ud. Since this code
- * may be called from other contexts besides the knodemgrds, protect the
- * gap after release of the semaphore by nodemgr_serialize_remove_uds.
+ struct unit_directory *ud;
+
+ /* Use class_find device to iterate the devices. Since this code
+ * may be called from other contexts besides the knodemgrds,
+ * protect it by nodemgr_serialize_remove_uds.
*/
mutex_lock(&nodemgr_serialize_remove_uds);
for (;;) {
- ud = NULL;
- down(&nodemgr_ud_class.sem);
- list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
- tmp = container_of(dev, struct unit_directory,
- unit_dev);
- if (tmp->ne == ne) {
- ud = tmp;
- break;
- }
- }
- up(&nodemgr_ud_class.sem);
- if (ud == NULL)
+ dev = class_find_device(&nodemgr_ud_class, ne, __match_ne);
+ if (!dev)
break;
+ ud = container_of(dev, struct unit_directory, unit_dev);
+ put_device(dev);
device_unregister(&ud->unit_dev);
device_unregister(&ud->device);
}
@@ -882,45 +880,66 @@ fail_alloc:
return NULL;
}

+static int __match_ne_guid(struct device *dev, void *data)
+{
+ struct node_entry *ne;
+ u64 *guid = (u64 *)data;
+
+ ne = container_of(dev, struct node_entry, node_dev);
+ return ne->guid == *guid;
+}

static struct node_entry *find_entry_by_guid(u64 guid)
{
struct device *dev;
- struct node_entry *ne, *ret_ne = NULL;
-
- down(&nodemgr_ne_class.sem);
- list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
- ne = container_of(dev, struct node_entry, node_dev);
+ struct node_entry *ne;

- if (ne->guid == guid) {
- ret_ne = ne;
- break;
- }
- }
- up(&nodemgr_ne_class.sem);
+ dev = class_find_device(&nodemgr_ne_class, &guid, __match_ne_guid);
+ if (!dev)
+ return NULL;
+ ne = container_of(dev, struct node_entry, node_dev);
+ put_device(dev);

- return ret_ne;
+ return ne;
}

+struct match_nodeid_param {
+ struct hpsb_host *host;
+ nodeid_t nodeid;
+};
+
+static int __match_ne_nodeid(struct device *dev, void *data)
+{
+ int found = 0;
+ struct node_entry *ne;
+ struct match_nodeid_param *param = (struct match_nodeid_param *)data;
+
+ if (!dev)
+ goto ret;
+ ne = container_of(dev, struct node_entry, node_dev);
+ if (ne->host == param->host && ne->nodeid == param->nodeid)
+ found = 1;
+ret:
+ return found;
+}

static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
nodeid_t nodeid)
{
struct device *dev;
- struct node_entry *ne, *ret_ne = NULL;
+ struct node_entry *ne;
+ struct match_nodeid_param param;

- down(&nodemgr_ne_class.sem);
- list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
- ne = container_of(dev, struct node_entry, node_dev);
+ param.host = host;
+ param.nodeid = nodeid;

- if (ne->host == host && ne->nodeid == nodeid) {
- ret_ne = ne;
- break;
- }
- }
- up(&nodemgr_ne_class.sem);
+ dev = class_find_device(&nodemgr_ne_class, &param, __match_ne_nodeid);
+ if (!dev)
+ return NULL;
+ ne = container_of(dev, struct node_entry, node_dev);
+ put_device(dev);

- return ret_ne;
+ return ne;
}


@@ -1370,107 +1389,109 @@ static void nodemgr_node_scan(struct host_info *hi, int generation)
}
}

-
-static void nodemgr_suspend_ne(struct node_entry *ne)
+static int __nodemgr_driver_suspend(struct device *dev, void *data)
{
- struct device *dev;
struct unit_directory *ud;
struct device_driver *drv;
+ struct node_entry *ne = (struct node_entry *)data;
int error;

- HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
- NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
+ ud = container_of(dev, struct unit_directory, unit_dev);
+ if (ud->ne == ne) {
+ drv = get_driver(ud->device.driver);
+ if (drv) {
+ error = 1; /* release if suspend is not implemented */
+ if (drv->suspend) {
+ down(&ud->device.sem);
+ error = drv->suspend(&ud->device, PMSG_SUSPEND);
+ up(&ud->device.sem);
+ }
+ if (error)
+ device_release_driver(&ud->device);
+ put_driver(drv);
+ }
+ }

- ne->in_limbo = 1;
- WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
+ return 0;
+}

- down(&nodemgr_ud_class.sem);
- list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
- ud = container_of(dev, struct unit_directory, unit_dev);
- if (ud->ne != ne)
- continue;
+static int __nodemgr_driver_resume(struct device *dev, void *data)
+{
+ struct unit_directory *ud;
+ struct device_driver *drv;
+ struct node_entry *ne = (struct node_entry *)data;

+ ud = container_of(dev, struct unit_directory, unit_dev);
+ if (ud->ne == ne) {
drv = get_driver(ud->device.driver);
- if (!drv)
- continue;
-
- error = 1; /* release if suspend is not implemented */
- if (drv->suspend) {
- down(&ud->device.sem);
- error = drv->suspend(&ud->device, PMSG_SUSPEND);
- up(&ud->device.sem);
+ if (drv) {
+ if (drv->resume) {
+ down(&ud->device.sem);
+ drv->resume(&ud->device);
+ up(&ud->device.sem);
+ }
+ put_driver(drv);
}
- if (error)
- device_release_driver(&ud->device);
- put_driver(drv);
}
- up(&nodemgr_ud_class.sem);
-}

+ return 0;
+}

-static void nodemgr_resume_ne(struct node_entry *ne)
+static void nodemgr_suspend_ne(struct node_entry *ne)
{
- struct device *dev;
- struct unit_directory *ud;
- struct device_driver *drv;
+ HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
+ NODE_BUS_ARGS(ne->host, ne->nodeid),
+ (unsigned long long)ne->guid);

- ne->in_limbo = 0;
- device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
+ ne->in_limbo = 1;
+ WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));

- down(&nodemgr_ud_class.sem);
- list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
- ud = container_of(dev, struct unit_directory, unit_dev);
- if (ud->ne != ne)
- continue;
+ class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend);
+}

- drv = get_driver(ud->device.driver);
- if (!drv)
- continue;

- if (drv->resume) {
- down(&ud->device.sem);
- drv->resume(&ud->device);
- up(&ud->device.sem);
- }
- put_driver(drv);
- }
- up(&nodemgr_ud_class.sem);
+static void nodemgr_resume_ne(struct node_entry *ne)
+{
+ ne->in_limbo = 0;
+ device_remove_file(&ne->device, &dev_attr_ne_in_limbo);

+ class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume);
HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
}

-
-static void nodemgr_update_pdrv(struct node_entry *ne)
+static int __nodemgr_update_pdrv(struct device *dev, void *data)
{
- struct device *dev;
struct unit_directory *ud;
struct device_driver *drv;
struct hpsb_protocol_driver *pdrv;
+ struct node_entry *ne = (struct node_entry *)data;
int error;

- down(&nodemgr_ud_class.sem);
- list_for_each_entry(dev, &nodemgr_ud_class.devices, node) {
- ud = container_of(dev, struct unit_directory, unit_dev);
- if (ud->ne != ne)
- continue;
-
+ ud = container_of(dev, struct unit_directory, unit_dev);
+ if (ud->ne == ne) {
drv = get_driver(ud->device.driver);
- if (!drv)
- continue;
-
- error = 0;
- pdrv = container_of(drv, struct hpsb_protocol_driver, driver);
- if (pdrv->update) {
- down(&ud->device.sem);
- error = pdrv->update(ud);
- up(&ud->device.sem);
+ if (drv) {
+ error = 0;
+ pdrv = container_of(drv, struct hpsb_protocol_driver,
+ driver);
+ if (pdrv->update) {
+ down(&ud->device.sem);
+ error = pdrv->update(ud);
+ up(&ud->device.sem);
+ }
+ if (error)
+ device_release_driver(&ud->device);
+ put_driver(drv);
}
- if (error)
- device_release_driver(&ud->device);
- put_driver(drv);
}
- up(&nodemgr_ud_class.sem);
+
+ return 0;
+}
+
+static void nodemgr_update_pdrv(struct node_entry *ne)
+{
+ class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv);
}


@@ -1529,13 +1550,31 @@ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int ge
put_device(dev);
}

+struct probe_param {
+ struct host_info *hi;
+ int generation;
+};
+
+static int __nodemgr_node_probe(struct device *dev, void *data)
+{
+ struct probe_param *param = (struct probe_param *)data;
+ struct node_entry *ne;
+
+ ne = container_of(dev, struct node_entry, node_dev);
+ if (!ne->needs_probe)
+ nodemgr_probe_ne(param->hi, ne, param->generation);
+ if (ne->needs_probe)
+ nodemgr_probe_ne(param->hi, ne, param->generation);
+ return 0;
+}

static void nodemgr_node_probe(struct host_info *hi, int generation)
{
struct hpsb_host *host = hi->host;
- struct device *dev;
- struct node_entry *ne;
+ struct probe_param param;

+ param.hi = hi;
+ param.generation = generation;
/* Do some processing of the nodes we've probed. This pulls them
* into the sysfs layer if needed, and can result in processing of
* unit-directories, or just updating the node and it's
@@ -1545,19 +1584,7 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
* while probes are time-consuming. (Well, those probes need some
* improvement...) */

- down(&nodemgr_ne_class.sem);
- list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
- ne = container_of(dev, struct node_entry, node_dev);
- if (!ne->needs_probe)
- nodemgr_probe_ne(hi, ne, generation);
- }
- list_for_each_entry(dev, &nodemgr_ne_class.devices, node) {
- ne = container_of(dev, struct node_entry, node_dev);
- if (ne->needs_probe)
- nodemgr_probe_ne(hi, ne, generation);
- }
- up(&nodemgr_ne_class.sem);
-
+ class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe);

/* If we had a bus reset while we were scanning the bus, it is
* possible that we did not probe all nodes. In that case, we
@@ -1757,6 +1784,22 @@ exit:
return 0;
}

+struct host_iter_param {
+ void *data;
+ int (*cb)(struct hpsb_host *, void *);
+};
+
+static int __nodemgr_for_each_host(struct device *dev, void *data)
+{
+ struct hpsb_host *host;
+ struct host_iter_param *hip = (struct host_iter_param *)data;
+ int error = 0;
+
+ host = container_of(dev, struct hpsb_host, host_dev);
+ error = hip->cb(host, hip->data);
+
+ return error;
+}
/**
* nodemgr_for_each_host - call a function for each IEEE 1394 host
* @data: an address to supply to the callback
@@ -1771,18 +1814,13 @@ exit:
*/
int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
{
- struct device *dev;
- struct hpsb_host *host;
- int error = 0;
-
- down(&hpsb_host_class.sem);
- list_for_each_entry(dev, &hpsb_host_class.devices, node) {
- host = container_of(dev, struct hpsb_host, host_dev);
+ struct host_iter_param hip;
+ int error;

- if ((error = cb(host, data)))
- break;
- }
- up(&hpsb_host_class.sem);
+ hip.cb = cb;
+ hip.data = data;
+ error = class_for_each_device(&hpsb_host_class, &hip,
+ __nodemgr_for_each_host);

return error;
}
--
1.5.3.8

2008-01-25 08:08:55

by Greg KH

[permalink] [raw]
Subject: [PATCH 111/196] Kobject: change drivers/firmware/edd.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Matt Domsch <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/edd.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index ddcc957..dc0b87b 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -721,13 +721,13 @@ edd_device_register(struct edd_device *edev, int i)
if (!edev)
return 1;
edd_dev_set_info(edev, i);
- kobject_set_name(&edev->kobj, "int13_dev%02x",
- 0x80 + i);
edev->kobj.kset = edd_kset;
- edev->kobj.ktype = &edd_ktype;
- error = kobject_register(&edev->kobj);
- if (!error)
+ error = kobject_init_and_add(&edev->kobj, &edd_ktype, NULL,
+ "int13_dev%02x", 0x80 + i);
+ if (!error) {
edd_populate_dir(edev);
+ kobject_uevent(&edev->kobj, KOBJ_ADD);
+ }
return error;
}

--
1.5.3.8

2008-01-25 08:09:25

by Greg KH

[permalink] [raw]
Subject: [PATCH 172/196] Kobject: convert drivers/* from kobject_unregister() to kobject_put()

There is no need for kobject_unregister() anymore, thanks to Kay's
kobject cleanup changes, so replace all instances of it with
kobject_put().


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 4 ++--
drivers/base/sys.c | 2 +-
drivers/block/pktcdvd.c | 2 +-
drivers/cpufreq/cpufreq.c | 4 +---
drivers/cpuidle/sysfs.c | 4 ++--
drivers/edac/edac_device_sysfs.c | 10 +++++-----
drivers/edac/edac_mc_sysfs.c | 12 ++++++------
drivers/edac/edac_pci_sysfs.c | 6 +++---
drivers/firmware/edd.c | 2 +-
drivers/firmware/efivars.c | 6 +++---
drivers/infiniband/core/sysfs.c | 6 +++---
drivers/md/md.c | 2 +-
drivers/net/ibmveth.c | 2 +-
drivers/parisc/pdc_stable.c | 6 +++---
drivers/pci/hotplug/pci_hotplug_core.c | 2 +-
drivers/pci/hotplug/rpadlpar_sysfs.c | 4 ++--
drivers/uio/uio.c | 8 ++++----
17 files changed, 40 insertions(+), 42 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index aea5793..a377b65 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -681,7 +681,7 @@ int bus_add_driver(struct device_driver *drv)
kobject_uevent(&priv->kobj, KOBJ_ADD);
return error;
out_unregister:
- kobject_unregister(&priv->kobj);
+ kobject_put(&priv->kobj);
out_put_bus:
bus_put(bus);
return error;
@@ -708,7 +708,7 @@ void bus_remove_driver(struct device_driver * drv)
pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name);
driver_detach(drv);
module_remove_driver(drv);
- kobject_unregister(&drv->p->kobj);
+ kobject_put(&drv->p->kobj);
bus_put(drv->bus);
}

diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 47fc6eb..e666441 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -264,7 +264,7 @@ void sysdev_unregister(struct sys_device * sysdev)
}
mutex_unlock(&sysdev_drivers_lock);

- kobject_unregister(&sysdev->kobj);
+ kobject_put(&sysdev->kobj);
}


diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index d1ee383..e9de171 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -130,7 +130,7 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
static void pkt_kobj_remove(struct pktcdvd_kobj *p)
{
if (p)
- kobject_unregister(&p->kobj);
+ kobject_put(&p->kobj);
}
/*
* default release function for pktcdvd kernel objects.
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 9e102af..5efd555 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -913,7 +913,7 @@ err_out_unregister:
cpufreq_cpu_data[j] = NULL;
spin_unlock_irqrestore(&cpufreq_driver_lock, flags);

- kobject_unregister(&policy->kobj);
+ kobject_put(&policy->kobj);
wait_for_completion(&policy->kobj_unregister);

err_out_driver_exit:
@@ -1030,8 +1030,6 @@ static int __cpufreq_remove_dev (struct sys_device * sys_dev)

unlock_policy_rwsem_write(cpu);

- kobject_unregister(&data->kobj);
-
kobject_put(&data->kobj);

/* we need to make sure that the underlying kobj is actually
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 059db9c..088ea74 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -277,7 +277,7 @@ static struct kobj_type ktype_state_cpuidle = {

static void inline cpuidle_free_state_kobj(struct cpuidle_device *device, int i)
{
- kobject_unregister(&device->kobjs[i]->kobj);
+ kobject_put(&device->kobjs[i]->kobj);
wait_for_completion(&device->kobjs[i]->kobj_unregister);
kfree(device->kobjs[i]);
device->kobjs[i] = NULL;
@@ -358,5 +358,5 @@ void cpuidle_remove_sysfs(struct sys_device *sysdev)
struct cpuidle_device *dev;

dev = per_cpu(cpuidle_devices, cpu);
- kobject_unregister(&dev->kobj);
+ kobject_put(&dev->kobj);
}
diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 10e5b19..5376457 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -303,7 +303,7 @@ void edac_device_unregister_sysfs_main_kobj(
* a) module_put() this module
* b) 'kfree' the memory
*/
- kobject_unregister(&edac_dev->kobj);
+ kobject_put(&edac_dev->kobj);
}

/* edac_dev -> instance information */
@@ -574,7 +574,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,

/* Error unwind stack */
err_on_attrib:
- kobject_unregister(&block->kobj);
+ kobject_put(&block->kobj);

err_out:
return err;
@@ -605,7 +605,7 @@ static void edac_device_delete_block(struct edac_device_ctl_info *edac_dev,
/* unregister this block's kobject, SEE:
* edac_device_ctrl_block_release() callback operation
*/
- kobject_unregister(&block->kobj);
+ kobject_put(&block->kobj);
}

/* instance ctor/dtor code */
@@ -672,7 +672,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,

/* error unwind stack */
err_release_instance_kobj:
- kobject_unregister(&instance->kobj);
+ kobject_put(&instance->kobj);

err_out:
return err;
@@ -697,7 +697,7 @@ static void edac_device_delete_instance(struct edac_device_ctl_info *edac_dev,
/* unregister this instance's kobject, SEE:
* edac_device_ctrl_instance_release() for callback operation
*/
- kobject_unregister(&instance->kobj);
+ kobject_put(&instance->kobj);
}

/*
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 45b1d36..9aac880 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -395,7 +395,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
goto err_release_top_kobj;

/* At this point, to release a csrow kobj, one must
- * call the kobject_unregister and allow that tear down
+ * call the kobject_put and allow that tear down
* to work the releasing
*/

@@ -406,7 +406,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
err = edac_create_channel_files(&csrow->kobj, chan);
if (err) {
/* special case the unregister here */
- kobject_unregister(&csrow->kobj);
+ kobject_put(&csrow->kobj);
goto err_out;
}
}
@@ -808,7 +808,7 @@ fail_out:
void edac_mc_unregister_sysfs_main_kobj(struct mem_ctl_info *mci)
{
/* delete the kobj from the mc_kset */
- kobject_unregister(&mci->edac_mci_kobj);
+ kobject_put(&mci->edac_mci_kobj);
}

#define EDAC_DEVICE_SYMLINK "device"
@@ -923,7 +923,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
fail1:
for (i--; i >= 0; i--) {
if (csrow->nr_pages > 0) {
- kobject_unregister(&mci->csrows[i].kobj);
+ kobject_put(&mci->csrows[i].kobj);
}
}

@@ -950,7 +950,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
for (i = 0; i < mci->nr_csrows; i++) {
if (mci->csrows[i].nr_pages > 0) {
debugf0("%s() unreg csrow-%d\n", __func__, i);
- kobject_unregister(&mci->csrows[i].kobj);
+ kobject_put(&mci->csrows[i].kobj);
}
}

@@ -967,7 +967,7 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci)
debugf0("%s() unregister this mci kobj\n", __func__);

/* unregister this instance's kobject */
- kobject_unregister(&mci->edac_mci_kobj);
+ kobject_put(&mci->edac_mci_kobj);
}


diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index 834eaa9..5b075da 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -205,7 +205,7 @@ void edac_pci_unregister_sysfs_instance_kobj(struct edac_pci_ctl_info *pci)
* function release the main reference count and then
* kfree the memory
*/
- kobject_unregister(&pci->kobj);
+ kobject_put(&pci->kobj);
}

/***************************** EDAC PCI sysfs root **********************/
@@ -411,9 +411,9 @@ static void edac_pci_main_kobj_teardown(void)
* main kobj
*/
if (atomic_dec_return(&edac_pci_sysfs_refcount) == 0) {
- debugf0("%s() called kobject_unregister on main kobj\n",
+ debugf0("%s() called kobject_put on main kobj\n",
__func__);
- kobject_unregister(&edac_pci_top_main_kobj);
+ kobject_put(&edac_pci_top_main_kobj);
}
}

diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index dc0b87b..d168223 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -693,7 +693,7 @@ edd_create_symlink_to_pcidev(struct edd_device *edev)
static inline void
edd_device_unregister(struct edd_device *edev)
{
- kobject_unregister(&edev->kobj);
+ kobject_put(&edev->kobj);
}

static void edd_populate_dir(struct edd_device * edev)
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index b61a72f..f4f709d 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -397,7 +397,7 @@ static struct kobj_type efivar_ktype = {
static inline void
efivar_unregister(struct efivar_entry *var)
{
- kobject_unregister(&var->kobj);
+ kobject_put(&var->kobj);
}


@@ -732,7 +732,7 @@ efivars_init(void)
kset_unregister(vars_kset);

out_firmware_unregister:
- kobject_unregister(efi_kobj);
+ kobject_put(efi_kobj);

out_free:
kfree(variable_name);
@@ -753,7 +753,7 @@ efivars_exit(void)
}

kset_unregister(vars_kset);
- kobject_unregister(efi_kobj);
+ kobject_put(efi_kobj);
}

module_init(efivars_init);
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index aa81129..c864ef7 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -714,7 +714,7 @@ err_put:
sysfs_remove_group(p, &pma_group);
sysfs_remove_group(p, &port->pkey_group);
sysfs_remove_group(p, &port->gid_group);
- kobject_unregister(p);
+ kobject_put(p);
}
}

@@ -738,10 +738,10 @@ void ib_device_unregister_sysfs(struct ib_device *device)
sysfs_remove_group(p, &pma_group);
sysfs_remove_group(p, &port->pkey_group);
sysfs_remove_group(p, &port->gid_group);
- kobject_unregister(p);
+ kobject_put(p);
}

- kobject_unregister(device->ports_parent);
+ kobject_put(device->ports_parent);
class_device_unregister(&device->class_dev);
}

diff --git a/drivers/md/md.c b/drivers/md/md.c
index ae800ba..c28a120 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -231,7 +231,7 @@ static void mddev_put(mddev_t *mddev)
list_del(&mddev->all_mddevs);
spin_unlock(&all_mddevs_lock);
blk_cleanup_queue(mddev->queue);
- kobject_unregister(&mddev->kobj);
+ kobject_put(&mddev->kobj);
} else
spin_unlock(&all_mddevs_lock);
}
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index bee3037..57772be 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1236,7 +1236,7 @@ static int __devexit ibmveth_remove(struct vio_dev *dev)
int i;

for(i = 0; i<IbmVethNumBufferPools; i++)
- kobject_unregister(&adapter->rx_buff_pool[i].kobj);
+ kobject_put(&adapter->rx_buff_pool[i].kobj);

unregister_netdev(netdev);

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 87bc6b7..de34aa9 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -1026,7 +1026,7 @@ pdcs_unregister_pathentries(void)
for (i = 0; (entry = pdcspath_entries[i]); i++) {
read_lock(&entry->rw_lock);
if (entry->ready >= 2)
- kobject_unregister(&entry->kobj);
+ kobject_put(&entry->kobj);
read_unlock(&entry->rw_lock);
}
}
@@ -1086,7 +1086,7 @@ fail_pdcsreg:
kset_unregister(paths_kset);

fail_ksetreg:
- kobject_unregister(stable_kobj);
+ kobject_put(stable_kobj);

fail_firmreg:
printk(KERN_INFO PDCS_PREFIX " bailing out\n");
@@ -1098,7 +1098,7 @@ pdc_stable_exit(void)
{
pdcs_unregister_pathentries();
kset_unregister(paths_kset);
- kobject_unregister(stable_kobj);
+ kobject_put(stable_kobj);
}


diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 3606d5b..47bb0e1 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -671,7 +671,7 @@ int pci_hp_deregister (struct hotplug_slot *slot)

fs_remove_slot (slot);
dbg ("Removed slot %s from the list\n", slot->name);
- kobject_unregister(&slot->kobj);
+ kobject_put(&slot->kobj);
return 0;
}

diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index 9cde367..e32148a 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -114,12 +114,12 @@ int dlpar_sysfs_init(void)

error = sysfs_create_group(dlpar_kobj, &dlpar_attr_group);
if (error)
- kobject_unregister(dlpar_kobj);
+ kobject_put(dlpar_kobj);
return error;
}

void dlpar_sysfs_exit(void)
{
sysfs_remove_group(dlpar_kobj, &dlpar_attr_group);
- kobject_unregister(dlpar_kobj);
+ kobject_put(dlpar_kobj);
}
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index f352731..03b66fb 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -186,9 +186,9 @@ err:
for (mi--; mi>=0; mi--) {
mem = &idev->info->mem[mi];
map = mem->map;
- kobject_unregister(&map->kobj);
+ kobject_put(&map->kobj);
}
- kobject_unregister(idev->map_dir);
+ kobject_put(idev->map_dir);
sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
err_group:
dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
@@ -203,9 +203,9 @@ static void uio_dev_del_attributes(struct uio_device *idev)
mem = &idev->info->mem[mi];
if (mem->size == 0)
break;
- kobject_unregister(&mem->map->kobj);
+ kobject_put(&mem->map->kobj);
}
- kobject_unregister(idev->map_dir);
+ kobject_put(idev->map_dir);
sysfs_remove_group(&idev->dev->kobj, &uio_attr_grp);
}

--
1.5.3.8

2008-01-25 08:09:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 122/196] Kobject: change drivers/net/ibmveth.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Dave Larson <[email protected]>
Cc: Santiago Leon <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/net/ibmveth.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 7d7758f..bee3037 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1179,13 +1179,15 @@ static int __devinit ibmveth_probe(struct vio_dev *dev, const struct vio_device_

for(i = 0; i<IbmVethNumBufferPools; i++) {
struct kobject *kobj = &adapter->rx_buff_pool[i].kobj;
+ int error;
+
ibmveth_init_buffer_pool(&adapter->rx_buff_pool[i], i,
pool_count[i], pool_size[i],
pool_active[i]);
- kobj->parent = &dev->dev.kobj;
- kobject_set_name(kobj, "pool%d", i);
- kobj->ktype = &ktype_veth_pool;
- kobject_register(kobj);
+ error = kobject_init_and_add(kobj, &ktype_veth_pool,
+ &dev->dev.kobj, "pool%d", i);
+ if (!error)
+ kobject_uevent(kobj, KOBJ_ADD);
}

ibmveth_debug_printk("adapter @ 0x%p\n", adapter);
--
1.5.3.8

2008-01-25 08:10:04

by Greg KH

[permalink] [raw]
Subject: [PATCH 149/196] Driver: add driver_add_kobj for looney iseries_veth driver

The iseries driver wants to hang kobjects off of its driver, so, to
preserve backwards compatibility, we need to add a call to the driver
core to allow future changes to work properly.

Hopefully no one uses this function in the future and the iseries_veth
driver authors come to their senses so I can remove this hack...

Cc: Dave Larson <[email protected]>
Cc: Santiago Leon <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/driver.c | 24 ++++++++++++++++++++++++
drivers/net/iseries_veth.c | 2 +-
include/linux/device.h | 4 ++++
3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index e3b5840..633ae1d 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -124,6 +124,30 @@ void driver_remove_file(struct device_driver * drv, struct driver_attribute * at


/**
+ * driver_add_kobj - add a kobject below the specified driver
+ *
+ * You really don't want to do this, this is only here due to one looney
+ * iseries driver, go poke those developers if you are annoyed about
+ * this...
+ */
+int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
+ const char *fmt, ...)
+{
+ va_list args;
+ char *name;
+
+ va_start(args, fmt);
+ name = kvasprintf(GFP_KERNEL, fmt, args);
+ va_end(args);
+
+ if (!name)
+ return -ENOMEM;
+
+ return kobject_add_ng(kobj, &drv->kobj, "%s", name);
+}
+EXPORT_SYMBOL_GPL(driver_add_kobj);
+
+/**
* get_driver - increment driver reference count.
* @drv: driver.
*/
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 90ff4ec..1a8299a 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -1705,7 +1705,7 @@ static int __init veth_module_init(void)

kobj = &veth_cnx[i]->kobject;
/* If the add failes, complain but otherwise continue */
- if (0 != kobject_add_ng(kobj, &veth_driver.driver.kobj,
+ if (0 != driver_add_kobj(&veth_driver.driver, kobj,
"cnx%.2d", veth_cnx[i]->remote_lp))
veth_error("cnx %d: Failed adding to sysfs.\n", i);
}
diff --git a/include/linux/device.h b/include/linux/device.h
index d974dda..721ee31 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -156,6 +156,10 @@ extern int __must_check driver_create_file(struct device_driver *,
struct driver_attribute *);
extern void driver_remove_file(struct device_driver *, struct driver_attribute *);

+extern int __must_check driver_add_kobj(struct device_driver *drv,
+ struct kobject *kobj,
+ const char *fmt, ...);
+
extern int __must_check driver_for_each_device(struct device_driver * drv,
struct device *start, void *data,
int (*fn)(struct device *, void *));
--
1.5.3.8

2008-01-25 08:10:34

by Greg KH

[permalink] [raw]
Subject: [PATCH 191/196] scsi: use class iteration api

From: Dave Young <[email protected]>

Convert to use the class iteration api.

Signed-off-by: Dave Young <[email protected]>
Cc: James Bottomley <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/scsi/hosts.c | 24 +++++++++++++-----------
1 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 24271a8..6325115 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -429,6 +429,15 @@ void scsi_unregister(struct Scsi_Host *shost)
}
EXPORT_SYMBOL(scsi_unregister);

+static int __scsi_host_match(struct class_device *cdev, void *data)
+{
+ struct Scsi_Host *p;
+ unsigned short *hostnum = (unsigned short *)data;
+
+ p = class_to_shost(cdev);
+ return p->host_no == *hostnum;
+}
+
/**
* scsi_host_lookup - get a reference to a Scsi_Host by host no
*
@@ -439,19 +448,12 @@ EXPORT_SYMBOL(scsi_unregister);
**/
struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
{
- struct class *class = &shost_class;
struct class_device *cdev;
- struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p;
+ struct Scsi_Host *shost = ERR_PTR(-ENXIO);

- down(&class->sem);
- list_for_each_entry(cdev, &class->children, node) {
- p = class_to_shost(cdev);
- if (p->host_no == hostnum) {
- shost = scsi_host_get(p);
- break;
- }
- }
- up(&class->sem);
+ cdev = class_find_child(&shost_class, &hostnum, __scsi_host_match);
+ if (cdev)
+ shost = scsi_host_get(class_to_shost(cdev));

return shost;
}
--
1.5.3.8

2008-01-25 08:10:55

by Greg KH

[permalink] [raw]
Subject: [PATCH 119/196] Kobject: change drivers/acpi/system.c to use kobject_create_and_add

Stop using kobject_register for this static kobject, as it's overkill.
This way is much simpler.

Cc: Len Brown <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/acpi/system.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/acpi/system.c b/drivers/acpi/system.c
index c22b93a..5ffe0ea 100644
--- a/drivers/acpi/system.c
+++ b/drivers/acpi/system.c
@@ -58,7 +58,7 @@ module_param_call(acpica_version, NULL, param_get_acpica_version, NULL, 0444);
FS Interface (/sys)
-------------------------------------------------------------------------- */
static LIST_HEAD(acpi_table_attr_list);
-static struct kobject tables_kobj;
+static struct kobject *tables_kobj;

struct acpi_table_attr {
struct bin_attribute attr;
@@ -135,11 +135,9 @@ static int acpi_system_sysfs_init(void)
int table_index = 0;
int result;

- tables_kobj.parent = acpi_kobj;
- kobject_set_name(&tables_kobj, "tables");
- result = kobject_register(&tables_kobj);
- if (result)
- return result;
+ tables_kobj = kobject_create_and_add("tables", acpi_kobj);
+ if (!tables_kobj)
+ return -ENOMEM;

do {
result = acpi_get_table_by_index(table_index, &table_header);
@@ -153,7 +151,7 @@ static int acpi_system_sysfs_init(void)

acpi_table_attr_init(table_attr, table_header);
result =
- sysfs_create_bin_file(&tables_kobj,
+ sysfs_create_bin_file(tables_kobj,
&table_attr->attr);
if (result) {
kfree(table_attr);
@@ -163,6 +161,7 @@ static int acpi_system_sysfs_init(void)
&acpi_table_attr_list);
}
} while (!result);
+ kobject_uevent(tables_kobj, KOBJ_ADD);

return 0;
}
--
1.5.3.8

2008-01-25 08:11:25

by Greg KH

[permalink] [raw]
Subject: [PATCH 179/196] kobject: add sample code for how to use kobjects in a simple manner.

This is a simple kobject module, showing how to use kobj_attributes in
basic and more complex ways.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
samples/Kconfig | 10 +++
samples/Makefile | 2 +-
samples/kobject/Makefile | 1 +
samples/kobject/kobject-example.c | 137 +++++++++++++++++++++++++++++++++++++
4 files changed, 149 insertions(+), 1 deletions(-)
create mode 100644 samples/kobject/Makefile
create mode 100644 samples/kobject/kobject-example.c

diff --git a/samples/Kconfig b/samples/Kconfig
index 57bb223..74d97cc 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -13,4 +13,14 @@ config SAMPLE_MARKERS
help
This build markers example modules.

+config SAMPLE_KOBJECT
+ tristate "Build kobject examples"
+ help
+ This config option will allow you to build a number of
+ different kobject sample modules showing how to use kobjects,
+ ksets, and ktypes properly.
+
+ If in doubt, say "N" here.
+
endif # SAMPLES
+
diff --git a/samples/Makefile b/samples/Makefile
index 5a4f0b6..8652d0f 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,3 +1,3 @@
# Makefile for Linux samples code

-obj-$(CONFIG_SAMPLES) += markers/
+obj-$(CONFIG_SAMPLES) += markers/ kobject/
diff --git a/samples/kobject/Makefile b/samples/kobject/Makefile
new file mode 100644
index 0000000..cce16e9
--- /dev/null
+++ b/samples/kobject/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o
diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c
new file mode 100644
index 0000000..08d0d3f
--- /dev/null
+++ b/samples/kobject/kobject-example.c
@@ -0,0 +1,137 @@
+/*
+ * Sample kobject implementation
+ *
+ * Copyright (C) 2004-2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (C) 2007 Novell Inc.
+ *
+ * Released under the GPL version 2 only.
+ *
+ */
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/init.h>
+
+/*
+ * This module shows how to create a simple subdirectory in sysfs called
+ * /sys/kernel/kobject-example In that directory, 3 files are created:
+ * "foo", "baz", and "bar". If an integer is written to these files, it can be
+ * later read out of it.
+ */
+
+static int foo;
+static int baz;
+static int bar;
+
+/*
+ * The "foo" file where a static variable is read from and written to.
+ */
+static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%d\n", foo);
+}
+
+static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ sscanf(buf, "%du", &foo);
+ return count;
+}
+
+static struct kobj_attribute foo_attribute =
+ __ATTR(foo, 0666, foo_show, foo_store);
+
+/*
+ * More complex function where we determine which varible is being accessed by
+ * looking at the attribute for the "baz" and "bar" files.
+ */
+static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr,
+ char *buf)
+{
+ int var;
+
+ if (strcmp(attr->attr.name, "baz") == 0)
+ var = baz;
+ else
+ var = bar;
+ return sprintf(buf, "%d\n", var);
+}
+
+static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ int var;
+
+ sscanf(buf, "%du", &var);
+ if (strcmp(attr->attr.name, "baz") == 0)
+ baz = var;
+ else
+ bar = var;
+ return count;
+}
+
+static struct kobj_attribute baz_attribute =
+ __ATTR(baz, 0666, b_show, b_store);
+static struct kobj_attribute bar_attribute =
+ __ATTR(bar, 0666, b_show, b_store);
+
+
+/*
+ * Create a group of attributes so that we can create and destory them all
+ * at once.
+ */
+static struct attribute *attrs[] = {
+ &foo_attribute.attr,
+ &baz_attribute.attr,
+ &bar_attribute.attr,
+ NULL, /* need to NULL terminate the list of attributes */
+};
+
+/*
+ * An unnamed attribute group will put all of the attributes directly in
+ * the kobject directory. If we specify a name, a subdirectory will be
+ * created for the attributes with the directory being the name of the
+ * attribute group.
+ */
+static struct attribute_group attr_group = {
+ .attrs = attrs,
+};
+
+static struct kobject *example_kobj;
+
+static int example_init(void)
+{
+ int retval;
+
+ /*
+ * Create a simple kobject with the name of "kobject_example",
+ * located under /sys/kernel/
+ *
+ * As this is a simple directory, no uevent will be sent to
+ * userspace. That is why this function should not be used for
+ * any type of dynamic kobjects, where the name and number are
+ * not known ahead of time.
+ */
+ example_kobj = kobject_create_and_add("kobject_example", kernel_kobj);
+ if (!example_kobj)
+ return -ENOMEM;
+
+ /* Create the files associated with this kobject */
+ retval = sysfs_create_group(example_kobj, &attr_group);
+ if (retval)
+ kobject_put(example_kobj);
+
+ return retval;
+}
+
+static void example_exit(void)
+{
+ kobject_put(example_kobj);
+}
+
+module_init(example_init);
+module_exit(example_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Greg Kroah-Hartman <[email protected]>");
--
1.5.3.8

2008-01-25 08:11:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 169/196] Kobject: auto-cleanup on final unref

From: Kay Sievers <[email protected]>

We save the current state in the object itself, so we can do proper
cleanup when the last reference is dropped.

If the initial reference is dropped, the object will be removed from
sysfs if needed, if an "add" event was sent, "remove" will be send, and
the allocated resources are released.

This allows us to clean up some driver core usage as well as allowing us
to do other such changes to the rest of the kernel.

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 32 ++-------
include/linux/kobject.h | 5 ++
lib/kobject.c | 170 ++++++++++++++++++++++++++--------------------
lib/kobject_uevent.c | 11 +++
4 files changed, 119 insertions(+), 99 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 675a719..d5d542d 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -576,8 +576,8 @@ static struct kobject *get_device_parent(struct device *dev,

/*
* If we have no parent, we live in "virtual".
- * Class-devices with a bus-device as parent, live
- * in a class-directory to prevent namespace collisions.
+ * Class-devices with a non class-device as parent, live
+ * in a "glue" directory to prevent namespace collisions.
*/
if (parent == NULL)
parent_kobj = virtual_device_parent(dev);
@@ -607,8 +607,7 @@ static struct kobject *get_device_parent(struct device *dev,
kobject_put(k);
return NULL;
}
- /* Do not emit a uevent, as it's not needed for this
- * "class glue" directory. */
+ /* do not emit an uevent for this simple "glue" directory */
return k;
}

@@ -619,30 +618,13 @@ static struct kobject *get_device_parent(struct device *dev,

static void cleanup_device_parent(struct device *dev)
{
- struct device *d;
- int other = 0;
+ struct kobject *glue_dir = dev->kobj.parent;

- if (!dev->class)
- return;
-
- /* see if we live in a parent class directory */
- if (dev->kobj.parent->kset != &dev->class->class_dirs)
+ /* see if we live in a "glue" directory */
+ if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
return;

- /* if we are the last child of our class, delete the directory */
- down(&dev->class->sem);
- list_for_each_entry(d, &dev->class->devices, node) {
- if (d == dev)
- continue;
- if (d->kobj.parent == dev->kobj.parent) {
- other = 1;
- break;
- }
- }
- if (!other)
- kobject_del(dev->kobj.parent);
- kobject_put(dev->kobj.parent);
- up(&dev->class->sem);
+ kobject_put(glue_dir);
}
#endif

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 63967da..be03ce8 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -68,6 +68,11 @@ struct kobject {
struct kset * kset;
struct kobj_type * ktype;
struct sysfs_dirent * sd;
+ unsigned int state_initialized:1;
+ unsigned int state_name_set:1;
+ unsigned int state_in_sysfs:1;
+ unsigned int state_add_uevent_sent:1;
+ unsigned int state_remove_uevent_sent:1;
};

extern int kobject_set_name(struct kobject *, const char *, ...)
diff --git a/lib/kobject.c b/lib/kobject.c
index c321f19..4fce5ca 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -124,85 +124,74 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
}
EXPORT_SYMBOL_GPL(kobject_get_path);

-static void kobject_init_internal(struct kobject * kobj)
+/* add the kobject to its kset's list */
+static void kobj_kset_join(struct kobject *kobj)
{
- if (!kobj)
+ if (!kobj->kset)
return;
- kref_init(&kobj->kref);
- INIT_LIST_HEAD(&kobj->entry);
+
+ kset_get(kobj->kset);
+ spin_lock(&kobj->kset->list_lock);
+ list_add_tail(&kobj->entry, &kobj->kset->list);
+ spin_unlock(&kobj->kset->list_lock);
}

+/* remove the kobject from its kset's list */
+static void kobj_kset_leave(struct kobject *kobj)
+{
+ if (!kobj->kset)
+ return;

-/**
- * unlink - remove kobject from kset list.
- * @kobj: kobject.
- *
- * Remove the kobject from the kset list and decrement
- * its parent's refcount.
- * This is separated out, so we can use it in both
- * kobject_del() and kobject_add_internal() on error.
- */
+ spin_lock(&kobj->kset->list_lock);
+ list_del_init(&kobj->entry);
+ spin_unlock(&kobj->kset->list_lock);
+ kset_put(kobj->kset);
+}

-static void unlink(struct kobject * kobj)
+static void kobject_init_internal(struct kobject * kobj)
{
- struct kobject *parent = kobj->parent;
-
- if (kobj->kset) {
- spin_lock(&kobj->kset->list_lock);
- list_del_init(&kobj->entry);
- spin_unlock(&kobj->kset->list_lock);
- }
- kobj->parent = NULL;
- kobject_put(kobj);
- kobject_put(parent);
+ if (!kobj)
+ return;
+ kref_init(&kobj->kref);
+ INIT_LIST_HEAD(&kobj->entry);
}

+
static int kobject_add_internal(struct kobject *kobj)
{
int error = 0;
struct kobject * parent;

- if (!(kobj = kobject_get(kobj)))
+ if (!kobj)
return -ENOENT;
- if (!kobj->k_name)
- kobject_set_name(kobj, "NO_NAME");
- if (!*kobj->k_name) {
- pr_debug("kobject (%p) attempted to be registered with no "
+
+ if (!kobj->k_name || !kobj->k_name[0]) {
+ pr_debug("kobject: (%p): attempted to be registered with empty "
"name!\n", kobj);
WARN_ON(1);
- kobject_put(kobj);
return -EINVAL;
}
- parent = kobject_get(kobj->parent);

- pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
- kobject_name(kobj), kobj, __FUNCTION__,
- parent ? kobject_name(parent) : "<NULL>",
- kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
+ parent = kobject_get(kobj->parent);

+ /* join kset if set, use it as parent if we do not already have one */
if (kobj->kset) {
- kobj->kset = kset_get(kobj->kset);
-
- if (!parent) {
+ if (!parent)
parent = kobject_get(&kobj->kset->kobj);
- /*
- * If the kset is our parent, get a second
- * reference, we drop both the kset and the
- * parent ref on cleanup
- */
- kobject_get(parent);
- }
-
- spin_lock(&kobj->kset->list_lock);
- list_add_tail(&kobj->entry, &kobj->kset->list);
- spin_unlock(&kobj->kset->list_lock);
+ kobj_kset_join(kobj);
kobj->parent = parent;
}

+ pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
+ kobject_name(kobj), kobj, __FUNCTION__,
+ parent ? kobject_name(parent) : "<NULL>",
+ kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
+
error = create_dir(kobj);
if (error) {
- /* unlink does the kobject_put() for us */
- unlink(kobj);
+ kobj_kset_leave(kobj);
+ kobject_put(parent);
+ kobj->parent = NULL;

/* be noisy on error issues */
if (error == -EEXIST)
@@ -214,7 +203,8 @@ static int kobject_add_internal(struct kobject *kobj)
printk(KERN_ERR "%s failed for %s (%d)\n",
__FUNCTION__, kobject_name(kobj), error);
dump_stack();
- }
+ } else
+ kobj->state_in_sysfs = 1;

return error;
}
@@ -238,11 +228,13 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
if (!name)
return -ENOMEM;

+
/* Free the old name, if necessary. */
kfree(kobj->k_name);

/* Now, set the new name */
kobj->k_name = name;
+ kobj->state_name_set = 1;

return 0;
}
@@ -293,20 +285,25 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
err_str = "must have a ktype to be initialized properly!\n";
goto error;
}
- if (atomic_read(&kobj->kref.refcount)) {
+ if (kobj->state_initialized) {
/* do not error out as sometimes we can recover */
- printk(KERN_ERR "kobject: reference count is already set, "
- "something is seriously wrong.\n");
+ printk(KERN_ERR "kobject (%p): tried to init an initialized "
+ "object, something is seriously wrong.\n", kobj);
dump_stack();
}

kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry);
kobj->ktype = ktype;
+ kobj->state_name_set = 0;
+ kobj->state_in_sysfs = 0;
+ kobj->state_add_uevent_sent = 0;
+ kobj->state_remove_uevent_sent = 0;
+ kobj->state_initialized = 1;
return;

error:
- printk(KERN_ERR "kobject: %s\n", err_str);
+ printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
dump_stack();
}
EXPORT_SYMBOL(kobject_init);
@@ -345,17 +342,10 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
*
* If this function returns an error, kobject_put() must be called to
* properly clean up the memory associated with the object.
- *
- * If the function is successful, the only way to properly clean up the
- * memory is with a call to kobject_del(), in which case, a call to
- * kobject_put() is not necessary (kobject_del() does the final
- * kobject_put() to call the release function in the ktype's release
- * pointer.)
- *
* Under no instance should the kobject that is passed to this function
* be directly freed with a call to kfree(), that can leak memory.
*
- * Note, no uevent will be created with this call, the caller should set
+ * Note, no "add" uevent will be created with this call, the caller should set
* up all of the necessary sysfs files for the object and then call
* kobject_uevent() with the UEVENT_ADD parameter to ensure that
* userspace is properly notified of this kobject's creation.
@@ -369,6 +359,13 @@ int kobject_add(struct kobject *kobj, struct kobject *parent,
if (!kobj)
return -EINVAL;

+ if (!kobj->state_initialized) {
+ printk(KERN_ERR "kobject '%s' (%p): tried to add an "
+ "uninitialized object, something is seriously wrong.\n",
+ kobject_name(kobj), kobj);
+ dump_stack();
+ return -EINVAL;
+ }
va_start(args, fmt);
retval = kobject_add_varg(kobj, parent, fmt, args);
va_end(args);
@@ -527,8 +524,12 @@ void kobject_del(struct kobject * kobj)
{
if (!kobj)
return;
+
sysfs_remove_dir(kobj);
- unlink(kobj);
+ kobj->state_in_sysfs = 0;
+ kobj_kset_leave(kobj);
+ kobject_put(kobj->parent);
+ kobj->parent = NULL;
}

/**
@@ -565,21 +566,43 @@ struct kobject * kobject_get(struct kobject * kobj)
*/
static void kobject_cleanup(struct kobject *kobj)
{
- struct kobj_type * t = get_ktype(kobj);
- struct kset * s = kobj->kset;
+ struct kobj_type *t = get_ktype(kobj);
const char *name = kobj->k_name;
+ int name_set = kobj->state_name_set;

pr_debug("kobject: '%s' (%p): %s\n",
kobject_name(kobj), kobj, __FUNCTION__);
+
+ if (t && !t->release)
+ pr_debug("kobject: '%s' (%p): does not have a release() "
+ "function, it is broken and must be fixed.\n",
+ kobject_name(kobj), kobj);
+
+ /* send "remove" if the caller did not do it but sent "add" */
+ if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) {
+ pr_debug("kobject: '%s' (%p): auto cleanup 'remove' event\n",
+ kobject_name(kobj), kobj);
+ kobject_uevent(kobj, KOBJ_REMOVE);
+ }
+
+ /* remove from sysfs if the caller did not do it */
+ if (kobj->state_in_sysfs) {
+ pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
+ kobject_name(kobj), kobj);
+ kobject_del(kobj);
+ }
+
if (t && t->release) {
+ pr_debug("kobject: '%s' (%p): calling ktype release\n",
+ kobject_name(kobj), kobj);
t->release(kobj);
- /* If we have a release function, we can guess that this was
- * not a statically allocated kobject, so we should be safe to
- * free the name */
+ }
+
+ /* free name if we allocated it */
+ if (name_set && name) {
+ pr_debug("kobject: '%s': free name\n", name);
kfree(name);
}
- if (s)
- kset_put(s);
}

static void kobject_release(struct kref *kref)
@@ -601,8 +624,7 @@ void kobject_put(struct kobject * kobj)

static void dynamic_kobj_release(struct kobject *kobj)
{
- pr_debug("kobject: '%s' (%p): %s\n",
- kobject_name(kobj), kobj, __FUNCTION__);
+ pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
kfree(kobj);
}

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 51dc4d2..b021e67 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -180,6 +180,17 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
}
}

+ /*
+ * Mark "add" and "remove" events in the object to ensure proper
+ * events to userspace during automatic cleanup. If the object did
+ * send an "add" event, "remove" will automatically generated by
+ * the core, if not already done by the caller.
+ */
+ if (action == KOBJ_ADD)
+ kobj->state_add_uevent_sent = 1;
+ else if (action == KOBJ_REMOVE)
+ kobj->state_remove_uevent_sent = 1;
+
/* we will send an event, so request a new sequence number */
spin_lock(&sequence_lock);
seq = ++uevent_seqnum;
--
1.5.3.8

2008-01-25 08:12:14

by Greg KH

[permalink] [raw]
Subject: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.

Make the ipath driver use the new driver functions so that it does not
touch the sysfs portion of the driver structure.

We also remove the redundant symlink from the device back to the driver,
as it is already in the sysfs tree. Any userspace tools should be using
the standard symlink, not some driver specific one.

Cc: Roland Dreier <[email protected]>
Cc: Bryan O'Sullivan <[email protected]>
Cc: Arthur Jones <[email protected]>
Cc: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/infiniband/hw/ehca/ehca_main.c | 13 +++++++----
drivers/infiniband/hw/ipath/ipath_driver.c | 17 +++------------
drivers/infiniband/hw/ipath/ipath_kernel.h | 3 +-
drivers/infiniband/hw/ipath/ipath_sysfs.c | 30 ++++-----------------------
4 files changed, 18 insertions(+), 45 deletions(-)

diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 6a56d86..c9e32b4 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -590,6 +590,11 @@ static struct attribute_group ehca_drv_attr_grp = {
.attrs = ehca_drv_attrs
};

+static struct attribute_group *ehca_drv_attr_groups[] = {
+ &ehca_drv_attr_grp,
+ NULL,
+};
+
#define EHCA_RESOURCE_ATTR(name) \
static ssize_t ehca_show_##name(struct device *dev, \
struct device_attribute *attr, \
@@ -899,6 +904,9 @@ static struct of_platform_driver ehca_driver = {
.match_table = ehca_device_table,
.probe = ehca_probe,
.remove = ehca_remove,
+ .driver = {
+ .groups = ehca_drv_attr_groups,
+ },
};

void ehca_poll_eqs(unsigned long data)
@@ -957,10 +965,6 @@ int __init ehca_module_init(void)
goto module_init2;
}

- ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
- if (ret) /* only complain; we can live without attributes */
- ehca_gen_err("Cannot create driver attributes ret=%d", ret);
-
if (ehca_poll_all_eqs != 1) {
ehca_gen_err("WARNING!!!");
ehca_gen_err("It is possible to lose interrupts.");
@@ -986,7 +990,6 @@ void __exit ehca_module_exit(void)
if (ehca_poll_all_eqs == 1)
del_timer_sync(&poll_eqs_timer);

- sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
ibmebus_unregister_driver(&ehca_driver);

ehca_destroy_slab_caches();
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
index 1f152de..fc35598 100644
--- a/drivers/infiniband/hw/ipath/ipath_driver.c
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -121,6 +121,9 @@ static struct pci_driver ipath_driver = {
.probe = ipath_init_one,
.remove = __devexit_p(ipath_remove_one),
.id_table = ipath_pci_tbl,
+ .driver = {
+ .groups = ipath_driver_attr_groups,
+ },
};

static void ipath_check_status(struct work_struct *work)
@@ -2217,25 +2220,15 @@ static int __init infinipath_init(void)
goto bail_unit;
}

- ret = ipath_driver_create_group(&ipath_driver.driver);
- if (ret < 0) {
- printk(KERN_ERR IPATH_DRV_NAME ": Unable to create driver "
- "sysfs entries: error %d\n", -ret);
- goto bail_pci;
- }
-
ret = ipath_init_ipathfs();
if (ret < 0) {
printk(KERN_ERR IPATH_DRV_NAME ": Unable to create "
"ipathfs: error %d\n", -ret);
- goto bail_group;
+ goto bail_pci;
}

goto bail;

-bail_group:
- ipath_driver_remove_group(&ipath_driver.driver);
-
bail_pci:
pci_unregister_driver(&ipath_driver);

@@ -2250,8 +2243,6 @@ static void __exit infinipath_cleanup(void)
{
ipath_exit_ipathfs();

- ipath_driver_remove_group(&ipath_driver.driver);
-
ipath_cdbg(VERBOSE, "Unregistering pci driver\n");
pci_unregister_driver(&ipath_driver);

diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
index 8786dd7..bb1dc07 100644
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -938,8 +938,7 @@ struct device_driver;

extern const char ib_ipath_version[];

-int ipath_driver_create_group(struct device_driver *);
-void ipath_driver_remove_group(struct device_driver *);
+extern struct attribute_group *ipath_driver_attr_groups[];

int ipath_device_create_group(struct device *, struct ipath_devdata *);
void ipath_device_remove_group(struct device *, struct ipath_devdata *);
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
index e1ad7cf..aa27ca9 100644
--- a/drivers/infiniband/hw/ipath/ipath_sysfs.c
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -683,6 +683,11 @@ static struct attribute_group driver_attr_group = {
.attrs = driver_attributes
};

+struct attribute_group *ipath_driver_attr_groups[] = {
+ &driver_attr_group,
+ NULL,
+};
+
static DEVICE_ATTR(guid, S_IWUSR | S_IRUGO, show_guid, store_guid);
static DEVICE_ATTR(lmc, S_IWUSR | S_IRUGO, show_lmc, store_lmc);
static DEVICE_ATTR(lid, S_IWUSR | S_IRUGO, show_lid, store_lid);
@@ -753,24 +758,9 @@ int ipath_expose_reset(struct device *dev)
return ret;
}

-int ipath_driver_create_group(struct device_driver *drv)
-{
- int ret;
-
- ret = sysfs_create_group(&drv->kobj, &driver_attr_group);
-
- return ret;
-}
-
-void ipath_driver_remove_group(struct device_driver *drv)
-{
- sysfs_remove_group(&drv->kobj, &driver_attr_group);
-}
-
int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
{
int ret;
- char unit[5];

ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
if (ret)
@@ -780,11 +770,6 @@ int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
if (ret)
goto bail_attrs;

- snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
- ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
- if (ret == 0)
- goto bail;
-
sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
bail_attrs:
sysfs_remove_group(&dev->kobj, &dev_attr_group);
@@ -794,11 +779,6 @@ bail:

void ipath_device_remove_group(struct device *dev, struct ipath_devdata *dd)
{
- char unit[5];
-
- snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
- sysfs_remove_link(&dev->driver->kobj, unit);
-
sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
sysfs_remove_group(&dev->kobj, &dev_attr_group);

--
1.5.3.8

2008-01-25 08:12:34

by Greg KH

[permalink] [raw]
Subject: [PATCH 140/196] driver core: remove fields from struct bus_type

struct bus_type is static everywhere in the kernel. This moves the
kobject in the structure out of it, and a bunch of other private only to
the driver core fields are now moved to a private structure. This lets
us dynamically create the backing kobject properly and gives us the
chance to be able to document to users exactly how to use the struct
bus_type as there are no fields they can improperly access.

Thanks to Kay for the build fixes on this patch.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 30 ++++++++++++-
drivers/base/bus.c | 116 ++++++++++++++++++++++++++---------------------
drivers/base/core.c | 6 +-
drivers/base/dd.c | 4 +-
drivers/base/driver.c | 2 +-
drivers/base/platform.c | 4 +-
include/linux/device.h | 12 +----
7 files changed, 104 insertions(+), 70 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 7e309a4..ca6d273 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -1,6 +1,34 @@

-/* initialisation functions */
+/**
+ * struct bus_type_private - structure to hold the private to the driver core portions of the bus_type structure.
+ *
+ * @subsys - the struct kset that defines this bus. This is the main kobject
+ * @drivers_kset - the list of drivers associated with this bus
+ * @devices_kset - the list of devices associated with this bus
+ * @klist_devices - the klist to iterate over the @devices_kset
+ * @klist_drivers - the klist to iterate over the @drivers_kset
+ * @bus_notifier - the bus notifier list for anything that cares about things
+ * on this bus.
+ * @bus - pointer back to the struct bus_type that this structure is associated
+ * with.
+ *
+ * This structure is the one that is the actual kobject allowing struct
+ * bus_type to be statically allocated safely. Nothing outside of the driver
+ * core should ever touch these fields.
+ */
+struct bus_type_private {
+ struct kset subsys;
+ struct kset *drivers_kset;
+ struct kset *devices_kset;
+ struct klist klist_devices;
+ struct klist klist_drivers;
+ struct blocking_notifier_head bus_notifier;
+ unsigned int drivers_autoprobe:1;
+ struct bus_type *bus;
+};
+

+/* initialisation functions */
extern int devices_init(void);
extern int buses_init(void);
extern int classes_init(void);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 9c9027b..04d3850 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -17,7 +17,7 @@
#include "power/power.h"

#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
-#define to_bus(obj) container_of(obj, struct bus_type, subsys.kobj)
+#define to_bus(obj) container_of(obj, struct bus_type_private, subsys.kobj)

/*
* sysfs bindings for drivers
@@ -32,13 +32,17 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,

static struct bus_type *bus_get(struct bus_type *bus)
{
- return bus ? container_of(kset_get(&bus->subsys),
- struct bus_type, subsys) : NULL;
+ if (bus) {
+ kset_get(&bus->p->subsys);
+ return bus;
+ }
+ return NULL;
}

static void bus_put(struct bus_type *bus)
{
- kset_put(&bus->subsys);
+ if (bus)
+ kset_put(&bus->p->subsys);
}

static ssize_t
@@ -104,11 +108,11 @@ static ssize_t
bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
{
struct bus_attribute * bus_attr = to_bus_attr(attr);
- struct bus_type * bus = to_bus(kobj);
+ struct bus_type_private *bus_priv = to_bus(kobj);
ssize_t ret = 0;

if (bus_attr->show)
- ret = bus_attr->show(bus, buf);
+ ret = bus_attr->show(bus_priv->bus, buf);
return ret;
}

@@ -117,11 +121,11 @@ bus_attr_store(struct kobject * kobj, struct attribute * attr,
const char * buf, size_t count)
{
struct bus_attribute * bus_attr = to_bus_attr(attr);
- struct bus_type * bus = to_bus(kobj);
+ struct bus_type_private *bus_priv = to_bus(kobj);
ssize_t ret = 0;

if (bus_attr->store)
- ret = bus_attr->store(bus, buf, count);
+ ret = bus_attr->store(bus_priv->bus, buf, count);
return ret;
}

@@ -134,7 +138,7 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
{
int error;
if (bus_get(bus)) {
- error = sysfs_create_file(&bus->subsys.kobj, &attr->attr);
+ error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr);
bus_put(bus);
} else
error = -EINVAL;
@@ -144,7 +148,7 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
{
if (bus_get(bus)) {
- sysfs_remove_file(&bus->subsys.kobj, &attr->attr);
+ sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr);
bus_put(bus);
}
}
@@ -237,16 +241,16 @@ static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);

static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
{
- return sprintf(buf, "%d\n", bus->drivers_autoprobe);
+ return sprintf(buf, "%d\n", bus->p->drivers_autoprobe);
}

static ssize_t store_drivers_autoprobe(struct bus_type *bus,
const char *buf, size_t count)
{
if (buf[0] == '0')
- bus->drivers_autoprobe = 0;
+ bus->p->drivers_autoprobe = 0;
else
- bus->drivers_autoprobe = 1;
+ bus->p->drivers_autoprobe = 1;
return count;
}

@@ -300,7 +304,7 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
if (!bus)
return -EINVAL;

- klist_iter_init_node(&bus->klist_devices, &i,
+ klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->knode_bus : NULL));
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
@@ -333,7 +337,7 @@ struct device * bus_find_device(struct bus_type *bus,
if (!bus)
return NULL;

- klist_iter_init_node(&bus->klist_devices, &i,
+ klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->knode_bus : NULL));
while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
@@ -379,7 +383,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
if (!bus)
return -EINVAL;

- klist_iter_init_node(&bus->klist_drivers, &i,
+ klist_iter_init_node(&bus->p->klist_drivers, &i,
start ? &start->knode_bus : NULL);
while ((drv = next_driver(&i)) && !error)
error = fn(drv, data);
@@ -420,7 +424,7 @@ static void device_remove_attrs(struct bus_type * bus, struct device * dev)
static int make_deprecated_bus_links(struct device *dev)
{
return sysfs_create_link(&dev->kobj,
- &dev->bus->subsys.kobj, "bus");
+ &dev->bus->p->subsys.kobj, "bus");
}

static void remove_deprecated_bus_links(struct device *dev)
@@ -449,12 +453,12 @@ int bus_add_device(struct device * dev)
error = device_add_attrs(bus, dev);
if (error)
goto out_put;
- error = sysfs_create_link(&bus->devices_kset->kobj,
+ error = sysfs_create_link(&bus->p->devices_kset->kobj,
&dev->kobj, dev->bus_id);
if (error)
goto out_id;
error = sysfs_create_link(&dev->kobj,
- &dev->bus->subsys.kobj, "subsystem");
+ &dev->bus->p->subsys.kobj, "subsystem");
if (error)
goto out_subsys;
error = make_deprecated_bus_links(dev);
@@ -466,7 +470,7 @@ int bus_add_device(struct device * dev)
out_deprecated:
sysfs_remove_link(&dev->kobj, "subsystem");
out_subsys:
- sysfs_remove_link(&bus->devices_kset->kobj, dev->bus_id);
+ sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id);
out_id:
device_remove_attrs(bus, dev);
out_put:
@@ -488,11 +492,11 @@ void bus_attach_device(struct device * dev)

if (bus) {
dev->is_registered = 1;
- if (bus->drivers_autoprobe)
+ if (bus->p->drivers_autoprobe)
ret = device_attach(dev);
WARN_ON(ret < 0);
if (ret >= 0)
- klist_add_tail(&dev->knode_bus, &bus->klist_devices);
+ klist_add_tail(&dev->knode_bus, &bus->p->klist_devices);
else
dev->is_registered = 0;
}
@@ -512,7 +516,7 @@ void bus_remove_device(struct device * dev)
if (dev->bus) {
sysfs_remove_link(&dev->kobj, "subsystem");
remove_deprecated_bus_links(dev);
- sysfs_remove_link(&dev->bus->devices_kset->kobj, dev->bus_id);
+ sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id);
device_remove_attrs(dev->bus, dev);
if (dev->is_registered) {
dev->is_registered = 0;
@@ -638,18 +642,18 @@ int bus_add_driver(struct device_driver *drv)
error = kobject_set_name(&drv->kobj, "%s", drv->name);
if (error)
goto out_put_bus;
- drv->kobj.kset = bus->drivers_kset;
+ drv->kobj.kset = bus->p->drivers_kset;
drv->kobj.ktype = &driver_ktype;
error = kobject_register(&drv->kobj);
if (error)
goto out_put_bus;

- if (drv->bus->drivers_autoprobe) {
+ if (drv->bus->p->drivers_autoprobe) {
error = driver_attach(drv);
if (error)
goto out_unregister;
}
- klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
+ klist_add_tail(&drv->knode_bus, &bus->p->klist_drivers);
module_add_driver(drv->owner, drv);

error = driver_create_file(drv, &driver_attr_uevent);
@@ -828,7 +832,7 @@ static ssize_t bus_uevent_store(struct bus_type *bus,
enum kobject_action action;

if (kobject_action_type(buf, count, &action) == 0)
- kobject_uevent(&bus->subsys.kobj, action);
+ kobject_uevent(&bus->p->subsys.kobj, action);
return count;
}
static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
@@ -844,17 +848,26 @@ static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);
int bus_register(struct bus_type * bus)
{
int retval;
+ struct bus_type_private *priv;
+
+ priv = kzalloc(sizeof(struct bus_type_private), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->bus = bus;
+ bus->p = priv;

- BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier);
+ BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier);

- retval = kobject_set_name(&bus->subsys.kobj, "%s", bus->name);
+ retval = kobject_set_name(&priv->subsys.kobj, "%s", bus->name);
if (retval)
goto out;

- bus->subsys.kobj.kset = bus_kset;
- bus->subsys.kobj.ktype = &bus_ktype;
+ priv->subsys.kobj.kset = bus_kset;
+ priv->subsys.kobj.ktype = &bus_ktype;
+ priv->drivers_autoprobe = 1;

- retval = kset_register(&bus->subsys);
+ retval = kset_register(&priv->subsys);
if (retval)
goto out;

@@ -862,24 +875,23 @@ int bus_register(struct bus_type * bus)
if (retval)
goto bus_uevent_fail;

- bus->devices_kset = kset_create_and_add("devices", NULL,
- &bus->subsys.kobj);
- if (!bus->devices_kset) {
+ priv->devices_kset = kset_create_and_add("devices", NULL,
+ &priv->subsys.kobj);
+ if (!priv->devices_kset) {
retval = -ENOMEM;
goto bus_devices_fail;
}

- bus->drivers_kset = kset_create_and_add("drivers", NULL,
- &bus->subsys.kobj);
- if (!bus->drivers_kset) {
+ priv->drivers_kset = kset_create_and_add("drivers", NULL,
+ &priv->subsys.kobj);
+ if (!priv->drivers_kset) {
retval = -ENOMEM;
goto bus_drivers_fail;
}

- klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
- klist_init(&bus->klist_drivers, NULL, NULL);
+ klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put);
+ klist_init(&priv->klist_drivers, NULL, NULL);

- bus->drivers_autoprobe = 1;
retval = add_probe_files(bus);
if (retval)
goto bus_probe_files_fail;
@@ -894,13 +906,14 @@ int bus_register(struct bus_type * bus)
bus_attrs_fail:
remove_probe_files(bus);
bus_probe_files_fail:
- kset_unregister(bus->drivers_kset);
+ kset_unregister(bus->p->drivers_kset);
bus_drivers_fail:
- kset_unregister(bus->devices_kset);
+ kset_unregister(bus->p->devices_kset);
bus_devices_fail:
bus_remove_file(bus, &bus_attr_uevent);
bus_uevent_fail:
- kset_unregister(&bus->subsys);
+ kset_unregister(&bus->p->subsys);
+ kfree(bus->p);
out:
return retval;
}
@@ -917,33 +930,34 @@ void bus_unregister(struct bus_type * bus)
pr_debug("bus %s: unregistering\n", bus->name);
bus_remove_attrs(bus);
remove_probe_files(bus);
- kset_unregister(bus->drivers_kset);
- kset_unregister(bus->devices_kset);
+ kset_unregister(bus->p->drivers_kset);
+ kset_unregister(bus->p->devices_kset);
bus_remove_file(bus, &bus_attr_uevent);
- kset_unregister(&bus->subsys);
+ kset_unregister(&bus->p->subsys);
+ kfree(bus->p);
}

int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
{
- return blocking_notifier_chain_register(&bus->bus_notifier, nb);
+ return blocking_notifier_chain_register(&bus->p->bus_notifier, nb);
}
EXPORT_SYMBOL_GPL(bus_register_notifier);

int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
{
- return blocking_notifier_chain_unregister(&bus->bus_notifier, nb);
+ return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb);
}
EXPORT_SYMBOL_GPL(bus_unregister_notifier);

struct kset *bus_get_kset(struct bus_type *bus)
{
- return &bus->subsys;
+ return &bus->p->subsys;
}
EXPORT_SYMBOL_GPL(bus_get_kset);

struct klist *bus_get_device_klist(struct bus_type *bus)
{
- return &bus->klist_devices;
+ return &bus->p->klist_devices;
}
EXPORT_SYMBOL_GPL(bus_get_device_klist);

diff --git a/drivers/base/core.c b/drivers/base/core.c
index beb3516..414a480 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -769,7 +769,7 @@ int device_add(struct device *dev)

/* notify clients of device entry (new way) */
if (dev->bus)
- blocking_notifier_call_chain(&dev->bus->bus_notifier,
+ blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_ADD_DEVICE, dev);

error = device_create_file(dev, &uevent_attr);
@@ -820,7 +820,7 @@ int device_add(struct device *dev)
dpm_sysfs_remove(dev);
PMError:
if (dev->bus)
- blocking_notifier_call_chain(&dev->bus->bus_notifier,
+ blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
device_remove_attrs(dev);
AttrsError:
@@ -999,7 +999,7 @@ void device_del(struct device * dev)
if (platform_notify_remove)
platform_notify_remove(dev);
if (dev->bus)
- blocking_notifier_call_chain(&dev->bus->bus_notifier,
+ blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj);
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7ac474d..7bf0e67 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -38,7 +38,7 @@ static void driver_bound(struct device *dev)
dev->bus_id, dev->driver->name);

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

klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
@@ -296,7 +296,7 @@ static void __device_release_driver(struct device * dev)
klist_remove(&dev->knode_driver);

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

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1c9770d..f94be40 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)
*/
struct device_driver *driver_find(const char *name, struct bus_type *bus)
{
- struct kobject *k = kset_find_obj(bus->drivers_kset, name);
+ struct kobject *k = kset_find_obj(bus->p->drivers_kset, name);
if (k)
return to_drv(k);
return NULL;
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index fb56092..d56a05f 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -497,12 +497,12 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
* if the probe was successful, and make sure any forced probes of
* new devices fail.
*/
- spin_lock(&platform_bus_type.klist_drivers.k_lock);
+ spin_lock(&platform_bus_type.p->klist_drivers.k_lock);
drv->probe = NULL;
if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
retval = -ENODEV;
drv->driver.probe = platform_drv_probe_fail;
- spin_unlock(&platform_bus_type.klist_drivers.k_lock);
+ spin_unlock(&platform_bus_type.p->klist_drivers.k_lock);

if (code != retval)
platform_driver_unregister(drv);
diff --git a/include/linux/device.h b/include/linux/device.h
index 62e695b..3f24bf4 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -35,6 +35,7 @@ struct device_driver;
struct class;
struct class_device;
struct bus_type;
+struct bus_type_private;

struct bus_attribute {
struct attribute attr;
@@ -51,15 +52,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);

struct bus_type {
const char * name;
-
- struct kset subsys;
- struct kset *drivers_kset;
- struct kset *devices_kset;
- struct klist klist_devices;
- struct klist klist_drivers;
-
- struct blocking_notifier_head bus_notifier;
-
struct bus_attribute * bus_attrs;
struct device_attribute * dev_attrs;
struct driver_attribute * drv_attrs;
@@ -75,7 +67,7 @@ struct bus_type {
int (*resume_early)(struct device * dev);
int (*resume)(struct device * dev);

- unsigned int drivers_autoprobe:1;
+ struct bus_type_private *p;
};

extern int __must_check bus_register(struct bus_type * bus);
--
1.5.3.8

2008-01-25 08:12:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 161/196] Kobject: convert drivers/md/md.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Neil Brown <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/md/md.c | 13 ++++---------
1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index f79efb3..7ae9740 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1383,16 +1383,13 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
return -EBUSY;
}
bdevname(rdev->bdev,b);
- if (kobject_set_name(&rdev->kobj, "dev-%s", b) < 0)
- return -ENOMEM;
- while ( (s=strchr(rdev->kobj.k_name, '/')) != NULL)
+ while ( (s=strchr(b, '/')) != NULL)
*s = '!';
-
+
rdev->mddev = mddev;
printk(KERN_INFO "md: bind<%s>\n", b);

- rdev->kobj.parent = &mddev->kobj;
- if ((err = kobject_add(&rdev->kobj)))
+ if ((err = kobject_add_ng(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
goto fail;

if (rdev->bdev->bd_part)
@@ -2036,9 +2033,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
if (err)
goto abort_free;

- rdev->kobj.parent = NULL;
- rdev->kobj.ktype = &rdev_ktype;
- kobject_init(&rdev->kobj);
+ kobject_init_ng(&rdev->kobj, &rdev_ktype);

rdev->desc_nr = -1;
rdev->saved_raid_disk = -1;
--
1.5.3.8

2008-01-25 08:13:26

by Greg KH

[permalink] [raw]
Subject: [PATCH 123/196] Kobject: change drivers/parisc/pdc_stable.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Kyle McMartin <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Grant Grundler <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/parisc/pdc_stable.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/parisc/pdc_stable.c b/drivers/parisc/pdc_stable.c
index 880b10b..87bc6b7 100644
--- a/drivers/parisc/pdc_stable.c
+++ b/drivers/parisc/pdc_stable.c
@@ -991,13 +991,12 @@ pdcs_register_pathentries(void)
if (err < 0)
continue;

- if ((err = kobject_set_name(&entry->kobj, "%s", entry->name)))
- return err;
entry->kobj.kset = paths_kset;
- entry->kobj.ktype = &ktype_pdcspath;
- if ((err = kobject_register(&entry->kobj)))
+ err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
+ "%s", entry->name);
+ if (err)
return err;
-
+
/* kobject is now registered */
write_lock(&entry->rw_lock);
entry->ready = 2;
@@ -1009,6 +1008,7 @@ pdcs_register_pathentries(void)
}

write_unlock(&entry->rw_lock);
+ kobject_uevent(&entry->kobj, KOBJ_ADD);
}

return 0;
--
1.5.3.8

2008-01-25 08:13:49

by Greg KH

[permalink] [raw]
Subject: [PATCH 165/196] Kobject: remove kobject_init() as no one uses it anymore

The old kobject_init() function is on longer in use, so let us remove it
from the public scope (kset mess in the kobject.c file still uses it,
but that can be cleaned up later very simply.)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 1 -
lib/kobject.c | 11 +++--------
2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 84c5afd..53458b6 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -78,7 +78,6 @@ static inline const char * kobject_name(const struct kobject * kobj)
return kobj->k_name;
}

-extern void kobject_init(struct kobject *);
extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
extern int __must_check kobject_add(struct kobject *kobj,
struct kobject *parent,
diff --git a/lib/kobject.c b/lib/kobject.c
index 359e114..10d977b 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -124,11 +124,7 @@ char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
}
EXPORT_SYMBOL_GPL(kobject_get_path);

-/**
- * kobject_init - initialize object.
- * @kobj: object in question.
- */
-void kobject_init(struct kobject * kobj)
+static void kobject_init_internal(struct kobject * kobj)
{
if (!kobj)
return;
@@ -232,7 +228,7 @@ int kobject_register(struct kobject * kobj)
{
int error = -EINVAL;
if (kobj) {
- kobject_init(kobj);
+ kobject_init_internal(kobj);
error = kobject_add(kobj);
if (!error)
kobject_uevent(kobj, KOBJ_ADD);
@@ -695,7 +691,7 @@ EXPORT_SYMBOL_GPL(kobject_create_and_add);

void kset_init(struct kset * k)
{
- kobject_init(&k->kobj);
+ kobject_init_internal(&k->kobj);
INIT_LIST_HEAD(&k->list);
spin_lock_init(&k->list_lock);
}
@@ -887,7 +883,6 @@ struct kset *kset_create_and_add(const char *name,
}
EXPORT_SYMBOL_GPL(kset_create_and_add);

-EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
--
1.5.3.8

2008-01-25 08:14:17

by Greg KH

[permalink] [raw]
Subject: [PATCH 196/196] Driver core: coding style fixes

Fix up a number of coding style issues in the drivers/base/ directory
that have annoyed me over the years. checkpatch.pl is now very happy.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 14 +-
drivers/base/bus.c | 290 +++++++++++++++++++++++------------------------
drivers/base/class.c | 140 +++++++++++-----------
drivers/base/core.c | 203 +++++++++++++++------------------
drivers/base/dd.c | 119 ++++++++++----------
drivers/base/driver.c | 120 +++++++++-----------
drivers/base/init.c | 9 +-
drivers/base/platform.c | 233 +++++++++++++++++++-------------------
8 files changed, 545 insertions(+), 583 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index f7ad65a..c044414 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -50,15 +50,15 @@ extern int platform_bus_init(void);
extern int system_bus_init(void);
extern int cpu_dev_init(void);

-extern int bus_add_device(struct device * dev);
-extern void bus_attach_device(struct device * dev);
-extern void bus_remove_device(struct device * dev);
+extern int bus_add_device(struct device *dev);
+extern void bus_attach_device(struct device *dev);
+extern void bus_remove_device(struct device *dev);

-extern int bus_add_driver(struct device_driver *);
-extern void bus_remove_driver(struct device_driver *);
+extern int bus_add_driver(struct device_driver *drv);
+extern void bus_remove_driver(struct device_driver *drv);

-extern void driver_detach(struct device_driver * drv);
-extern int driver_probe_device(struct device_driver *, struct device *);
+extern void driver_detach(struct device_driver *drv);
+extern int driver_probe_device(struct device_driver *drv, struct device *dev);

extern void sysdev_shutdown(void);
extern int sysdev_suspend(pm_message_t state);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index a377b65..f484495 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -46,10 +46,10 @@ static void bus_put(struct bus_type *bus)
kset_put(&bus->p->subsys);
}

-static ssize_t
-drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
+static ssize_t drv_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
{
- struct driver_attribute * drv_attr = to_drv_attr(attr);
+ struct driver_attribute *drv_attr = to_drv_attr(attr);
struct driver_private *drv_priv = to_driver(kobj);
ssize_t ret = -EIO;

@@ -58,11 +58,10 @@ drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
return ret;
}

-static ssize_t
-drv_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * buf, size_t count)
+static ssize_t drv_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
{
- struct driver_attribute * drv_attr = to_drv_attr(attr);
+ struct driver_attribute *drv_attr = to_drv_attr(attr);
struct driver_private *drv_priv = to_driver(kobj);
ssize_t ret = -EIO;

@@ -89,16 +88,13 @@ static struct kobj_type driver_ktype = {
.release = driver_release,
};

-
/*
* sysfs bindings for buses
*/
-
-
-static ssize_t
-bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
+static ssize_t bus_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
{
- struct bus_attribute * bus_attr = to_bus_attr(attr);
+ struct bus_attribute *bus_attr = to_bus_attr(attr);
struct bus_type_private *bus_priv = to_bus(kobj);
ssize_t ret = 0;

@@ -107,11 +103,10 @@ bus_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
return ret;
}

-static ssize_t
-bus_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * buf, size_t count)
+static ssize_t bus_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
{
- struct bus_attribute * bus_attr = to_bus_attr(attr);
+ struct bus_attribute *bus_attr = to_bus_attr(attr);
struct bus_type_private *bus_priv = to_bus(kobj);
ssize_t ret = 0;

@@ -125,7 +120,7 @@ static struct sysfs_ops bus_sysfs_ops = {
.store = bus_attr_store,
};

-int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
+int bus_create_file(struct bus_type *bus, struct bus_attribute *attr)
{
int error;
if (bus_get(bus)) {
@@ -135,14 +130,16 @@ int bus_create_file(struct bus_type * bus, struct bus_attribute * attr)
error = -EINVAL;
return error;
}
+EXPORT_SYMBOL_GPL(bus_create_file);

-void bus_remove_file(struct bus_type * bus, struct bus_attribute * attr)
+void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
{
if (bus_get(bus)) {
sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr);
bus_put(bus);
}
}
+EXPORT_SYMBOL_GPL(bus_remove_file);

static struct kobj_type bus_ktype = {
.sysfs_ops = &bus_sysfs_ops,
@@ -219,10 +216,13 @@ static ssize_t driver_bind(struct device_driver *drv,
if (dev->parent)
up(&dev->parent->sem);

- if (err > 0) /* success */
+ if (err > 0) {
+ /* success */
err = count;
- else if (err == 0) /* driver didn't accept device */
+ } else if (err == 0) {
+ /* driver didn't accept device */
err = -ENODEV;
+ }
}
put_device(dev);
bus_put(bus);
@@ -259,37 +259,36 @@ static ssize_t store_drivers_probe(struct bus_type *bus,
}
#endif

-static struct device * next_device(struct klist_iter * i)
+static struct device *next_device(struct klist_iter *i)
{
- struct klist_node * n = klist_next(i);
+ struct klist_node *n = klist_next(i);
return n ? container_of(n, struct device, knode_bus) : NULL;
}

/**
- * bus_for_each_dev - device iterator.
- * @bus: bus type.
- * @start: device to start iterating from.
- * @data: data for the callback.
- * @fn: function to be called for each device.
+ * bus_for_each_dev - device iterator.
+ * @bus: bus type.
+ * @start: device to start iterating from.
+ * @data: data for the callback.
+ * @fn: function to be called for each device.
*
- * Iterate over @bus's list of devices, and call @fn for each,
- * passing it @data. If @start is not NULL, we use that device to
- * begin iterating from.
+ * Iterate over @bus's list of devices, and call @fn for each,
+ * passing it @data. If @start is not NULL, we use that device to
+ * begin iterating from.
*
- * We check the return of @fn each time. If it returns anything
- * other than 0, we break out and return that value.
+ * We check the return of @fn each time. If it returns anything
+ * other than 0, we break out and return that value.
*
- * NOTE: The device that returns a non-zero value is not retained
- * in any way, nor is its refcount incremented. If the caller needs
- * to retain this data, it should do, and increment the reference
- * count in the supplied callback.
+ * NOTE: The device that returns a non-zero value is not retained
+ * in any way, nor is its refcount incremented. If the caller needs
+ * to retain this data, it should do, and increment the reference
+ * count in the supplied callback.
*/
-
-int bus_for_each_dev(struct bus_type * bus, struct device * start,
- void * data, int (*fn)(struct device *, void *))
+int bus_for_each_dev(struct bus_type *bus, struct device *start,
+ void *data, int (*fn)(struct device *, void *))
{
struct klist_iter i;
- struct device * dev;
+ struct device *dev;
int error = 0;

if (!bus)
@@ -302,6 +301,7 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
klist_iter_exit(&i);
return error;
}
+EXPORT_SYMBOL_GPL(bus_for_each_dev);

/**
* bus_find_device - device iterator for locating a particular device.
@@ -318,9 +318,9 @@ int bus_for_each_dev(struct bus_type * bus, struct device * start,
* if it does. If the callback returns non-zero, this function will
* return to the caller and not iterate over any more devices.
*/
-struct device * bus_find_device(struct bus_type *bus,
- struct device *start, void *data,
- int (*match)(struct device *, void *))
+struct device *bus_find_device(struct bus_type *bus,
+ struct device *start, void *data,
+ int (*match)(struct device *dev, void *data))
{
struct klist_iter i;
struct device *dev;
@@ -336,11 +336,11 @@ struct device * bus_find_device(struct bus_type *bus,
klist_iter_exit(&i);
return dev;
}
+EXPORT_SYMBOL_GPL(bus_find_device);

-
-static struct device_driver * next_driver(struct klist_iter * i)
+static struct device_driver *next_driver(struct klist_iter *i)
{
- struct klist_node * n = klist_next(i);
+ struct klist_node *n = klist_next(i);
struct driver_private *drv_priv;

if (n) {
@@ -351,30 +351,29 @@ static struct device_driver * next_driver(struct klist_iter * i)
}

/**
- * bus_for_each_drv - driver iterator
- * @bus: bus we're dealing with.
- * @start: driver to start iterating on.
- * @data: data to pass to the callback.
- * @fn: function to call for each driver.
+ * bus_for_each_drv - driver iterator
+ * @bus: bus we're dealing with.
+ * @start: driver to start iterating on.
+ * @data: data to pass to the callback.
+ * @fn: function to call for each driver.
*
- * This is nearly identical to the device iterator above.
- * We iterate over each driver that belongs to @bus, and call
- * @fn for each. If @fn returns anything but 0, we break out
- * and return it. If @start is not NULL, we use it as the head
- * of the list.
+ * This is nearly identical to the device iterator above.
+ * We iterate over each driver that belongs to @bus, and call
+ * @fn for each. If @fn returns anything but 0, we break out
+ * and return it. If @start is not NULL, we use it as the head
+ * of the list.
*
- * NOTE: we don't return the driver that returns a non-zero
- * value, nor do we leave the reference count incremented for that
- * driver. If the caller needs to know that info, it must set it
- * in the callback. It must also be sure to increment the refcount
- * so it doesn't disappear before returning to the caller.
+ * NOTE: we don't return the driver that returns a non-zero
+ * value, nor do we leave the reference count incremented for that
+ * driver. If the caller needs to know that info, it must set it
+ * in the callback. It must also be sure to increment the refcount
+ * so it doesn't disappear before returning to the caller.
*/
-
-int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
- void * data, int (*fn)(struct device_driver *, void *))
+int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
+ void *data, int (*fn)(struct device_driver *, void *))
{
struct klist_iter i;
- struct device_driver * drv;
+ struct device_driver *drv;
int error = 0;

if (!bus)
@@ -387,6 +386,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
klist_iter_exit(&i);
return error;
}
+EXPORT_SYMBOL_GPL(bus_for_each_drv);

static int device_add_attrs(struct bus_type *bus, struct device *dev)
{
@@ -397,7 +397,7 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev)
return 0;

for (i = 0; attr_name(bus->dev_attrs[i]); i++) {
- error = device_create_file(dev,&bus->dev_attrs[i]);
+ error = device_create_file(dev, &bus->dev_attrs[i]);
if (error) {
while (--i >= 0)
device_remove_file(dev, &bus->dev_attrs[i]);
@@ -407,13 +407,13 @@ static int device_add_attrs(struct bus_type *bus, struct device *dev)
return error;
}

-static void device_remove_attrs(struct bus_type * bus, struct device * dev)
+static void device_remove_attrs(struct bus_type *bus, struct device *dev)
{
int i;

if (bus->dev_attrs) {
for (i = 0; attr_name(bus->dev_attrs[i]); i++)
- device_remove_file(dev,&bus->dev_attrs[i]);
+ device_remove_file(dev, &bus->dev_attrs[i]);
}
}

@@ -434,15 +434,15 @@ static inline void remove_deprecated_bus_links(struct device *dev) { }
#endif

/**
- * bus_add_device - add device to bus
- * @dev: device being added
+ * bus_add_device - add device to bus
+ * @dev: device being added
*
- * - Add the device to its bus's list of devices.
- * - Create link to device's bus.
+ * - Add the device to its bus's list of devices.
+ * - Create link to device's bus.
*/
-int bus_add_device(struct device * dev)
+int bus_add_device(struct device *dev)
{
- struct bus_type * bus = bus_get(dev->bus);
+ struct bus_type *bus = bus_get(dev->bus);
int error = 0;

if (bus) {
@@ -476,13 +476,13 @@ out_put:
}

/**
- * bus_attach_device - add device to bus
- * @dev: device tried to attach to a driver
+ * bus_attach_device - add device to bus
+ * @dev: device tried to attach to a driver
*
- * - Add device to bus's list of devices.
- * - Try to attach to driver.
+ * - Add device to bus's list of devices.
+ * - Try to attach to driver.
*/
-void bus_attach_device(struct device * dev)
+void bus_attach_device(struct device *dev)
{
struct bus_type *bus = dev->bus;
int ret = 0;
@@ -500,32 +500,34 @@ void bus_attach_device(struct device * dev)
}

/**
- * bus_remove_device - remove device from bus
- * @dev: device to be removed
+ * bus_remove_device - remove device from bus
+ * @dev: device to be removed
*
- * - Remove symlink from bus's directory.
- * - Delete device from bus's list.
- * - Detach from its driver.
- * - Drop reference taken in bus_add_device().
+ * - Remove symlink from bus's directory.
+ * - Delete device from bus's list.
+ * - Detach from its driver.
+ * - Drop reference taken in bus_add_device().
*/
-void bus_remove_device(struct device * dev)
+void bus_remove_device(struct device *dev)
{
if (dev->bus) {
sysfs_remove_link(&dev->kobj, "subsystem");
remove_deprecated_bus_links(dev);
- sysfs_remove_link(&dev->bus->p->devices_kset->kobj, dev->bus_id);
+ sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
+ dev->bus_id);
device_remove_attrs(dev->bus, dev);
if (dev->is_registered) {
dev->is_registered = 0;
klist_del(&dev->knode_bus);
}
- pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id);
+ pr_debug("bus: '%s': remove device %s\n",
+ dev->bus->name, dev->bus_id);
device_release_driver(dev);
bus_put(dev->bus);
}
}

-static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
+static int driver_add_attrs(struct bus_type *bus, struct device_driver *drv)
{
int error = 0;
int i;
@@ -534,19 +536,19 @@ static int driver_add_attrs(struct bus_type * bus, struct device_driver * drv)
for (i = 0; attr_name(bus->drv_attrs[i]); i++) {
error = driver_create_file(drv, &bus->drv_attrs[i]);
if (error)
- goto Err;
+ goto err;
}
}
- Done:
+done:
return error;
- Err:
+err:
while (--i >= 0)
driver_remove_file(drv, &bus->drv_attrs[i]);
- goto Done;
+ goto done;
}

-
-static void driver_remove_attrs(struct bus_type * bus, struct device_driver * drv)
+static void driver_remove_attrs(struct bus_type *bus,
+ struct device_driver *drv)
{
int i;

@@ -623,9 +625,8 @@ static ssize_t driver_uevent_store(struct device_driver *drv,
static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store);

/**
- * bus_add_driver - Add a driver to the bus.
- * @drv: driver.
- *
+ * bus_add_driver - Add a driver to the bus.
+ * @drv: driver.
*/
int bus_add_driver(struct device_driver *drv)
{
@@ -688,15 +689,14 @@ out_put_bus:
}

/**
- * bus_remove_driver - delete driver from bus's knowledge.
- * @drv: driver.
+ * bus_remove_driver - delete driver from bus's knowledge.
+ * @drv: driver.
*
- * Detach the driver from the devices it controls, and remove
- * it from its bus's list of drivers. Finally, we drop the reference
- * to the bus we took in bus_add_driver().
+ * Detach the driver from the devices it controls, and remove
+ * it from its bus's list of drivers. Finally, we drop the reference
+ * to the bus we took in bus_add_driver().
*/
-
-void bus_remove_driver(struct device_driver * drv)
+void bus_remove_driver(struct device_driver *drv)
{
if (!drv->bus)
return;
@@ -712,10 +712,9 @@ void bus_remove_driver(struct device_driver * drv)
bus_put(drv->bus);
}

-
/* Helper for bus_rescan_devices's iter */
static int __must_check bus_rescan_devices_helper(struct device *dev,
- void *data)
+ void *data)
{
int ret = 0;

@@ -737,10 +736,11 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
* attached and rescan it against existing drivers to see if it matches
* any by calling device_attach() for the unbound devices.
*/
-int bus_rescan_devices(struct bus_type * bus)
+int bus_rescan_devices(struct bus_type *bus)
{
return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper);
}
+EXPORT_SYMBOL_GPL(bus_rescan_devices);

/**
* device_reprobe - remove driver for a device and probe for a new driver
@@ -765,55 +765,55 @@ int device_reprobe(struct device *dev)
EXPORT_SYMBOL_GPL(device_reprobe);

/**
- * find_bus - locate bus by name.
- * @name: name of bus.
+ * find_bus - locate bus by name.
+ * @name: name of bus.
*
- * Call kset_find_obj() to iterate over list of buses to
- * find a bus by name. Return bus if found.
+ * Call kset_find_obj() to iterate over list of buses to
+ * find a bus by name. Return bus if found.
*
- * Note that kset_find_obj increments bus' reference count.
+ * Note that kset_find_obj increments bus' reference count.
*/
#if 0
-struct bus_type * find_bus(char * name)
+struct bus_type *find_bus(char *name)
{
- struct kobject * k = kset_find_obj(bus_kset, name);
+ struct kobject *k = kset_find_obj(bus_kset, name);
return k ? to_bus(k) : NULL;
}
#endif /* 0 */


/**
- * bus_add_attrs - Add default attributes for this bus.
- * @bus: Bus that has just been registered.
+ * bus_add_attrs - Add default attributes for this bus.
+ * @bus: Bus that has just been registered.
*/

-static int bus_add_attrs(struct bus_type * bus)
+static int bus_add_attrs(struct bus_type *bus)
{
int error = 0;
int i;

if (bus->bus_attrs) {
for (i = 0; attr_name(bus->bus_attrs[i]); i++) {
- error = bus_create_file(bus,&bus->bus_attrs[i]);
+ error = bus_create_file(bus, &bus->bus_attrs[i]);
if (error)
- goto Err;
+ goto err;
}
}
- Done:
+done:
return error;
- Err:
+err:
while (--i >= 0)
- bus_remove_file(bus,&bus->bus_attrs[i]);
- goto Done;
+ bus_remove_file(bus, &bus->bus_attrs[i]);
+ goto done;
}

-static void bus_remove_attrs(struct bus_type * bus)
+static void bus_remove_attrs(struct bus_type *bus)
{
int i;

if (bus->bus_attrs) {
for (i = 0; attr_name(bus->bus_attrs[i]); i++)
- bus_remove_file(bus,&bus->bus_attrs[i]);
+ bus_remove_file(bus, &bus->bus_attrs[i]);
}
}

@@ -843,14 +843,14 @@ static ssize_t bus_uevent_store(struct bus_type *bus,
static BUS_ATTR(uevent, S_IWUSR, NULL, bus_uevent_store);

/**
- * bus_register - register a bus with the system.
- * @bus: bus.
+ * bus_register - register a bus with the system.
+ * @bus: bus.
*
- * Once we have that, we registered the bus with the kobject
- * infrastructure, then register the children subsystems it has:
- * the devices and drivers that belong to the bus.
+ * Once we have that, we registered the bus with the kobject
+ * infrastructure, then register the children subsystems it has:
+ * the devices and drivers that belong to the bus.
*/
-int bus_register(struct bus_type * bus)
+int bus_register(struct bus_type *bus)
{
int retval;
struct bus_type_private *priv;
@@ -922,15 +922,16 @@ bus_uevent_fail:
out:
return retval;
}
+EXPORT_SYMBOL_GPL(bus_register);

/**
- * bus_unregister - remove a bus from the system
- * @bus: bus.
+ * bus_unregister - remove a bus from the system
+ * @bus: bus.
*
- * Unregister the child subsystems and the bus itself.
- * Finally, we call bus_put() to release the refcount
+ * Unregister the child subsystems and the bus itself.
+ * Finally, we call bus_put() to release the refcount
*/
-void bus_unregister(struct bus_type * bus)
+void bus_unregister(struct bus_type *bus)
{
pr_debug("bus: '%s': unregistering\n", bus->name);
bus_remove_attrs(bus);
@@ -941,6 +942,7 @@ void bus_unregister(struct bus_type * bus)
kset_unregister(&bus->p->subsys);
kfree(bus->p);
}
+EXPORT_SYMBOL_GPL(bus_unregister);

int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
{
@@ -973,15 +975,3 @@ int __init buses_init(void)
return -ENOMEM;
return 0;
}
-
-
-EXPORT_SYMBOL_GPL(bus_for_each_dev);
-EXPORT_SYMBOL_GPL(bus_find_device);
-EXPORT_SYMBOL_GPL(bus_for_each_drv);
-
-EXPORT_SYMBOL_GPL(bus_register);
-EXPORT_SYMBOL_GPL(bus_unregister);
-EXPORT_SYMBOL_GPL(bus_rescan_devices);
-
-EXPORT_SYMBOL_GPL(bus_create_file);
-EXPORT_SYMBOL_GPL(bus_remove_file);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 9f737ff..59cf358 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -23,11 +23,11 @@
#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
#define to_class(obj) container_of(obj, struct class, subsys.kobj)

-static ssize_t
-class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
+static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
{
- struct class_attribute * class_attr = to_class_attr(attr);
- struct class * dc = to_class(kobj);
+ struct class_attribute *class_attr = to_class_attr(attr);
+ struct class *dc = to_class(kobj);
ssize_t ret = -EIO;

if (class_attr->show)
@@ -35,12 +35,11 @@ class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
return ret;
}

-static ssize_t
-class_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * buf, size_t count)
+static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
{
- struct class_attribute * class_attr = to_class_attr(attr);
- struct class * dc = to_class(kobj);
+ struct class_attribute *class_attr = to_class_attr(attr);
+ struct class *dc = to_class(kobj);
ssize_t ret = -EIO;

if (class_attr->store)
@@ -48,7 +47,7 @@ class_attr_store(struct kobject * kobj, struct attribute * attr,
return ret;
}

-static void class_release(struct kobject * kobj)
+static void class_release(struct kobject *kobj)
{
struct class *class = to_class(kobj);

@@ -75,17 +74,17 @@ static struct kobj_type class_ktype = {
static struct kset *class_kset;


-int class_create_file(struct class * cls, const struct class_attribute * attr)
+int class_create_file(struct class *cls, const struct class_attribute *attr)
{
int error;
- if (cls) {
+ if (cls)
error = sysfs_create_file(&cls->subsys.kobj, &attr->attr);
- } else
+ else
error = -EINVAL;
return error;
}

-void class_remove_file(struct class * cls, const struct class_attribute * attr)
+void class_remove_file(struct class *cls, const struct class_attribute *attr)
{
if (cls)
sysfs_remove_file(&cls->subsys.kobj, &attr->attr);
@@ -94,48 +93,48 @@ void class_remove_file(struct class * cls, const struct class_attribute * attr)
static struct class *class_get(struct class *cls)
{
if (cls)
- return container_of(kset_get(&cls->subsys), struct class, subsys);
+ return container_of(kset_get(&cls->subsys),
+ struct class, subsys);
return NULL;
}

-static void class_put(struct class * cls)
+static void class_put(struct class *cls)
{
if (cls)
kset_put(&cls->subsys);
}

-
-static int add_class_attrs(struct class * cls)
+static int add_class_attrs(struct class *cls)
{
int i;
int error = 0;

if (cls->class_attrs) {
for (i = 0; attr_name(cls->class_attrs[i]); i++) {
- error = class_create_file(cls,&cls->class_attrs[i]);
+ error = class_create_file(cls, &cls->class_attrs[i]);
if (error)
- goto Err;
+ goto error;
}
}
- Done:
+done:
return error;
- Err:
+error:
while (--i >= 0)
- class_remove_file(cls,&cls->class_attrs[i]);
- goto Done;
+ class_remove_file(cls, &cls->class_attrs[i]);
+ goto done;
}

-static void remove_class_attrs(struct class * cls)
+static void remove_class_attrs(struct class *cls)
{
int i;

if (cls->class_attrs) {
for (i = 0; attr_name(cls->class_attrs[i]); i++)
- class_remove_file(cls,&cls->class_attrs[i]);
+ class_remove_file(cls, &cls->class_attrs[i]);
}
}

-int class_register(struct class * cls)
+int class_register(struct class *cls)
{
int error;

@@ -167,7 +166,7 @@ int class_register(struct class * cls)
return error;
}

-void class_unregister(struct class * cls)
+void class_unregister(struct class *cls)
{
pr_debug("device class '%s': unregistering\n", cls->name);
remove_class_attrs(cls);
@@ -249,8 +248,8 @@ void class_destroy(struct class *cls)

/* Class Device Stuff */

-int class_device_create_file(struct class_device * class_dev,
- const struct class_device_attribute * attr)
+int class_device_create_file(struct class_device *class_dev,
+ const struct class_device_attribute *attr)
{
int error = -EINVAL;
if (class_dev)
@@ -258,8 +257,8 @@ int class_device_create_file(struct class_device * class_dev,
return error;
}

-void class_device_remove_file(struct class_device * class_dev,
- const struct class_device_attribute * attr)
+void class_device_remove_file(struct class_device *class_dev,
+ const struct class_device_attribute *attr)
{
if (class_dev)
sysfs_remove_file(&class_dev->kobj, &attr->attr);
@@ -281,12 +280,11 @@ void class_device_remove_bin_file(struct class_device *class_dev,
sysfs_remove_bin_file(&class_dev->kobj, attr);
}

-static ssize_t
-class_device_attr_show(struct kobject * kobj, struct attribute * attr,
- char * buf)
+static ssize_t class_device_attr_show(struct kobject *kobj,
+ struct attribute *attr, char *buf)
{
- struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
- struct class_device * cd = to_class_dev(kobj);
+ struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
+ struct class_device *cd = to_class_dev(kobj);
ssize_t ret = 0;

if (class_dev_attr->show)
@@ -294,12 +292,12 @@ class_device_attr_show(struct kobject * kobj, struct attribute * attr,
return ret;
}

-static ssize_t
-class_device_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * buf, size_t count)
+static ssize_t class_device_attr_store(struct kobject *kobj,
+ struct attribute *attr,
+ const char *buf, size_t count)
{
- struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr);
- struct class_device * cd = to_class_dev(kobj);
+ struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr);
+ struct class_device *cd = to_class_dev(kobj);
ssize_t ret = 0;

if (class_dev_attr->store)
@@ -312,10 +310,10 @@ static struct sysfs_ops class_dev_sysfs_ops = {
.store = class_device_attr_store,
};

-static void class_dev_release(struct kobject * kobj)
+static void class_dev_release(struct kobject *kobj)
{
struct class_device *cd = to_class_dev(kobj);
- struct class * cls = cd->class;
+ struct class *cls = cd->class;

pr_debug("device class '%s': release.\n", cd->class_id);

@@ -324,8 +322,8 @@ static void class_dev_release(struct kobject * kobj)
else if (cls->release)
cls->release(cd);
else {
- printk(KERN_ERR "Class Device '%s' does not have a release() function, "
- "it is broken and must be fixed.\n",
+ printk(KERN_ERR "Class Device '%s' does not have a release() "
+ "function, it is broken and must be fixed.\n",
cd->class_id);
WARN_ON(1);
}
@@ -436,7 +434,8 @@ static int class_uevent(struct kset *kset, struct kobject *kobj,
add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);

if (dev->driver)
- add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name);
+ add_uevent_var(env, "PHYSDEVDRIVER=%s",
+ dev->driver->name);
}

if (class_dev->uevent) {
@@ -469,40 +468,40 @@ static struct kset class_obj_subsys = {
.uevent_ops = &class_uevent_ops,
};

-static int class_device_add_attrs(struct class_device * cd)
+static int class_device_add_attrs(struct class_device *cd)
{
int i;
int error = 0;
- struct class * cls = cd->class;
+ struct class *cls = cd->class;

if (cls->class_dev_attrs) {
for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) {
error = class_device_create_file(cd,
- &cls->class_dev_attrs[i]);
+ &cls->class_dev_attrs[i]);
if (error)
- goto Err;
+ goto err;
}
}
- Done:
+done:
return error;
- Err:
+err:
while (--i >= 0)
- class_device_remove_file(cd,&cls->class_dev_attrs[i]);
- goto Done;
+ class_device_remove_file(cd, &cls->class_dev_attrs[i]);
+ goto done;
}

-static void class_device_remove_attrs(struct class_device * cd)
+static void class_device_remove_attrs(struct class_device *cd)
{
int i;
- struct class * cls = cd->class;
+ struct class *cls = cd->class;

if (cls->class_dev_attrs) {
for (i = 0; attr_name(cls->class_dev_attrs[i]); i++)
- class_device_remove_file(cd,&cls->class_dev_attrs[i]);
+ class_device_remove_file(cd, &cls->class_dev_attrs[i]);
}
}

-static int class_device_add_groups(struct class_device * cd)
+static int class_device_add_groups(struct class_device *cd)
{
int i;
int error = 0;
@@ -512,7 +511,8 @@ static int class_device_add_groups(struct class_device * cd)
error = sysfs_create_group(&cd->kobj, cd->groups[i]);
if (error) {
while (--i >= 0)
- sysfs_remove_group(&cd->kobj, cd->groups[i]);
+ sysfs_remove_group(&cd->kobj,
+ cd->groups[i]);
goto out;
}
}
@@ -521,14 +521,12 @@ out:
return error;
}

-static void class_device_remove_groups(struct class_device * cd)
+static void class_device_remove_groups(struct class_device *cd)
{
int i;
- if (cd->groups) {
- for (i = 0; cd->groups[i]; i++) {
+ if (cd->groups)
+ for (i = 0; cd->groups[i]; i++)
sysfs_remove_group(&cd->kobj, cd->groups[i]);
- }
- }
}

static ssize_t show_dev(struct class_device *class_dev, char *buf)
@@ -653,7 +651,7 @@ int class_device_add(struct class_device *class_dev)
out3:
kobject_del(&class_dev->kobj);
out2:
- if(parent_class_dev)
+ if (parent_class_dev)
class_device_put(parent_class_dev);
class_put(parent_class);
out1:
@@ -670,9 +668,11 @@ int class_device_register(struct class_device *class_dev)
/**
* class_device_create - creates a class device and registers it with sysfs
* @cls: pointer to the struct class that this device should be registered to.
- * @parent: pointer to the parent struct class_device of this new device, if any.
+ * @parent: pointer to the parent struct class_device of this new device, if
+ * any.
* @devt: the dev_t for the char device to be added.
- * @device: a pointer to a struct device that is assiociated with this class device.
+ * @device: a pointer to a struct device that is assiociated with this class
+ * device.
* @fmt: string for the class device's name
*
* This function can be used by char device classes. A struct
@@ -796,7 +796,7 @@ void class_device_destroy(struct class *cls, dev_t devt)
class_device_unregister(class_dev);
}

-struct class_device * class_device_get(struct class_device *class_dev)
+struct class_device *class_device_get(struct class_device *class_dev)
{
if (class_dev)
return to_class_dev(kobject_get(&class_dev->kobj));
@@ -973,7 +973,7 @@ int class_interface_register(struct class_interface *class_intf)

void class_interface_unregister(struct class_interface *class_intf)
{
- struct class * parent = class_intf->class;
+ struct class *parent = class_intf->class;
struct class_device *class_dev;
struct device *dev;

diff --git a/drivers/base/core.c b/drivers/base/core.c
index f09dde3..edf3bbe 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -24,8 +24,8 @@
#include "base.h"
#include "power/power.h"

-int (*platform_notify)(struct device * dev) = NULL;
-int (*platform_notify_remove)(struct device * dev) = NULL;
+int (*platform_notify)(struct device *dev) = NULL;
+int (*platform_notify_remove)(struct device *dev) = NULL;

/*
* sysfs bindings for devices.
@@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string);
#define to_dev(obj) container_of(obj, struct device, kobj)
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)

-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);
+ struct device_attribute *dev_attr = to_dev_attr(attr);
+ struct device *dev = to_dev(kobj);
ssize_t ret = -EIO;

if (dev_attr->show)
@@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
return ret;
}

-static ssize_t
-dev_attr_store(struct kobject * kobj, struct attribute * attr,
- const char * buf, size_t count)
+static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
{
- struct device_attribute * dev_attr = to_dev_attr(attr);
- struct device * dev = to_dev(kobj);
+ struct device_attribute *dev_attr = to_dev_attr(attr);
+ struct device *dev = to_dev(kobj);
ssize_t ret = -EIO;

if (dev_attr->store)
@@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = {
* reaches 0. We forward the call to the device's release
* method, which should handle actually freeing the structure.
*/
-static void device_release(struct kobject * kobj)
+static void device_release(struct kobject *kobj)
{
- struct device * dev = to_dev(kobj);
+ struct device *dev = to_dev(kobj);

if (dev->release)
dev->release(dev);
@@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj)
else if (dev->class && dev->class->dev_release)
dev->class->dev_release(dev);
else {
- printk(KERN_ERR "Device '%s' does not have a release() function, "
- "it is broken and must be fixed.\n",
+ printk(KERN_ERR "Device '%s' does not have a release() "
+ "function, it is broken and must be fixed.\n",
dev->bus_id);
WARN_ON(1);
}
@@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);

if (dev->driver)
- add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name);
+ add_uevent_var(env, "PHYSDEVDRIVER=%s",
+ dev->driver->name);
}
#endif

@@ -327,7 +327,8 @@ static int device_add_groups(struct device *dev,
error = sysfs_create_group(&dev->kobj, groups[i]);
if (error) {
while (--i >= 0)
- sysfs_remove_group(&dev->kobj, groups[i]);
+ sysfs_remove_group(&dev->kobj,
+ groups[i]);
break;
}
}
@@ -406,14 +407,12 @@ static struct device_attribute devt_attr =
/* kset to create /sys/devices/ */
struct kset *devices_kset;

-
/**
- * device_create_file - create sysfs attribute file for device.
- * @dev: device.
- * @attr: device attribute descriptor.
+ * device_create_file - create sysfs attribute file for device.
+ * @dev: device.
+ * @attr: device attribute descriptor.
*/
-
-int device_create_file(struct device * dev, struct device_attribute * attr)
+int device_create_file(struct device *dev, struct device_attribute *attr)
{
int error = 0;
if (get_device(dev)) {
@@ -424,12 +423,11 @@ int device_create_file(struct device * dev, struct device_attribute * attr)
}

/**
- * device_remove_file - remove sysfs attribute file.
- * @dev: device.
- * @attr: device attribute descriptor.
+ * device_remove_file - remove sysfs attribute file.
+ * @dev: device.
+ * @attr: device attribute descriptor.
*/
-
-void device_remove_file(struct device * dev, struct device_attribute * attr)
+void device_remove_file(struct device *dev, struct device_attribute *attr)
{
if (get_device(dev)) {
sysfs_remove_file(&dev->kobj, &attr->attr);
@@ -510,18 +508,16 @@ static void klist_children_put(struct klist_node *n)
put_device(dev);
}

-
/**
- * device_initialize - init device structure.
- * @dev: device.
+ * device_initialize - init device structure.
+ * @dev: device.
*
- * This prepares the device for use by other layers,
- * including adding it to the device hierarchy.
- * It is the first half of device_register(), if called by
- * that, though it can also be called separately, so one
- * may use @dev's fields (e.g. the refcount).
+ * This prepares the device for use by other layers,
+ * including adding it to the device hierarchy.
+ * It is the first half of device_register(), if called by
+ * that, though it can also be called separately, so one
+ * may use @dev's fields (e.g. the refcount).
*/
-
void device_initialize(struct device *dev)
{
dev->kobj.kset = devices_kset;
@@ -754,15 +750,15 @@ static void device_remove_class_symlinks(struct device *dev)
}

/**
- * device_add - add device to device hierarchy.
- * @dev: device.
+ * device_add - add device to device hierarchy.
+ * @dev: device.
*
- * This is part 2 of device_register(), though may be called
- * separately _iff_ device_initialize() has been called separately.
+ * This is part 2 of device_register(), though may be called
+ * separately _iff_ device_initialize() has been called separately.
*
- * This adds it to the kobject hierarchy via kobject_add(), adds it
- * to the global and sibling lists for the device, then
- * adds it to the other relevant subsystems of the driver model.
+ * This adds it to the kobject hierarchy via kobject_add(), adds it
+ * to the global and sibling lists for the device, then
+ * adds it to the other relevant subsystems of the driver model.
*/
int device_add(struct device *dev)
{
@@ -870,70 +866,63 @@ int device_add(struct device *dev)
goto Done;
}

-
/**
- * device_register - register a device with the system.
- * @dev: pointer to the device structure
+ * device_register - register a device with the system.
+ * @dev: pointer to the device structure
*
- * This happens in two clean steps - initialize the device
- * and add it to the system. The two steps can be called
- * separately, but this is the easiest and most common.
- * I.e. you should only call the two helpers separately if
- * have a clearly defined need to use and refcount the device
- * before it is added to the hierarchy.
+ * This happens in two clean steps - initialize the device
+ * and add it to the system. The two steps can be called
+ * separately, but this is the easiest and most common.
+ * I.e. you should only call the two helpers separately if
+ * have a clearly defined need to use and refcount the device
+ * before it is added to the hierarchy.
*/
-
int device_register(struct device *dev)
{
device_initialize(dev);
return device_add(dev);
}

-
/**
- * get_device - increment reference count for device.
- * @dev: device.
+ * get_device - increment reference count for device.
+ * @dev: device.
*
- * This simply forwards the call to kobject_get(), though
- * we do take care to provide for the case that we get a NULL
- * pointer passed in.
+ * This simply forwards the call to kobject_get(), though
+ * we do take care to provide for the case that we get a NULL
+ * pointer passed in.
*/
-
-struct device * get_device(struct device * dev)
+struct device *get_device(struct device *dev)
{
return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
}

-
/**
- * put_device - decrement reference count.
- * @dev: device in question.
+ * put_device - decrement reference count.
+ * @dev: device in question.
*/
-void put_device(struct device * dev)
+void put_device(struct device *dev)
{
/* might_sleep(); */
if (dev)
kobject_put(&dev->kobj);
}

-
/**
- * device_del - delete device from system.
- * @dev: device.
+ * device_del - delete device from system.
+ * @dev: device.
*
- * This is the first part of the device unregistration
- * sequence. This removes the device from the lists we control
- * from here, has it removed from the other driver model
- * subsystems it was added to in device_add(), and removes it
- * from the kobject hierarchy.
+ * This is the first part of the device unregistration
+ * sequence. This removes the device from the lists we control
+ * from here, has it removed from the other driver model
+ * subsystems it was added to in device_add(), and removes it
+ * from the kobject hierarchy.
*
- * NOTE: this should be called manually _iff_ device_add() was
- * also called manually.
+ * NOTE: this should be called manually _iff_ device_add() was
+ * also called manually.
*/
-
-void device_del(struct device * dev)
+void device_del(struct device *dev)
{
- struct device * parent = dev->parent;
+ struct device *parent = dev->parent;
struct class_interface *class_intf;

device_pm_remove(dev);
@@ -979,47 +968,46 @@ void device_del(struct device * dev)
}

/**
- * device_unregister - unregister device from system.
- * @dev: device going away.
+ * device_unregister - unregister device from system.
+ * @dev: device going away.
*
- * We do this in two parts, like we do device_register(). First,
- * we remove it from all the subsystems with device_del(), then
- * we decrement the reference count via put_device(). If that
- * is the final reference count, the device will be cleaned up
- * via device_release() above. Otherwise, the structure will
- * stick around until the final reference to the device is dropped.
+ * We do this in two parts, like we do device_register(). First,
+ * we remove it from all the subsystems with device_del(), then
+ * we decrement the reference count via put_device(). If that
+ * is the final reference count, the device will be cleaned up
+ * via device_release() above. Otherwise, the structure will
+ * stick around until the final reference to the device is dropped.
*/
-void device_unregister(struct device * dev)
+void device_unregister(struct device *dev)
{
pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
device_del(dev);
put_device(dev);
}

-
-static struct device * next_device(struct klist_iter * i)
+static struct device *next_device(struct klist_iter *i)
{
- struct klist_node * n = klist_next(i);
+ struct klist_node *n = klist_next(i);
return n ? container_of(n, struct device, knode_parent) : NULL;
}

/**
- * device_for_each_child - device child iterator.
- * @parent: parent struct device.
- * @data: data for the callback.
- * @fn: function to be called for each device.
+ * device_for_each_child - device child iterator.
+ * @parent: parent struct device.
+ * @data: data for the callback.
+ * @fn: function to be called for each device.
*
- * Iterate over @parent's child devices, and call @fn for each,
- * passing it @data.
+ * Iterate over @parent's child devices, and call @fn for each,
+ * passing it @data.
*
- * We check the return of @fn each time. If it returns anything
- * other than 0, we break out and return that value.
+ * We check the return of @fn each time. If it returns anything
+ * other than 0, we break out and return that value.
*/
-int device_for_each_child(struct device * parent, void * data,
- int (*fn)(struct device *, void *))
+int device_for_each_child(struct device *parent, void *data,
+ int (*fn)(struct device *dev, void *data))
{
struct klist_iter i;
- struct device * child;
+ struct device *child;
int error = 0;

klist_iter_init(&parent->klist_children, &i);
@@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data,
* current device can be obtained, this function will return to the caller
* and not iterate over any more devices.
*/
-struct device * device_find_child(struct device *parent, void *data,
- int (*match)(struct device *, void *))
+struct device *device_find_child(struct device *parent, void *data,
+ int (*match)(struct device *dev, void *data))
{
struct klist_iter i;
struct device *child;
@@ -1312,8 +1300,7 @@ static int device_move_class_links(struct device *dev,
class_name);
if (error)
sysfs_remove_link(&dev->kobj, "device");
- }
- else
+ } else
error = 0;
out:
kfree(class_name);
@@ -1344,7 +1331,7 @@ int device_move(struct device *dev, struct device *new_parent)
return -EINVAL;

new_parent = get_device(new_parent);
- new_parent_kobj = get_device_parent (dev, new_parent);
+ new_parent_kobj = get_device_parent(dev, new_parent);

pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
__FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
@@ -1390,7 +1377,7 @@ EXPORT_SYMBOL_GPL(device_move);
*/
void device_shutdown(void)
{
- struct device * dev, *devn;
+ struct device *dev, *devn;

list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
kobj.entry) {
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index b0726eb..a5cde94 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1,20 +1,20 @@
/*
- * drivers/base/dd.c - The core device/driver interactions.
+ * drivers/base/dd.c - The core device/driver interactions.
*
- * This file contains the (sometimes tricky) code that controls the
- * interactions between devices and drivers, which primarily includes
- * driver binding and unbinding.
+ * This file contains the (sometimes tricky) code that controls the
+ * interactions between devices and drivers, which primarily includes
+ * driver binding and unbinding.
*
- * All of this code used to exist in drivers/base/bus.c, but was
- * relocated to here in the name of compartmentalization (since it wasn't
- * strictly code just for the 'struct bus_type'.
+ * All of this code used to exist in drivers/base/bus.c, but was
+ * relocated to here in the name of compartmentalization (since it wasn't
+ * strictly code just for the 'struct bus_type'.
*
- * Copyright (c) 2002-5 Patrick Mochel
- * Copyright (c) 2002-3 Open Source Development Labs
- * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
- * Copyright (c) 2007 Novell Inc.
+ * Copyright (c) 2002-5 Patrick Mochel
+ * Copyright (c) 2002-3 Open Source Development Labs
+ * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2007 Novell Inc.
*
- * This file is released under the GPLv2
+ * This file is released under the GPLv2
*/

#include <linux/device.h>
@@ -71,18 +71,18 @@ static void driver_sysfs_remove(struct device *dev)
}

/**
- * device_bind_driver - bind a driver to one device.
- * @dev: device.
+ * device_bind_driver - bind a driver to one device.
+ * @dev: device.
*
- * Allow manual attachment of a driver to a device.
- * Caller must have already set @dev->driver.
+ * Allow manual attachment of a driver to a device.
+ * Caller must have already set @dev->driver.
*
- * Note that this does not modify the bus reference count
- * nor take the bus's rwsem. Please verify those are accounted
- * for before calling this. (It is ok to call with no other effort
- * from a driver's probe() method.)
+ * Note that this does not modify the bus reference count
+ * nor take the bus's rwsem. Please verify those are accounted
+ * for before calling this. (It is ok to call with no other effort
+ * from a driver's probe() method.)
*
- * This function must be called with @dev->sem held.
+ * This function must be called with @dev->sem held.
*/
int device_bind_driver(struct device *dev)
{
@@ -93,6 +93,7 @@ int device_bind_driver(struct device *dev)
driver_bound(dev);
return ret;
}
+EXPORT_SYMBOL_GPL(device_bind_driver);

static atomic_t probe_count = ATOMIC_INIT(0);
static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
@@ -183,7 +184,7 @@ int driver_probe_done(void)
* This function must be called with @dev->sem held. When called for a
* USB interface, @dev->parent->sem must be held as well.
*/
-int driver_probe_device(struct device_driver * drv, struct device * dev)
+int driver_probe_device(struct device_driver *drv, struct device *dev)
{
int ret = 0;

@@ -201,27 +202,27 @@ done:
return ret;
}

-static int __device_attach(struct device_driver * drv, void * data)
+static int __device_attach(struct device_driver *drv, void *data)
{
- struct device * dev = data;
+ struct device *dev = data;
return driver_probe_device(drv, dev);
}

/**
- * device_attach - try to attach device to a driver.
- * @dev: device.
+ * device_attach - try to attach device to a driver.
+ * @dev: device.
*
- * Walk the list of drivers that the bus has and call
- * driver_probe_device() for each pair. If a compatible
- * pair is found, break out and return.
+ * Walk the list of drivers that the bus has and call
+ * driver_probe_device() for each pair. If a compatible
+ * pair is found, break out and return.
*
- * Returns 1 if the device was bound to a driver;
- * 0 if no matching device was found;
- * -ENODEV if the device is not registered.
+ * Returns 1 if the device was bound to a driver;
+ * 0 if no matching device was found;
+ * -ENODEV if the device is not registered.
*
- * When called for a USB interface, @dev->parent->sem must be held.
+ * When called for a USB interface, @dev->parent->sem must be held.
*/
-int device_attach(struct device * dev)
+int device_attach(struct device *dev)
{
int ret = 0;

@@ -240,10 +241,11 @@ int device_attach(struct device * dev)
up(&dev->sem);
return ret;
}
+EXPORT_SYMBOL_GPL(device_attach);

-static int __driver_attach(struct device * dev, void * data)
+static int __driver_attach(struct device *dev, void *data)
{
- struct device_driver * drv = data;
+ struct device_driver *drv = data;

/*
* Lock device and try to bind to it. We drop the error
@@ -268,26 +270,27 @@ static int __driver_attach(struct device * dev, void * data)
}

/**
- * driver_attach - try to bind driver to devices.
- * @drv: driver.
+ * driver_attach - try to bind driver to devices.
+ * @drv: driver.
*
- * Walk the list of devices that the bus has on it and try to
- * match the driver with each one. If driver_probe_device()
- * returns 0 and the @dev->driver is set, we've found a
- * compatible pair.
+ * Walk the list of devices that the bus has on it and try to
+ * match the driver with each one. If driver_probe_device()
+ * returns 0 and the @dev->driver is set, we've found a
+ * compatible pair.
*/
-int driver_attach(struct device_driver * drv)
+int driver_attach(struct device_driver *drv)
{
return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach);
}
+EXPORT_SYMBOL_GPL(driver_attach);

/*
- * __device_release_driver() must be called with @dev->sem held.
- * When called for a USB interface, @dev->parent->sem must be held as well.
+ * __device_release_driver() must be called with @dev->sem held.
+ * When called for a USB interface, @dev->parent->sem must be held as well.
*/
-static void __device_release_driver(struct device * dev)
+static void __device_release_driver(struct device *dev)
{
- struct device_driver * drv;
+ struct device_driver *drv;

drv = dev->driver;
if (drv) {
@@ -310,13 +313,13 @@ static void __device_release_driver(struct device * dev)
}

/**
- * device_release_driver - manually detach device from driver.
- * @dev: device.
+ * device_release_driver - manually detach device from driver.
+ * @dev: device.
*
- * Manually detach device from driver.
- * When called for a USB interface, @dev->parent->sem must be held.
+ * Manually detach device from driver.
+ * When called for a USB interface, @dev->parent->sem must be held.
*/
-void device_release_driver(struct device * dev)
+void device_release_driver(struct device *dev)
{
/*
* If anyone calls device_release_driver() recursively from
@@ -327,15 +330,15 @@ void device_release_driver(struct device * dev)
__device_release_driver(dev);
up(&dev->sem);
}
-
+EXPORT_SYMBOL_GPL(device_release_driver);

/**
* driver_detach - detach driver from all devices it controls.
* @drv: driver.
*/
-void driver_detach(struct device_driver * drv)
+void driver_detach(struct device_driver *drv)
{
- struct device * dev;
+ struct device *dev;

for (;;) {
spin_lock(&drv->p->klist_devices.k_lock);
@@ -359,9 +362,3 @@ void driver_detach(struct device_driver * drv)
put_device(dev);
}
}
-
-EXPORT_SYMBOL_GPL(device_bind_driver);
-EXPORT_SYMBOL_GPL(device_release_driver);
-EXPORT_SYMBOL_GPL(device_attach);
-EXPORT_SYMBOL_GPL(driver_attach);
-
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 94b697a..a35f041 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -19,27 +19,26 @@
#define to_dev(node) container_of(node, struct device, driver_list)


-static struct device * next_device(struct klist_iter * i)
+static struct device *next_device(struct klist_iter *i)
{
- struct klist_node * n = klist_next(i);
+ struct klist_node *n = klist_next(i);
return n ? container_of(n, struct device, knode_driver) : NULL;
}

/**
- * driver_for_each_device - Iterator for devices bound to a driver.
- * @drv: Driver we're iterating.
- * @start: Device to begin with
- * @data: Data to pass to the callback.
- * @fn: Function to call for each device.
+ * driver_for_each_device - Iterator for devices bound to a driver.
+ * @drv: Driver we're iterating.
+ * @start: Device to begin with
+ * @data: Data to pass to the callback.
+ * @fn: Function to call for each device.
*
- * Iterate over the @drv's list of devices calling @fn for each one.
+ * Iterate over the @drv's list of devices calling @fn for each one.
*/
-
-int driver_for_each_device(struct device_driver * drv, struct device * start,
- void * data, int (*fn)(struct device *, void *))
+int driver_for_each_device(struct device_driver *drv, struct device *start,
+ void *data, int (*fn)(struct device *, void *))
{
struct klist_iter i;
- struct device * dev;
+ struct device *dev;
int error = 0;

if (!drv)
@@ -52,10 +51,8 @@ int driver_for_each_device(struct device_driver * drv, struct device * start,
klist_iter_exit(&i);
return error;
}
-
EXPORT_SYMBOL_GPL(driver_for_each_device);

-
/**
* driver_find_device - device iterator for locating a particular device.
* @drv: The device's driver
@@ -71,9 +68,9 @@ EXPORT_SYMBOL_GPL(driver_for_each_device);
* if it does. If the callback returns non-zero, this function will
* return to the caller and not iterate over any more devices.
*/
-struct device * driver_find_device(struct device_driver *drv,
- struct device * start, void * data,
- int (*match)(struct device *, void *))
+struct device *driver_find_device(struct device_driver *drv,
+ struct device *start, void *data,
+ int (*match)(struct device *dev, void *data))
{
struct klist_iter i;
struct device *dev;
@@ -92,12 +89,12 @@ struct device * driver_find_device(struct device_driver *drv,
EXPORT_SYMBOL_GPL(driver_find_device);

/**
- * driver_create_file - create sysfs file for driver.
- * @drv: driver.
- * @attr: driver attribute descriptor.
+ * driver_create_file - create sysfs file for driver.
+ * @drv: driver.
+ * @attr: driver attribute descriptor.
*/
-
-int driver_create_file(struct device_driver * drv, struct driver_attribute * attr)
+int driver_create_file(struct device_driver *drv,
+ struct driver_attribute *attr)
{
int error;
if (get_driver(drv)) {
@@ -107,22 +104,22 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att
error = -EINVAL;
return error;
}
-
+EXPORT_SYMBOL_GPL(driver_create_file);

/**
- * driver_remove_file - remove sysfs file for driver.
- * @drv: driver.
- * @attr: driver attribute descriptor.
+ * driver_remove_file - remove sysfs file for driver.
+ * @drv: driver.
+ * @attr: driver attribute descriptor.
*/
-
-void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr)
+void driver_remove_file(struct device_driver *drv,
+ struct driver_attribute *attr)
{
if (get_driver(drv)) {
sysfs_remove_file(&drv->p->kobj, &attr->attr);
put_driver(drv);
}
}
-
+EXPORT_SYMBOL_GPL(driver_remove_file);

/**
* driver_add_kobj - add a kobject below the specified driver
@@ -149,10 +146,10 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
EXPORT_SYMBOL_GPL(driver_add_kobj);

/**
- * get_driver - increment driver reference count.
- * @drv: driver.
+ * get_driver - increment driver reference count.
+ * @drv: driver.
*/
-struct device_driver * get_driver(struct device_driver * drv)
+struct device_driver *get_driver(struct device_driver *drv)
{
if (drv) {
struct driver_private *priv;
@@ -164,16 +161,17 @@ struct device_driver * get_driver(struct device_driver * drv)
}
return NULL;
}
-
+EXPORT_SYMBOL_GPL(get_driver);

/**
- * put_driver - decrement driver's refcount.
- * @drv: driver.
+ * put_driver - decrement driver's refcount.
+ * @drv: driver.
*/
-void put_driver(struct device_driver * drv)
+void put_driver(struct device_driver *drv)
{
kobject_put(&drv->p->kobj);
}
+EXPORT_SYMBOL_GPL(put_driver);

static int driver_add_groups(struct device_driver *drv,
struct attribute_group **groups)
@@ -205,24 +203,23 @@ static void driver_remove_groups(struct device_driver *drv,
sysfs_remove_group(&drv->p->kobj, groups[i]);
}

-
/**
- * driver_register - register driver with bus
- * @drv: driver to register
+ * driver_register - register driver with bus
+ * @drv: driver to register
*
- * We pass off most of the work to the bus_add_driver() call,
- * since most of the things we have to do deal with the bus
- * structures.
+ * We pass off most of the work to the bus_add_driver() call,
+ * since most of the things we have to do deal with the bus
+ * structures.
*/
-int driver_register(struct device_driver * drv)
+int driver_register(struct device_driver *drv)
{
int ret;

if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
- (drv->bus->shutdown && drv->shutdown)) {
- printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
- }
+ (drv->bus->shutdown && drv->shutdown))
+ printk(KERN_WARNING "Driver '%s' needs updating - please use "
+ "bus_type methods\n", drv->name);
ret = bus_add_driver(drv);
if (ret)
return ret;
@@ -231,29 +228,30 @@ int driver_register(struct device_driver * drv)
bus_remove_driver(drv);
return ret;
}
+EXPORT_SYMBOL_GPL(driver_register);

/**
- * driver_unregister - remove driver from system.
- * @drv: driver.
+ * driver_unregister - remove driver from system.
+ * @drv: driver.
*
- * Again, we pass off most of the work to the bus-level call.
+ * Again, we pass off most of the work to the bus-level call.
*/
-
-void driver_unregister(struct device_driver * drv)
+void driver_unregister(struct device_driver *drv)
{
driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}
+EXPORT_SYMBOL_GPL(driver_unregister);

/**
- * driver_find - locate driver on a bus by its name.
- * @name: name of the driver.
- * @bus: bus to scan for the driver.
+ * driver_find - locate driver on a bus by its name.
+ * @name: name of the driver.
+ * @bus: bus to scan for the driver.
*
- * Call kset_find_obj() to iterate over list of drivers on
- * a bus to find driver by name. Return driver if found.
+ * Call kset_find_obj() to iterate over list of drivers on
+ * a bus to find driver by name. Return driver if found.
*
- * Note that kset_find_obj increments driver's reference count.
+ * Note that kset_find_obj increments driver's reference count.
*/
struct device_driver *driver_find(const char *name, struct bus_type *bus)
{
@@ -266,12 +264,4 @@ struct device_driver *driver_find(const char *name, struct bus_type *bus)
}
return NULL;
}
-
-EXPORT_SYMBOL_GPL(driver_register);
-EXPORT_SYMBOL_GPL(driver_unregister);
-EXPORT_SYMBOL_GPL(get_driver);
-EXPORT_SYMBOL_GPL(put_driver);
EXPORT_SYMBOL_GPL(driver_find);
-
-EXPORT_SYMBOL_GPL(driver_create_file);
-EXPORT_SYMBOL_GPL(driver_remove_file);
diff --git a/drivers/base/init.c b/drivers/base/init.c
index 1da88a1..7bd9b6a 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -1,10 +1,8 @@
/*
- *
* Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
*
* This file is released under the GPLv2
- *
*/

#include <linux/device.h>
@@ -14,12 +12,11 @@
#include "base.h"

/**
- * driver_init - initialize driver model.
+ * driver_init - initialize driver model.
*
- * Call the driver model init functions to initialize their
- * subsystems. Called early from init/main.c.
+ * Call the driver model init functions to initialize their
+ * subsystems. Called early from init/main.c.
*/
-
void __init driver_init(void)
{
/* These are the core pieces */
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 48d5db4..efaf282 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -20,7 +20,8 @@

#include "base.h"

-#define to_platform_driver(drv) (container_of((drv), struct platform_driver, driver))
+#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
+ driver))

struct device platform_bus = {
.bus_id = "platform",
@@ -28,14 +29,13 @@ struct device platform_bus = {
EXPORT_SYMBOL_GPL(platform_bus);

/**
- * platform_get_resource - get a resource for a device
- * @dev: platform device
- * @type: resource type
- * @num: resource index
+ * platform_get_resource - get a resource for a device
+ * @dev: platform device
+ * @type: resource type
+ * @num: resource index
*/
-struct resource *
-platform_get_resource(struct platform_device *dev, unsigned int type,
- unsigned int num)
+struct resource *platform_get_resource(struct platform_device *dev,
+ unsigned int type, unsigned int num)
{
int i;

@@ -43,8 +43,7 @@ platform_get_resource(struct platform_device *dev, unsigned int type,
struct resource *r = &dev->resource[i];

if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM|
- IORESOURCE_IRQ|IORESOURCE_DMA))
- == type)
+ IORESOURCE_IRQ|IORESOURCE_DMA)) == type)
if (num-- == 0)
return r;
}
@@ -53,9 +52,9 @@ platform_get_resource(struct platform_device *dev, unsigned int type,
EXPORT_SYMBOL_GPL(platform_get_resource);

/**
- * platform_get_irq - get an IRQ for a device
- * @dev: platform device
- * @num: IRQ number index
+ * platform_get_irq - get an IRQ for a device
+ * @dev: platform device
+ * @num: IRQ number index
*/
int platform_get_irq(struct platform_device *dev, unsigned int num)
{
@@ -66,14 +65,13 @@ int platform_get_irq(struct platform_device *dev, unsigned int num)
EXPORT_SYMBOL_GPL(platform_get_irq);

/**
- * platform_get_resource_byname - get a resource for a device by name
- * @dev: platform device
- * @type: resource type
- * @name: resource name
+ * platform_get_resource_byname - get a resource for a device by name
+ * @dev: platform device
+ * @type: resource type
+ * @name: resource name
*/
-struct resource *
-platform_get_resource_byname(struct platform_device *dev, unsigned int type,
- char *name)
+struct resource *platform_get_resource_byname(struct platform_device *dev,
+ unsigned int type, char *name)
{
int i;

@@ -90,22 +88,23 @@ platform_get_resource_byname(struct platform_device *dev, unsigned int type,
EXPORT_SYMBOL_GPL(platform_get_resource_byname);

/**
- * platform_get_irq - get an IRQ for a device
- * @dev: platform device
- * @name: IRQ name
+ * platform_get_irq - get an IRQ for a device
+ * @dev: platform device
+ * @name: IRQ name
*/
int platform_get_irq_byname(struct platform_device *dev, char *name)
{
- struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
+ struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ,
+ name);

return r ? r->start : -ENXIO;
}
EXPORT_SYMBOL_GPL(platform_get_irq_byname);

/**
- * platform_add_devices - add a numbers of platform devices
- * @devs: array of platform devices to add
- * @num: number of platform devices in array
+ * platform_add_devices - add a numbers of platform devices
+ * @devs: array of platform devices to add
+ * @num: number of platform devices in array
*/
int platform_add_devices(struct platform_device **devs, int num)
{
@@ -130,12 +129,11 @@ struct platform_object {
};

/**
- * platform_device_put
- * @pdev: platform device to free
+ * platform_device_put
+ * @pdev: platform device to free
*
- * Free all memory associated with a platform device. This function
- * must _only_ be externally called in error cases. All other usage
- * is a bug.
+ * Free all memory associated with a platform device. This function must
+ * _only_ be externally called in error cases. All other usage is a bug.
*/
void platform_device_put(struct platform_device *pdev)
{
@@ -146,7 +144,8 @@ EXPORT_SYMBOL_GPL(platform_device_put);

static void platform_device_release(struct device *dev)
{
- struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev);
+ struct platform_object *pa = container_of(dev, struct platform_object,
+ pdev.dev);

kfree(pa->pdev.dev.platform_data);
kfree(pa->pdev.resource);
@@ -154,12 +153,12 @@ static void platform_device_release(struct device *dev)
}

/**
- * platform_device_alloc
- * @name: base name of the device we're adding
- * @id: instance id
+ * platform_device_alloc
+ * @name: base name of the device we're adding
+ * @id: instance id
*
- * Create a platform device object which can have other objects attached
- * to it, and which will have attached objects freed when it is released.
+ * Create a platform device object which can have other objects attached
+ * to it, and which will have attached objects freed when it is released.
*/
struct platform_device *platform_device_alloc(const char *name, int id)
{
@@ -179,16 +178,17 @@ struct platform_device *platform_device_alloc(const char *name, int id)
EXPORT_SYMBOL_GPL(platform_device_alloc);

/**
- * platform_device_add_resources
- * @pdev: platform device allocated by platform_device_alloc to add resources to
- * @res: set of resources that needs to be allocated for the device
- * @num: number of resources
+ * platform_device_add_resources
+ * @pdev: platform device allocated by platform_device_alloc to add resources to
+ * @res: set of resources that needs to be allocated for the device
+ * @num: number of resources
*
- * Add a copy of the resources to the platform device. The memory
- * associated with the resources will be freed when the platform
- * device is released.
+ * Add a copy of the resources to the platform device. The memory
+ * associated with the resources will be freed when the platform device is
+ * released.
*/
-int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num)
+int platform_device_add_resources(struct platform_device *pdev,
+ struct resource *res, unsigned int num)
{
struct resource *r;

@@ -203,16 +203,17 @@ int platform_device_add_resources(struct platform_device *pdev, struct resource
EXPORT_SYMBOL_GPL(platform_device_add_resources);

/**
- * platform_device_add_data
- * @pdev: platform device allocated by platform_device_alloc to add resources to
- * @data: platform specific data for this platform device
- * @size: size of platform specific data
+ * platform_device_add_data
+ * @pdev: platform device allocated by platform_device_alloc to add resources to
+ * @data: platform specific data for this platform device
+ * @size: size of platform specific data
*
- * Add a copy of platform specific data to the platform device's platform_data
- * pointer. The memory associated with the platform data will be freed
- * when the platform device is released.
+ * Add a copy of platform specific data to the platform device's
+ * platform_data pointer. The memory associated with the platform data
+ * will be freed when the platform device is released.
*/
-int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size)
+int platform_device_add_data(struct platform_device *pdev, const void *data,
+ size_t size)
{
void *d;

@@ -226,11 +227,11 @@ int platform_device_add_data(struct platform_device *pdev, const void *data, siz
EXPORT_SYMBOL_GPL(platform_device_add_data);

/**
- * platform_device_add - add a platform device to device hierarchy
- * @pdev: platform device we're adding
+ * platform_device_add - add a platform device to device hierarchy
+ * @pdev: platform device we're adding
*
- * This is part 2 of platform_device_register(), though may be called
- * separately _iff_ pdev was allocated by platform_device_alloc().
+ * This is part 2 of platform_device_register(), though may be called
+ * separately _iff_ pdev was allocated by platform_device_alloc().
*/
int platform_device_add(struct platform_device *pdev)
{
@@ -289,13 +290,12 @@ int platform_device_add(struct platform_device *pdev)
EXPORT_SYMBOL_GPL(platform_device_add);

/**
- * platform_device_del - remove a platform-level device
- * @pdev: platform device we're removing
+ * platform_device_del - remove a platform-level device
+ * @pdev: platform device we're removing
*
- * Note that this function will also release all memory- and port-based
- * resources owned by the device (@dev->resource). This function
- * must _only_ be externally called in error cases. All other usage
- * is a bug.
+ * Note that this function will also release all memory- and port-based
+ * resources owned by the device (@dev->resource). This function must
+ * _only_ be externally called in error cases. All other usage is a bug.
*/
void platform_device_del(struct platform_device *pdev)
{
@@ -314,11 +314,10 @@ void platform_device_del(struct platform_device *pdev)
EXPORT_SYMBOL_GPL(platform_device_del);

/**
- * platform_device_register - add a platform-level device
- * @pdev: platform device we're adding
- *
+ * platform_device_register - add a platform-level device
+ * @pdev: platform device we're adding
*/
-int platform_device_register(struct platform_device * pdev)
+int platform_device_register(struct platform_device *pdev)
{
device_initialize(&pdev->dev);
return platform_device_add(pdev);
@@ -326,14 +325,14 @@ int platform_device_register(struct platform_device * pdev)
EXPORT_SYMBOL_GPL(platform_device_register);

/**
- * platform_device_unregister - unregister a platform-level device
- * @pdev: platform device we're unregistering
+ * platform_device_unregister - unregister a platform-level device
+ * @pdev: platform device we're unregistering
*
- * Unregistration is done in 2 steps. First we release all resources
- * and remove it from the subsystem, then we drop reference count by
- * calling platform_device_put().
+ * Unregistration is done in 2 steps. First we release all resources
+ * and remove it from the subsystem, then we drop reference count by
+ * calling platform_device_put().
*/
-void platform_device_unregister(struct platform_device * pdev)
+void platform_device_unregister(struct platform_device *pdev)
{
platform_device_del(pdev);
platform_device_put(pdev);
@@ -341,27 +340,29 @@ void platform_device_unregister(struct platform_device * pdev)
EXPORT_SYMBOL_GPL(platform_device_unregister);

/**
- * platform_device_register_simple
- * @name: base name of the device we're adding
- * @id: instance id
- * @res: set of resources that needs to be allocated for the device
- * @num: number of resources
+ * platform_device_register_simple
+ * @name: base name of the device we're adding
+ * @id: instance id
+ * @res: set of resources that needs to be allocated for the device
+ * @num: number of resources
*
- * This function creates a simple platform device that requires minimal
- * resource and memory management. Canned release function freeing
- * memory allocated for the device allows drivers using such devices
- * to be unloaded without waiting for the last reference to the device
- * to be dropped.
+ * This function creates a simple platform device that requires minimal
+ * resource and memory management. Canned release function freeing memory
+ * allocated for the device allows drivers using such devices to be
+ * unloaded without waiting for the last reference to the device to be
+ * dropped.
*
- * This interface is primarily intended for use with legacy drivers
- * which probe hardware directly. Because such drivers create sysfs
- * device nodes themselves, rather than letting system infrastructure
- * handle such device enumeration tasks, they don't fully conform to
- * the Linux driver model. In particular, when such drivers are built
- * as modules, they can't be "hotplugged".
+ * This interface is primarily intended for use with legacy drivers which
+ * probe hardware directly. Because such drivers create sysfs device nodes
+ * themselves, rather than letting system infrastructure handle such device
+ * enumeration tasks, they don't fully conform to the Linux driver model.
+ * In particular, when such drivers are built as modules, they can't be
+ * "hotplugged".
*/
-struct platform_device *platform_device_register_simple(const char *name, int id,
- struct resource *res, unsigned int num)
+struct platform_device *platform_device_register_simple(const char *name,
+ int id,
+ struct resource *res,
+ unsigned int num)
{
struct platform_device *pdev;
int retval;
@@ -436,8 +437,8 @@ static int platform_drv_resume(struct device *_dev)
}

/**
- * platform_driver_register
- * @drv: platform driver structure
+ * platform_driver_register
+ * @drv: platform driver structure
*/
int platform_driver_register(struct platform_driver *drv)
{
@@ -457,8 +458,8 @@ int platform_driver_register(struct platform_driver *drv)
EXPORT_SYMBOL_GPL(platform_driver_register);

/**
- * platform_driver_unregister
- * @drv: platform driver structure
+ * platform_driver_unregister
+ * @drv: platform driver structure
*/
void platform_driver_unregister(struct platform_driver *drv)
{
@@ -516,8 +517,8 @@ EXPORT_SYMBOL_GPL(platform_driver_probe);
* (b) sysfs attribute lets new-style coldplug recover from hotplug events
* mishandled before system is fully running: "modprobe $(cat modalias)"
*/
-static ssize_t
-modalias_show(struct device *dev, struct device_attribute *a, char *buf)
+static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
+ char *buf)
{
struct platform_device *pdev = to_platform_device(dev);
int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
@@ -538,26 +539,24 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
return 0;
}

-
/**
- * platform_match - bind platform device to platform driver.
- * @dev: device.
- * @drv: driver.
+ * platform_match - bind platform device to platform driver.
+ * @dev: device.
+ * @drv: driver.
*
- * Platform device IDs are assumed to be encoded like this:
- * "<name><instance>", where <name> is a short description of the
- * type of device, like "pci" or "floppy", and <instance> is the
- * enumerated instance of the device, like '0' or '42'.
- * Driver IDs are simply "<name>".
- * So, extract the <name> from the platform_device structure,
- * and compare it against the name of the driver. Return whether
- * they match or not.
+ * Platform device IDs are assumed to be encoded like this:
+ * "<name><instance>", where <name> is a short description of the type of
+ * device, like "pci" or "floppy", and <instance> is the enumerated
+ * instance of the device, like '0' or '42'. Driver IDs are simply
+ * "<name>". So, extract the <name> from the platform_device structure,
+ * and compare it against the name of the driver. Return whether they match
+ * or not.
*/
-
-static int platform_match(struct device * dev, struct device_driver * drv)
+static int platform_match(struct device *dev, struct device_driver *drv)
{
- struct platform_device *pdev = container_of(dev, struct platform_device, dev);
+ struct platform_device *pdev;

+ pdev = container_of(dev, struct platform_device, dev);
return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);
}

@@ -574,9 +573,10 @@ static int platform_suspend(struct device *dev, pm_message_t mesg)
static int platform_suspend_late(struct device *dev, pm_message_t mesg)
{
struct platform_driver *drv = to_platform_driver(dev->driver);
- struct platform_device *pdev = container_of(dev, struct platform_device, dev);
+ struct platform_device *pdev;
int ret = 0;

+ pdev = container_of(dev, struct platform_device, dev);
if (dev->driver && drv->suspend_late)
ret = drv->suspend_late(pdev, mesg);

@@ -586,16 +586,17 @@ static int platform_suspend_late(struct device *dev, pm_message_t mesg)
static int platform_resume_early(struct device *dev)
{
struct platform_driver *drv = to_platform_driver(dev->driver);
- struct platform_device *pdev = container_of(dev, struct platform_device, dev);
+ struct platform_device *pdev;
int ret = 0;

+ pdev = container_of(dev, struct platform_device, dev);
if (dev->driver && drv->resume_early)
ret = drv->resume_early(pdev);

return ret;
}

-static int platform_resume(struct device * dev)
+static int platform_resume(struct device *dev)
{
int ret = 0;

--
1.5.3.8

2008-01-25 08:14:37

by Greg KH

[permalink] [raw]
Subject: [PATCH 118/196] Kobject: change arch/x86/kernel/cpu/intel_cacheinfo.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Ashok Raj <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/x86/kernel/cpu/intel_cacheinfo.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 9f530ff..3509542 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -733,10 +733,8 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
if (unlikely(retval < 0))
return retval;

- cache_kobject[cpu]->parent = &sys_dev->kobj;
- kobject_set_name(cache_kobject[cpu], "%s", "cache");
- cache_kobject[cpu]->ktype = &ktype_percpu_entry;
- retval = kobject_register(cache_kobject[cpu]);
+ retval = kobject_init_and_add(cache_kobject[cpu], &ktype_percpu_entry,
+ &sys_dev->kobj, "%s", "cache");
if (retval < 0) {
cpuid4_cache_sysfs_exit(cpu);
return retval;
@@ -746,10 +744,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
this_object = INDEX_KOBJECT_PTR(cpu,i);
this_object->cpu = cpu;
this_object->index = i;
- this_object->kobj.parent = cache_kobject[cpu];
- kobject_set_name(&(this_object->kobj), "index%1lu", i);
- this_object->kobj.ktype = &ktype_cache;
- retval = kobject_register(&(this_object->kobj));
+ retval = kobject_init_and_add(&(this_object->kobj),
+ &ktype_cache, cache_kobject[cpu],
+ "index%1lu", i);
if (unlikely(retval)) {
for (j = 0; j < i; j++) {
kobject_unregister(
@@ -759,10 +756,12 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
cpuid4_cache_sysfs_exit(cpu);
break;
}
+ kobject_uevent(&(this_object->kobj), KOBJ_ADD);
}
if (!retval)
cpu_set(cpu, cache_dev_map);

+ kobject_uevent(cache_kobject[cpu], KOBJ_ADD);
return retval;
}

--
1.5.3.8

2008-01-25 08:14:56

by Greg KH

[permalink] [raw]
Subject: [PATCH 171/196] Kobject: convert arch/* from kobject_unregister() to kobject_put()

There is no need for kobject_unregister() anymore, thanks to Kay's
kobject cleanup changes, so replace all instances of it with
kobject_put().


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/ia64/kernel/topology.c | 9 ++++-----
arch/s390/hypfs/inode.c | 4 ++--
arch/sh/kernel/cpu/sh4/sq.c | 2 +-
arch/x86/kernel/cpu/intel_cacheinfo.c | 9 ++++-----
arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 6 +++---
5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
index c4311e3..a2484fc 100644
--- a/arch/ia64/kernel/topology.c
+++ b/arch/ia64/kernel/topology.c
@@ -366,10 +366,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
"index%1lu", i);
if (unlikely(retval)) {
for (j = 0; j < i; j++) {
- kobject_unregister(
- &(LEAF_KOBJECT_PTR(cpu,j)->kobj));
+ kobject_put(&(LEAF_KOBJECT_PTR(cpu,j)->kobj));
}
- kobject_unregister(&all_cpu_cache_info[cpu].kobj);
+ kobject_put(&all_cpu_cache_info[cpu].kobj);
cpu_cache_sysfs_exit(cpu);
break;
}
@@ -386,10 +385,10 @@ static int __cpuinit cache_remove_dev(struct sys_device * sys_dev)
unsigned long i;

for (i = 0; i < all_cpu_cache_info[cpu].num_cache_leaves; i++)
- kobject_unregister(&(LEAF_KOBJECT_PTR(cpu,i)->kobj));
+ kobject_put(&(LEAF_KOBJECT_PTR(cpu,i)->kobj));

if (all_cpu_cache_info[cpu].kobj.parent) {
- kobject_unregister(&all_cpu_cache_info[cpu].kobj);
+ kobject_put(&all_cpu_cache_info[cpu].kobj);
memset(&all_cpu_cache_info[cpu].kobj,
0,
sizeof(struct kobject));
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index 631a610..4b010ff 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -517,7 +517,7 @@ static int __init hypfs_init(void)
return 0;

fail_filesystem:
- kobject_unregister(s390_kobj);
+ kobject_put(s390_kobj);
fail_sysfs:
if (!MACHINE_IS_VM)
hypfs_diag_exit();
@@ -531,7 +531,7 @@ static void __exit hypfs_exit(void)
if (!MACHINE_IS_VM)
hypfs_diag_exit();
unregister_filesystem(&hypfs_type);
- kobject_unregister(s390_kobj);
+ kobject_put(s390_kobj);
}

module_init(hypfs_init)
diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index 97fd9b9..3008c00 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -360,7 +360,7 @@ static int __devexit sq_sysdev_remove(struct sys_device *sysdev)
unsigned int cpu = sysdev->id;
struct kobject *kobj = sq_kobject[cpu];

- kobject_unregister(kobj);
+ kobject_put(kobj);
return 0;
}

diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 3509542..8b4507b 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -749,10 +749,9 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
"index%1lu", i);
if (unlikely(retval)) {
for (j = 0; j < i; j++) {
- kobject_unregister(
- &(INDEX_KOBJECT_PTR(cpu,j)->kobj));
+ kobject_put(&(INDEX_KOBJECT_PTR(cpu,j)->kobj));
}
- kobject_unregister(cache_kobject[cpu]);
+ kobject_put(cache_kobject[cpu]);
cpuid4_cache_sysfs_exit(cpu);
break;
}
@@ -777,8 +776,8 @@ static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
cpu_clear(cpu, cache_dev_map);

for (i = 0; i < num_cache_leaves; i++)
- kobject_unregister(&(INDEX_KOBJECT_PTR(cpu,i)->kobj));
- kobject_unregister(cache_kobject[cpu]);
+ kobject_put(&(INDEX_KOBJECT_PTR(cpu,i)->kobj));
+ kobject_put(cache_kobject[cpu]);
cpuid4_cache_sysfs_exit(cpu);
}

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
index ef15f35..7535887 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
@@ -456,7 +456,7 @@ recurse:

out_free:
if (b) {
- kobject_unregister(&b->kobj);
+ kobject_put(&b->kobj);
kfree(b);
}
return err;
@@ -581,7 +581,7 @@ static void deallocate_threshold_block(unsigned int cpu,
return;

list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) {
- kobject_unregister(&pos->kobj);
+ kobject_put(&pos->kobj);
list_del(&pos->miscj);
kfree(pos);
}
@@ -627,7 +627,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
deallocate_threshold_block(cpu, bank);

free_out:
- kobject_unregister(b->kobj);
+ kobject_put(b->kobj);
kfree(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
}
--
1.5.3.8

2008-01-25 08:15:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 137/196] driver core: remove owner field from struct bus_type

This isn't used by anything in the driver core, and by no one in the 204
different usages of it in the kernel tree. Remove this field so no one
gets any idea that it is needed to be used.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/device.h | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index a3b3ff1..313e0b3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -51,7 +51,6 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *);

struct bus_type {
const char * name;
- struct module * owner;

struct kset subsys;
struct kset *drivers_kset;
--
1.5.3.8

2008-01-25 08:15:49

by Greg KH

[permalink] [raw]
Subject: [PATCH 181/196] Driver core: use LIST_HEAD instead of call to INIT_LIST_HEAD in __init

From: Denis Cheng <[email protected]>

LIST_HEAD has been widely used, so switch to this simpler method.

Signed-off-by: Denis Cheng <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/attribute_container.c | 9 +--------
drivers/base/base.h | 1 -
drivers/base/init.c | 1 -
3 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 7370d7c..d4dfb97 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -61,7 +61,7 @@ attribute_container_classdev_to_container(struct class_device *classdev)
}
EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container);

-static struct list_head attribute_container_list;
+static LIST_HEAD(attribute_container_list);

static DEFINE_MUTEX(attribute_container_mutex);

@@ -429,10 +429,3 @@ attribute_container_find_class_device(struct attribute_container *cont,
return cdev;
}
EXPORT_SYMBOL_GPL(attribute_container_find_class_device);
-
-int __init
-attribute_container_init(void)
-{
- INIT_LIST_HEAD(&attribute_container_list);
- return 0;
-}
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 3b0f395..a74ceda 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -49,7 +49,6 @@ static inline int hypervisor_init(void) { return 0; }
extern int platform_bus_init(void);
extern int system_bus_init(void);
extern int cpu_dev_init(void);
-extern int attribute_container_init(void);

extern int bus_add_device(struct device * dev);
extern void bus_attach_device(struct device * dev);
diff --git a/drivers/base/init.c b/drivers/base/init.c
index 3713815..1da88a1 100644
--- a/drivers/base/init.c
+++ b/drivers/base/init.c
@@ -36,5 +36,4 @@ void __init driver_init(void)
system_bus_init();
cpu_dev_init();
memory_dev_init();
- attribute_container_init();
}
--
1.5.3.8

2008-01-25 08:16:08

by Greg KH

[permalink] [raw]
Subject: [PATCH 127/196] Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Jacob Shin <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
index 2d65311..ef15f35 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
@@ -432,10 +432,9 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
else
per_cpu(threshold_banks, cpu)[bank]->blocks = b;

- kobject_set_name(&b->kobj, "misc%i", block);
- b->kobj.parent = per_cpu(threshold_banks, cpu)[bank]->kobj;
- b->kobj.ktype = &threshold_ktype;
- err = kobject_register(&b->kobj);
+ err = kobject_init_and_add(&b->kobj, &threshold_ktype,
+ per_cpu(threshold_banks, cpu)[bank]->kobj,
+ "misc%i", block);
if (err)
goto out_free;
recurse:
@@ -451,6 +450,8 @@ recurse:
if (err)
goto out_free;

+ kobject_uevent(&b->kobj, KOBJ_ADD);
+
return err;

out_free:
--
1.5.3.8

2008-01-25 08:16:37

by Greg KH

[permalink] [raw]
Subject: [PATCH 130/196] Kobject: convert drivers/base/core.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index b3a931f..beb3516 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -523,8 +523,7 @@ static void klist_children_put(struct klist_node *n)
void device_initialize(struct device *dev)
{
dev->kobj.kset = devices_kset;
- dev->kobj.ktype = &device_ktype;
- kobject_init(&dev->kobj);
+ kobject_init_ng(&dev->kobj, &device_ktype);
klist_init(&dev->klist_children, klist_children_get,
klist_children_put);
INIT_LIST_HEAD(&dev->dma_pools);
@@ -729,7 +728,7 @@ static void device_remove_class_symlinks(struct device *dev)
* This is part 2 of device_register(), though may be called
* separately _iff_ device_initialize() has been called separately.
*
- * This adds it to the kobject hierarchy via kobject_add(), adds it
+ * This adds it to the kobject hierarchy via kobject_add_ng(), adds it
* to the global and sibling lists for the device, then
* adds it to the other relevant subsystems of the driver model.
*/
@@ -760,8 +759,7 @@ int device_add(struct device *dev)
goto Error;

/* first, register with generic layer. */
- kobject_set_name(&dev->kobj, "%s", dev->bus_id);
- error = kobject_add(&dev->kobj);
+ error = kobject_add_ng(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
if (error)
goto Error;

--
1.5.3.8

2008-01-25 08:16:53

by Greg KH

[permalink] [raw]
Subject: [PATCH 142/196] PCMCIA: use proper call to driver_create_file

Don't try to call the "raw" sysfs_create_file when we already have a
helper function to do this kind of work for us.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pcmcia/ds.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 5cf89a9..15c18f5 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -312,8 +312,7 @@ pcmcia_create_newid_file(struct pcmcia_driver *drv)
{
int error = 0;
if (drv->probe != NULL)
- error = sysfs_create_file(&drv->drv.kobj,
- &driver_attr_new_id.attr);
+ error = driver_create_file(&drv->drv, &driver_attr_new_id);
return error;
}

--
1.5.3.8

2008-01-25 08:17:22

by Greg KH

[permalink] [raw]
Subject: [PATCH 167/196] Kobject: remove kobject_register()

The function is no longer used by anyone in the kernel, and it prevents
the proper sending of the kobject uevent after the needed files are set
up by the caller. kobject_init_and_add() can be used in its place.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 1 -
lib/kobject.c | 18 ------------------
2 files changed, 0 insertions(+), 19 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index d9d8c36..2590847 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -96,7 +96,6 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,
extern int __must_check kobject_rename(struct kobject *, const char *new_name);
extern int __must_check kobject_move(struct kobject *, struct kobject *);

-extern int __must_check kobject_register(struct kobject *);
extern void kobject_unregister(struct kobject *);

extern struct kobject * kobject_get(struct kobject *);
diff --git a/lib/kobject.c b/lib/kobject.c
index 4cc231c..3326281 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -220,23 +220,6 @@ static int kobject_add_internal(struct kobject *kobj)
}

/**
- * kobject_register - initialize and add an object.
- * @kobj: object in question.
- */
-
-int kobject_register(struct kobject * kobj)
-{
- int error = -EINVAL;
- if (kobj) {
- kobject_init_internal(kobj);
- error = kobject_add(kobj);
- if (!error)
- kobject_uevent(kobj, KOBJ_ADD);
- }
- return error;
-}
-
-/**
* kobject_set_name_vargs - Set the name of an kobject
* @kobj: struct kobject to set the name of
* @fmt: format string used to build the name
@@ -883,7 +866,6 @@ struct kset *kset_create_and_add(const char *name,
}
EXPORT_SYMBOL_GPL(kset_create_and_add);

-EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
EXPORT_SYMBOL(kobject_put);
--
1.5.3.8

2008-01-25 08:17:49

by Greg KH

[permalink] [raw]
Subject: [PATCH 114/196] Kobject: change drivers/edac to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Acked-by: Doug Thompson <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/edac/edac_device_sysfs.c | 39 +++++++++++--------------------------
drivers/edac/edac_mc_sysfs.c | 28 ++++++++------------------
drivers/edac/edac_pci_sysfs.c | 29 +++++++--------------------
3 files changed, 29 insertions(+), 67 deletions(-)

diff --git a/drivers/edac/edac_device_sysfs.c b/drivers/edac/edac_device_sysfs.c
index 70b837f..10e5b19 100644
--- a/drivers/edac/edac_device_sysfs.c
+++ b/drivers/edac/edac_device_sysfs.c
@@ -246,16 +246,6 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)

/* Init the devices's kobject */
memset(&edac_dev->kobj, 0, sizeof(struct kobject));
- edac_dev->kobj.ktype = &ktype_device_ctrl;
-
- /* set this new device under the edac_class kobject */
- edac_dev->kobj.parent = &edac_class->kset.kobj;
-
- /* generate sysfs "..../edac/<name>" */
- debugf4("%s() set name of kobject to: %s\n", __func__, edac_dev->name);
- err = kobject_set_name(&edac_dev->kobj, "%s", edac_dev->name);
- if (err)
- goto err_out;

/* Record which module 'owns' this control structure
* and bump the ref count of the module
@@ -268,12 +258,15 @@ int edac_device_register_sysfs_main_kobj(struct edac_device_ctl_info *edac_dev)
}

/* register */
- err = kobject_register(&edac_dev->kobj);
+ err = kobject_init_and_add(&edac_dev->kobj, &ktype_device_ctrl,
+ &edac_class->kset.kobj,
+ "%s", edac_dev->name);
if (err) {
debugf1("%s()Failed to register '.../edac/%s'\n",
__func__, edac_dev->name);
goto err_kobj_reg;
}
+ kobject_uevent(&edac_dev->kobj, KOBJ_ADD);

/* At this point, to 'free' the control struct,
* edac_device_unregister_sysfs_main_kobj() must be used
@@ -533,12 +526,6 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,

/* init this block's kobject */
memset(&block->kobj, 0, sizeof(struct kobject));
- block->kobj.parent = &instance->kobj;
- block->kobj.ktype = &ktype_block_ctrl;
-
- err = kobject_set_name(&block->kobj, "%s", block->name);
- if (err)
- return err;

/* bump the main kobject's reference count for this controller
* and this instance is dependant on the main
@@ -550,7 +537,9 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
}

/* Add this block's kobject */
- err = kobject_register(&block->kobj);
+ err = kobject_init_and_add(&block->kobj, &ktype_block_ctrl,
+ &instance->kobj,
+ "%s", block->name);
if (err) {
debugf1("%s() Failed to register instance '%s'\n",
__func__, block->name);
@@ -579,6 +568,7 @@ static int edac_device_create_block(struct edac_device_ctl_info *edac_dev,
goto err_on_attrib;
}
}
+ kobject_uevent(&block->kobj, KOBJ_ADD);

return 0;

@@ -637,15 +627,8 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
/* Init the instance's kobject */
memset(&instance->kobj, 0, sizeof(struct kobject));

- /* set this new device under the edac_device main kobject */
- instance->kobj.parent = &edac_dev->kobj;
- instance->kobj.ktype = &ktype_instance_ctrl;
instance->ctl = edac_dev;

- err = kobject_set_name(&instance->kobj, "%s", instance->name);
- if (err)
- goto err_out;
-
/* bump the main kobject's reference count for this controller
* and this instance is dependant on the main
*/
@@ -655,8 +638,9 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
goto err_out;
}

- /* Formally register this instance's kobject */
- err = kobject_register(&instance->kobj);
+ /* Formally register this instance's kobject under the edac_device */
+ err = kobject_init_and_add(&instance->kobj, &ktype_instance_ctrl,
+ &edac_dev->kobj, "%s", instance->name);
if (err != 0) {
debugf2("%s() Failed to register instance '%s'\n",
__func__, instance->name);
@@ -679,6 +663,7 @@ static int edac_device_create_instance(struct edac_device_ctl_info *edac_dev,
goto err_release_instance_kobj;
}
}
+ kobject_uevent(&instance->kobj, KOBJ_ADD);

debugf4("%s() Registered instance %d '%s' kobject\n",
__func__, idx, instance->name);
diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
index 905fcd7..45b1d36 100644
--- a/drivers/edac/edac_mc_sysfs.c
+++ b/drivers/edac/edac_mc_sysfs.c
@@ -380,13 +380,6 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
/* generate ..../edac/mc/mc<id>/csrow<index> */
memset(&csrow->kobj, 0, sizeof(csrow->kobj));
csrow->mci = mci; /* include container up link */
- csrow->kobj.parent = kobj_mci;
- csrow->kobj.ktype = &ktype_csrow;
-
- /* name this instance of csrow<id> */
- err = kobject_set_name(&csrow->kobj, "csrow%d", index);
- if (err)
- goto err_out;

/* bump the mci instance's kobject's ref count */
kobj = kobject_get(&mci->edac_mci_kobj);
@@ -396,7 +389,8 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
}

/* Instanstiate the csrow object */
- err = kobject_register(&csrow->kobj);
+ err = kobject_init_and_add(&csrow->kobj, &ktype_csrow, kobj_mci,
+ "csrow%d", index);
if (err)
goto err_release_top_kobj;

@@ -416,7 +410,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
goto err_out;
}
}
-
+ kobject_uevent(&csrow->kobj, KOBJ_ADD);
return 0;

/* error unwind stack */
@@ -764,15 +758,6 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
/* Init the mci's kobject */
memset(kobj_mci, 0, sizeof(*kobj_mci));

- /* this instance become part of the mc_kset */
- kobj_mci->kset = &mc_kset;
- kobj_mci->ktype = &ktype_mci;
-
- /* set the name of the mc<id> object */
- err = kobject_set_name(kobj_mci, "mc%d", mci->mc_idx);
- if (err)
- goto fail_out;
-
/* Record which module 'owns' this control structure
* and bump the ref count of the module
*/
@@ -784,13 +769,18 @@ int edac_mc_register_sysfs_main_kobj(struct mem_ctl_info *mci)
goto fail_out;
}

+ /* this instance become part of the mc_kset */
+ kobj_mci->kset = &mc_kset;
+
/* register the mc<id> kobject to the mc_kset */
- err = kobject_register(kobj_mci);
+ err = kobject_init_and_add(kobj_mci, &ktype_mci, NULL,
+ "mc%d", mci->mc_idx);
if (err) {
debugf1("%s()Failed to register '.../edac/mc%d'\n",
__func__, mci->mc_idx);
goto kobj_reg_fail;
}
+ kobject_uevent(kobj_mci, KOBJ_ADD);

/* At this point, to 'free' the control struct,
* edac_mc_unregister_sysfs_main_kobj() must be used
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index 69f5ddd..834eaa9 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -162,14 +162,6 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)

debugf0("%s()\n", __func__);

- /* Set the parent and the instance's ktype */
- pci->kobj.parent = &edac_pci_top_main_kobj;
- pci->kobj.ktype = &ktype_pci_instance;
-
- err = kobject_set_name(&pci->kobj, "pci%d", idx);
- if (err)
- return err;
-
/* First bump the ref count on the top main kobj, which will
* track the number of PCI instances we have, and thus nest
* properly on keeping the module loaded
@@ -181,7 +173,8 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
}

/* And now register this new kobject under the main kobj */
- err = kobject_register(&pci->kobj);
+ err = kobject_init_and_add(&pci->kobj, &ktype_pci_instance,
+ &edac_pci_top_main_kobj, "pci%d", idx);
if (err != 0) {
debugf2("%s() failed to register instance pci%d\n",
__func__, idx);
@@ -189,6 +182,7 @@ static int edac_pci_create_instance_kobj(struct edac_pci_ctl_info *pci, int idx)
goto error_out;
}

+ kobject_uevent(&pci->kobj, KOBJ_ADD);
debugf1("%s() Register instance 'pci%d' kobject\n", __func__, idx);

return 0;
@@ -364,14 +358,6 @@ int edac_pci_main_kobj_setup(void)
goto decrement_count_fail;
}

- /* Need the kobject hook ups, and name setting */
- edac_pci_top_main_kobj.ktype = &ktype_edac_pci_main_kobj;
- edac_pci_top_main_kobj.parent = &edac_class->kset.kobj;
-
- err = kobject_set_name(&edac_pci_top_main_kobj, "pci");
- if (err)
- goto decrement_count_fail;
-
/* Bump the reference count on this module to ensure the
* modules isn't unloaded until we deconstruct the top
* level main kobj for EDAC PCI
@@ -383,23 +369,24 @@ int edac_pci_main_kobj_setup(void)
}

/* Instanstiate the pci object */
- /* FIXME: maybe new sysdev_create_subdir() */
- err = kobject_register(&edac_pci_top_main_kobj);
+ err = kobject_init_and_add(&edac_pci_top_main_kobj, &ktype_edac_pci_main_kobj,
+ &edac_class->kset.kobj, "pci");
if (err) {
debugf1("Failed to register '.../edac/pci'\n");
- goto kobject_register_fail;
+ goto kobject_init_and_add_fail;
}

/* At this point, to 'release' the top level kobject
* for EDAC PCI, then edac_pci_main_kobj_teardown()
* must be used, for resources to be cleaned up properly
*/
+ kobject_uevent(&edac_pci_top_main_kobj, KOBJ_ADD);
debugf1("Registered '.../edac/pci' kobject\n");

return 0;

/* Error unwind statck */
-kobject_register_fail:
+kobject_init_and_add_fail:
module_put(THIS_MODULE);

decrement_count_fail:
--
1.5.3.8

2008-01-25 08:18:23

by Greg KH

[permalink] [raw]
Subject: [PATCH 157/196] Kobject: drop child->parent ref at unregistration

From: Alan Stern <[email protected]>

This patch (as1015) reverts changes that were made to the driver core
about four years ago. The intent back then was to avoid certain kinds
of invalid memory accesses by leaving kernel objects allocated as long
as any of their children were still allocated. The original and
correct approach was to wait only as long as any children were still
_registered_; that's what this patch reinstates.

This fixes a problem in the SCSI core made visible by the class_device
to regular device conversion: A reference loop (scsi_device holds
reference to request_queue, which is the child of a gendisk, which is
the child of the scsi_device) prevents the data structures from being
released, even though they are deregistered okay.

It's possible that this change will cause a few bugs to surface,
things that have been hidden for several years. They can be fixed
easily enough by having the child device take an explicit reference to
the parent whenever needed.

Signed-off-by: Alan Stern <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 1015f74..493e991 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -149,12 +149,16 @@ void kobject_init(struct kobject * kobj)

static void unlink(struct kobject * kobj)
{
+ struct kobject *parent = kobj->parent;
+
if (kobj->kset) {
spin_lock(&kobj->kset->list_lock);
list_del_init(&kobj->entry);
spin_unlock(&kobj->kset->list_lock);
}
+ kobj->parent = NULL;
kobject_put(kobj);
+ kobject_put(parent);
}

/**
@@ -208,7 +212,6 @@ int kobject_add(struct kobject * kobj)
if (error) {
/* unlink does the kobject_put() for us */
unlink(kobj);
- kobject_put(parent);

/* be noisy on error issues */
if (error == -EEXIST)
@@ -590,7 +593,6 @@ static void kobject_cleanup(struct kobject *kobj)
{
struct kobj_type * t = get_ktype(kobj);
struct kset * s = kobj->kset;
- struct kobject * parent = kobj->parent;
const char *name = kobj->k_name;

pr_debug("kobject: '%s' (%p): %s\n",
@@ -604,7 +606,6 @@ static void kobject_cleanup(struct kobject *kobj)
}
if (s)
kset_put(s);
- kobject_put(parent);
}

static void kobject_release(struct kref *kref)
--
1.5.3.8

2008-01-25 08:18:41

by Greg KH

[permalink] [raw]
Subject: [PATCH 136/196] Kobject: convert net/bridge/br_if.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Stephen Hemminger <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
net/bridge/br_if.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index dadec94..298e0f4 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -258,12 +258,6 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
p->state = BR_STATE_DISABLED;
br_stp_port_timer_init(p);

- kobject_init(&p->kobj);
- kobject_set_name(&p->kobj, SYSFS_BRIDGE_PORT_ATTR);
- p->kobj.ktype = &brport_ktype;
- p->kobj.parent = &(dev->dev.kobj);
- p->kobj.kset = NULL;
-
return p;
}

@@ -379,7 +373,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
if (IS_ERR(p))
return PTR_ERR(p);

- err = kobject_add(&p->kobj);
+ err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj),
+ SYSFS_BRIDGE_PORT_ATTR);
if (err)
goto err0;

@@ -416,6 +411,7 @@ err2:
br_fdb_delete_by_port(br, p, 1);
err1:
kobject_del(&p->kobj);
+ return err;
err0:
kobject_put(&p->kobj);
return err;
--
1.5.3.8

2008-01-25 08:19:05

by Greg KH

[permalink] [raw]
Subject: [PATCH 141/196] USB: use proper call to driver_create_file

Don't try to call the "raw" sysfs_create_file when we already have a
helper function to do this kind of work for us.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/usb/core/driver.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index c51f8e9..7c3aaa9 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -91,8 +91,8 @@ static int usb_create_newid_file(struct usb_driver *usb_drv)
goto exit;

if (usb_drv->probe != NULL)
- error = sysfs_create_file(&usb_drv->drvwrap.driver.kobj,
- &driver_attr_new_id.attr);
+ error = driver_create_file(&usb_drv->drvwrap.driver,
+ &driver_attr_new_id);
exit:
return error;
}
@@ -103,8 +103,8 @@ static void usb_remove_newid_file(struct usb_driver *usb_drv)
return;

if (usb_drv->probe != NULL)
- sysfs_remove_file(&usb_drv->drvwrap.driver.kobj,
- &driver_attr_new_id.attr);
+ driver_remove_file(&usb_drv->drvwrap.driver,
+ &driver_attr_new_id);
}

static void usb_free_dynids(struct usb_driver *usb_drv)
--
1.5.3.8

2008-01-25 08:19:35

by Greg KH

[permalink] [raw]
Subject: [PATCH 117/196] Kobject: change drivers/base/sys.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/sys.c | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 29eadc6..47fc6eb 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -224,20 +224,15 @@ int sysdev_register(struct sys_device * sysdev)
if (!cls)
return -EINVAL;

+ pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj));
+
/* Make sure the kset is set */
sysdev->kobj.kset = &cls->kset;

- /* But make sure we point to the right type for sysfs translation */
- sysdev->kobj.ktype = &ktype_sysdev;
- error = kobject_set_name(&sysdev->kobj, "%s%d",
- kobject_name(&cls->kset.kobj), sysdev->id);
- if (error)
- return error;
-
- pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj));
-
/* Register the object */
- error = kobject_register(&sysdev->kobj);
+ error = kobject_init_and_add(&sysdev->kobj, &ktype_sysdev, NULL,
+ "%s%d", kobject_name(&cls->kset.kobj),
+ sysdev->id);

if (!error) {
struct sysdev_driver * drv;
@@ -254,6 +249,7 @@ int sysdev_register(struct sys_device * sysdev)
}
mutex_unlock(&sysdev_drivers_lock);
}
+ kobject_uevent(&sysdev->kobj, KOBJ_ADD);
return error;
}

--
1.5.3.8

2008-01-25 08:19:54

by Greg KH

[permalink] [raw]
Subject: [PATCH 173/196] Kobject: convert fs/* from kobject_unregister() to kobject_put()

There is no need for kobject_unregister() anymore, thanks to Kay's
kobject cleanup changes, so replace all instances of it with
kobject_put().


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/configfs/mount.c | 6 +++---
fs/debugfs/inode.c | 4 ++--
fs/dlm/lockspace.c | 4 ++--
fs/ecryptfs/main.c | 4 ++--
fs/fuse/inode.c | 6 +++---
fs/gfs2/locking/dlm/sysfs.c | 2 +-
fs/gfs2/sys.c | 4 ++--
fs/partitions/check.c | 6 +++---
8 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 54bf0db..de3b31d 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -150,7 +150,7 @@ static int __init configfs_init(void)
err = register_filesystem(&configfs_fs_type);
if (err) {
printk(KERN_ERR "configfs: Unable to register filesystem!\n");
- kobject_unregister(config_kobj);
+ kobject_put(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
goto out;
@@ -159,7 +159,7 @@ static int __init configfs_init(void)
err = configfs_inode_init();
if (err) {
unregister_filesystem(&configfs_fs_type);
- kobject_unregister(config_kobj);
+ kobject_put(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
}
@@ -170,7 +170,7 @@ out:
static void __exit configfs_exit(void)
{
unregister_filesystem(&configfs_fs_type);
- kobject_unregister(config_kobj);
+ kobject_put(config_kobj);
kmem_cache_destroy(configfs_dir_cachep);
configfs_dir_cachep = NULL;
configfs_inode_exit();
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 97f6381..d26e282 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -438,7 +438,7 @@ static int __init debugfs_init(void)

retval = register_filesystem(&debug_fs_type);
if (retval)
- kobject_unregister(debug_kobj);
+ kobject_put(debug_kobj);
return retval;
}

@@ -446,7 +446,7 @@ static void __exit debugfs_exit(void)
{
simple_release_fs(&debugfs_mount, &debugfs_mount_count);
unregister_filesystem(&debug_fs_type);
- kobject_unregister(debug_kobj);
+ kobject_put(debug_kobj);
}

core_initcall(debugfs_init);
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index b750f13..5c108c4 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -579,7 +579,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
kfree(ls->ls_rsbtbl);
out_lsfree:
if (do_unreg)
- kobject_unregister(&ls->ls_kobj);
+ kobject_put(&ls->ls_kobj);
else
kfree(ls);
out:
@@ -728,7 +728,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
dlm_clear_members(ls);
dlm_clear_members_gone(ls);
kfree(ls->ls_node_array);
- kobject_unregister(&ls->ls_kobj);
+ kobject_put(&ls->ls_kobj);
/* The ls structure will be freed when the kobject is done with */

mutex_lock(&ls_lock);
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 4f13321..0249aa4 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -767,7 +767,7 @@ static int do_sysfs_registration(void)
if (rc) {
printk(KERN_ERR
"Unable to create ecryptfs version attributes\n");
- kobject_unregister(ecryptfs_kobj);
+ kobject_put(ecryptfs_kobj);
}
out:
return rc;
@@ -776,7 +776,7 @@ out:
static void do_sysfs_unregistration(void)
{
sysfs_remove_group(ecryptfs_kobj, &attr_group);
- kobject_unregister(ecryptfs_kobj);
+ kobject_put(ecryptfs_kobj);
}

static int __init ecryptfs_init(void)
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index e6e23a2..e5e80d1 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -810,15 +810,15 @@ static int fuse_sysfs_init(void)
return 0;

out_fuse_unregister:
- kobject_unregister(fuse_kobj);
+ kobject_put(fuse_kobj);
out_err:
return err;
}

static void fuse_sysfs_cleanup(void)
{
- kobject_unregister(connections_kobj);
- kobject_unregister(fuse_kobj);
+ kobject_put(connections_kobj);
+ kobject_put(fuse_kobj);
}

static int __init fuse_init(void)
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index a7336b9..a87b098 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -207,7 +207,7 @@ int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)

void gdlm_kobject_release(struct gdlm_ls *ls)
{
- kobject_unregister(&ls->kobj);
+ kobject_put(&ls->kobj);
}

int gdlm_sysfs_init(void)
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 8d9cd5b..3a3176b 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -525,7 +525,7 @@ fail_counters:
fail_lockstruct:
sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
fail_reg:
- kobject_unregister(&sdp->sd_kobj);
+ kobject_put(&sdp->sd_kobj);
fail:
fs_err(sdp, "error %d adding sysfs files", error);
return error;
@@ -537,7 +537,7 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
sysfs_remove_group(&sdp->sd_kobj, &args_group);
sysfs_remove_group(&sdp->sd_kobj, &counters_group);
sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
- kobject_unregister(&sdp->sd_kobj);
+ kobject_put(&sdp->sd_kobj);
}

int gfs2_sys_init(void)
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 97f3f5f..739da70 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -314,7 +314,7 @@ void delete_partition(struct gendisk *disk, int part)
p->nr_sects = 0;
p->ios[0] = p->ios[1] = 0;
p->sectors[0] = p->sectors[1] = 0;
- kobject_unregister(p->holder_dir);
+ kobject_put(p->holder_dir);
device_del(&p->dev);
put_device(&p->dev);
}
@@ -505,8 +505,8 @@ void del_gendisk(struct gendisk *disk)
disk_stat_set_all(disk, 0);
disk->stamp = 0;

- kobject_unregister(disk->holder_dir);
- kobject_unregister(disk->slave_dir);
+ kobject_put(disk->holder_dir);
+ kobject_put(disk->slave_dir);
disk->driverfs_dev = NULL;
#ifndef CONFIG_SYSFS_DEPRECATED
sysfs_remove_link(block_depr, disk->dev.bus_id);
--
1.5.3.8

2008-01-25 08:20:21

by Greg KH

[permalink] [raw]
Subject: [PATCH 168/196] Kset: remove kset_add function

No one is calling this anymore, so just remove it and hard-code the one
internal-use of it.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 1 -
lib/kobject.c | 13 +------------
2 files changed, 1 insertions(+), 13 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 2590847..63967da 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -158,7 +158,6 @@ struct kset {
};

extern void kset_init(struct kset * k);
-extern int __must_check kset_add(struct kset * k);
extern int __must_check kset_register(struct kset * k);
extern void kset_unregister(struct kset * k);
extern struct kset * __must_check kset_create_and_add(const char *name,
diff --git a/lib/kobject.c b/lib/kobject.c
index 3326281..c321f19 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -710,17 +710,6 @@ struct sysfs_ops kobj_sysfs_ops = {
};

/**
- * kset_add - add a kset object to the hierarchy.
- * @k: kset.
- */
-
-int kset_add(struct kset * k)
-{
- return kobject_add_internal(&k->kobj);
-}
-
-
-/**
* kset_register - initialize and add a kset.
* @k: kset.
*/
@@ -733,7 +722,7 @@ int kset_register(struct kset * k)
return -EINVAL;

kset_init(k);
- err = kset_add(k);
+ err = kobject_add_internal(&k->kobj);
if (err)
return err;
kobject_uevent(&k->kobj, KOBJ_ADD);
--
1.5.3.8

2008-01-25 08:20:53

by Greg KH

[permalink] [raw]
Subject: [PATCH 144/196] PCI: remove foolish code from pci-driver.c

The PCI bus should not be trying to declare its own attribute type.
Especially as this code could never ever be called because the driver
core overwrites the driver kobject type to be its own internal type.
Delete all of this code as it was never being used and is not correct.

Also update my copyright on the file while I'm touching things there.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pci/pci-driver.c | 50 ++++-----------------------------------------
1 files changed, 5 insertions(+), 45 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 73e3629..c4fa35d 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -1,6 +1,11 @@
/*
* drivers/pci/pci-driver.c
*
+ * (C) Copyright 2002-2004, 2007 Greg Kroah-Hartman <[email protected]>
+ * (C) Copyright 2007 Novell Inc.
+ *
+ * Released under the GPL v2 only.
+ *
*/

#include <linux/pci.h>
@@ -356,50 +361,6 @@ static void pci_device_shutdown(struct device *dev)
drv->shutdown(pci_dev);
}

-#define kobj_to_pci_driver(obj) container_of(obj, struct device_driver, kobj)
-#define attr_to_driver_attribute(obj) container_of(obj, struct driver_attribute, attr)
-
-static ssize_t
-pci_driver_attr_show(struct kobject * kobj, struct attribute *attr, char *buf)
-{
- struct device_driver *driver = kobj_to_pci_driver(kobj);
- struct driver_attribute *dattr = attr_to_driver_attribute(attr);
- ssize_t ret;
-
- if (!get_driver(driver))
- return -ENODEV;
-
- ret = dattr->show ? dattr->show(driver, buf) : -EIO;
-
- put_driver(driver);
- return ret;
-}
-
-static ssize_t
-pci_driver_attr_store(struct kobject * kobj, struct attribute *attr,
- const char *buf, size_t count)
-{
- struct device_driver *driver = kobj_to_pci_driver(kobj);
- struct driver_attribute *dattr = attr_to_driver_attribute(attr);
- ssize_t ret;
-
- if (!get_driver(driver))
- return -ENODEV;
-
- ret = dattr->store ? dattr->store(driver, buf, count) : -EIO;
-
- put_driver(driver);
- return ret;
-}
-
-static struct sysfs_ops pci_driver_sysfs_ops = {
- .show = pci_driver_attr_show,
- .store = pci_driver_attr_store,
-};
-static struct kobj_type pci_driver_kobj_type = {
- .sysfs_ops = &pci_driver_sysfs_ops,
-};
-
/**
* __pci_register_driver - register a new pci driver
* @drv: the driver structure to register
@@ -421,7 +382,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
drv->driver.bus = &pci_bus_type;
drv->driver.owner = owner;
drv->driver.mod_name = mod_name;
- drv->driver.kobj.ktype = &pci_driver_kobj_type;

spin_lock_init(&drv->dynids.lock);
INIT_LIST_HEAD(&drv->dynids.list);
--
1.5.3.8

2008-01-25 08:21:17

by Greg KH

[permalink] [raw]
Subject: [PATCH 193/196] Driver core: fix coding style issues in device.h

Finally clean up the odd spaces and other mess in device.h

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/device.h | 283 +++++++++++++++++++++++++-----------------------
1 files changed, 145 insertions(+), 138 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index cdaf57b..1880208 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -25,7 +25,8 @@
#include <asm/device.h>

#define DEVICE_NAME_SIZE 50
-#define DEVICE_NAME_HALF __stringify(20) /* Less than half to accommodate slop */
+/* DEVICE_NAME_HALF is really less than half to accommodate slop */
+#define DEVICE_NAME_HALF __stringify(20)
#define DEVICE_ID_SIZE 32
#define BUS_ID_SIZE KOBJ_NAME_LEN

@@ -40,52 +41,53 @@ struct bus_type_private;

struct bus_attribute {
struct attribute attr;
- ssize_t (*show)(struct bus_type *, char * buf);
- ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
+ ssize_t (*show)(struct bus_type *bus, char *buf);
+ ssize_t (*store)(struct bus_type *bus, const char *buf, size_t count);
};

-#define BUS_ATTR(_name,_mode,_show,_store) \
-struct bus_attribute bus_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define BUS_ATTR(_name, _mode, _show, _store) \
+struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)

extern int __must_check bus_create_file(struct bus_type *,
struct bus_attribute *);
extern void bus_remove_file(struct bus_type *, struct bus_attribute *);

struct bus_type {
- const char * name;
- struct bus_attribute * bus_attrs;
- struct device_attribute * dev_attrs;
- struct driver_attribute * drv_attrs;
-
- int (*match)(struct device * dev, struct device_driver * drv);
- int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
- int (*probe)(struct device * dev);
- int (*remove)(struct device * dev);
- void (*shutdown)(struct device * dev);
-
- int (*suspend)(struct device * dev, pm_message_t state);
- int (*suspend_late)(struct device * dev, pm_message_t state);
- int (*resume_early)(struct device * dev);
- int (*resume)(struct device * dev);
+ const char *name;
+ struct bus_attribute *bus_attrs;
+ struct device_attribute *dev_attrs;
+ struct driver_attribute *drv_attrs;
+
+ int (*match)(struct device *dev, struct device_driver *drv);
+ int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
+ int (*probe)(struct device *dev);
+ int (*remove)(struct device *dev);
+ void (*shutdown)(struct device *dev);
+
+ int (*suspend)(struct device *dev, pm_message_t state);
+ int (*suspend_late)(struct device *dev, pm_message_t state);
+ int (*resume_early)(struct device *dev);
+ int (*resume)(struct device *dev);

struct bus_type_private *p;
};

-extern int __must_check bus_register(struct bus_type * bus);
-extern void bus_unregister(struct bus_type * bus);
+extern int __must_check bus_register(struct bus_type *bus);
+extern void bus_unregister(struct bus_type *bus);

-extern int __must_check bus_rescan_devices(struct bus_type * bus);
+extern int __must_check bus_rescan_devices(struct bus_type *bus);

/* iterator helpers for buses */

-int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
- int (*fn)(struct device *, void *));
-struct device * bus_find_device(struct bus_type *bus, struct device *start,
- void *data, int (*match)(struct device *, void *));
+int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
+ int (*fn)(struct device *dev, void *data));
+struct device *bus_find_device(struct bus_type *bus, struct device *start,
+ void *data,
+ int (*match)(struct device *dev, void *data));

int __must_check bus_for_each_drv(struct bus_type *bus,
- struct device_driver *start, void *data,
- int (*fn)(struct device_driver *, void *));
+ struct device_driver *start, void *data,
+ int (*fn)(struct device_driver *, void *));

/*
* Bus notifiers: Get notified of addition/removal of devices
@@ -120,57 +122,63 @@ struct device_driver {
struct module *owner;
const char *mod_name; /* used for built-in modules */

- int (*probe) (struct device * dev);
- int (*remove) (struct device * dev);
- void (*shutdown) (struct device * dev);
- int (*suspend) (struct device * dev, pm_message_t state);
- int (*resume) (struct device * dev);
+ int (*probe) (struct device *dev);
+ int (*remove) (struct device *dev);
+ void (*shutdown) (struct device *dev);
+ int (*suspend) (struct device *dev, pm_message_t state);
+ int (*resume) (struct device *dev);
struct attribute_group **groups;

struct driver_private *p;
};


-extern int __must_check driver_register(struct device_driver * drv);
-extern void driver_unregister(struct device_driver * drv);
+extern int __must_check driver_register(struct device_driver *drv);
+extern void driver_unregister(struct device_driver *drv);

-extern struct device_driver * get_driver(struct device_driver * drv);
-extern void put_driver(struct device_driver * drv);
-extern struct device_driver *driver_find(const char *name, struct bus_type *bus);
+extern struct device_driver *get_driver(struct device_driver *drv);
+extern void put_driver(struct device_driver *drv);
+extern struct device_driver *driver_find(const char *name,
+ struct bus_type *bus);
extern int driver_probe_done(void);

/* sysfs interface for exporting driver attributes */

struct driver_attribute {
- struct attribute attr;
- ssize_t (*show)(struct device_driver *, char * buf);
- ssize_t (*store)(struct device_driver *, const char * buf, size_t count);
+ struct attribute attr;
+ ssize_t (*show)(struct device_driver *driver, char *buf);
+ ssize_t (*store)(struct device_driver *driver, const char *buf,
+ size_t count);
};

-#define DRIVER_ATTR(_name,_mode,_show,_store) \
-struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define DRIVER_ATTR(_name, _mode, _show, _store) \
+struct driver_attribute driver_attr_##_name = \
+ __ATTR(_name, _mode, _show, _store)

-extern int __must_check driver_create_file(struct device_driver *,
- struct driver_attribute *);
-extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
+extern int __must_check driver_create_file(struct device_driver *driver,
+ struct driver_attribute *attr);
+extern void driver_remove_file(struct device_driver *driver,
+ struct driver_attribute *attr);

extern int __must_check driver_add_kobj(struct device_driver *drv,
struct kobject *kobj,
const char *fmt, ...);

-extern int __must_check driver_for_each_device(struct device_driver * drv,
- struct device *start, void *data,
- int (*fn)(struct device *, void *));
-struct device * driver_find_device(struct device_driver *drv,
- struct device *start, void *data,
- int (*match)(struct device *, void *));
+extern int __must_check driver_for_each_device(struct device_driver *drv,
+ struct device *start,
+ void *data,
+ int (*fn)(struct device *dev,
+ void *));
+struct device *driver_find_device(struct device_driver *drv,
+ struct device *start, void *data,
+ int (*match)(struct device *dev, void *data));

/*
* device classes
*/
struct class {
- const char * name;
- struct module * owner;
+ const char *name;
+ struct module *owner;

struct kset subsys;
struct list_head children;
@@ -178,23 +186,23 @@ struct class {
struct list_head interfaces;
struct kset class_dirs;
struct semaphore sem; /* locks children, devices, interfaces */
- struct class_attribute * class_attrs;
- struct class_device_attribute * class_dev_attrs;
- struct device_attribute * dev_attrs;
+ struct class_attribute *class_attrs;
+ struct class_device_attribute *class_dev_attrs;
+ struct device_attribute *dev_attrs;

- int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
- int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);
+ int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
+ int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);

- void (*release)(struct class_device *dev);
- void (*class_release)(struct class *class);
- void (*dev_release)(struct device *dev);
+ void (*release)(struct class_device *dev);
+ void (*class_release)(struct class *class);
+ void (*dev_release)(struct device *dev);

- int (*suspend)(struct device *, pm_message_t state);
- int (*resume)(struct device *);
+ int (*suspend)(struct device *dev, pm_message_t state);
+ int (*resume)(struct device *dev);
};

-extern int __must_check class_register(struct class *);
-extern void class_unregister(struct class *);
+extern int __must_check class_register(struct class *class);
+extern void class_unregister(struct class *class);
extern int class_for_each_device(struct class *class, void *data,
int (*fn)(struct device *dev, void *data));
extern struct device *class_find_device(struct class *class, void *data,
@@ -204,27 +212,28 @@ extern struct class_device *class_find_child(struct class *class, void *data,


struct class_attribute {
- struct attribute attr;
- ssize_t (*show)(struct class *, char * buf);
- ssize_t (*store)(struct class *, const char * buf, size_t count);
+ struct attribute attr;
+ ssize_t (*show)(struct class *class, char *buf);
+ ssize_t (*store)(struct class *class, const char *buf, size_t count);
};

-#define CLASS_ATTR(_name,_mode,_show,_store) \
-struct class_attribute class_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define CLASS_ATTR(_name, _mode, _show, _store) \
+struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)

-extern int __must_check class_create_file(struct class *,
- const struct class_attribute *);
-extern void class_remove_file(struct class *, const struct class_attribute *);
+extern int __must_check class_create_file(struct class *class,
+ const struct class_attribute *attr);
+extern void class_remove_file(struct class *class,
+ const struct class_attribute *attr);

struct class_device_attribute {
- struct attribute attr;
- ssize_t (*show)(struct class_device *, char * buf);
- ssize_t (*store)(struct class_device *, const char * buf, size_t count);
+ struct attribute attr;
+ ssize_t (*show)(struct class_device *, char *buf);
+ ssize_t (*store)(struct class_device *, const char *buf, size_t count);
};

-#define CLASS_DEVICE_ATTR(_name,_mode,_show,_store) \
+#define CLASS_DEVICE_ATTR(_name, _mode, _show, _store) \
struct class_device_attribute class_device_attr_##_name = \
- __ATTR(_name,_mode,_show,_store)
+ __ATTR(_name, _mode, _show, _store)

extern int __must_check class_device_create_file(struct class_device *,
const struct class_device_attribute *);
@@ -257,26 +266,24 @@ struct class_device {
struct list_head node;

struct kobject kobj;
- struct class * class; /* required */
- dev_t devt; /* dev_t, creates the sysfs "dev" */
- struct device * dev; /* not necessary, but nice to have */
- void * class_data; /* class-specific data */
- struct class_device *parent; /* parent of this child device, if there is one */
- struct attribute_group ** groups; /* optional groups */
-
- void (*release)(struct class_device *dev);
- int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
- char class_id[BUS_ID_SIZE]; /* unique to this class */
+ struct class *class;
+ dev_t devt;
+ struct device *dev;
+ void *class_data;
+ struct class_device *parent;
+ struct attribute_group **groups;
+
+ void (*release)(struct class_device *dev);
+ int (*uevent)(struct class_device *dev, struct kobj_uevent_env *env);
+ char class_id[BUS_ID_SIZE];
};

-static inline void *
-class_get_devdata (struct class_device *dev)
+static inline void *class_get_devdata(struct class_device *dev)
{
return dev->class_data;
}

-static inline void
-class_set_devdata (struct class_device *dev, void *data)
+static inline void class_set_devdata(struct class_device *dev, void *data)
{
dev->class_data = data;
}
@@ -288,10 +295,10 @@ extern void class_device_initialize(struct class_device *);
extern int __must_check class_device_add(struct class_device *);
extern void class_device_del(struct class_device *);

-extern struct class_device * class_device_get(struct class_device *);
+extern struct class_device *class_device_get(struct class_device *);
extern void class_device_put(struct class_device *);

-extern void class_device_remove_file(struct class_device *,
+extern void class_device_remove_file(struct class_device *,
const struct class_device_attribute *);
extern int __must_check class_device_create_bin_file(struct class_device *,
struct bin_attribute *);
@@ -318,7 +325,7 @@ extern struct class_device *class_device_create(struct class *cls,
dev_t devt,
struct device *device,
const char *fmt, ...)
- __attribute__((format(printf,5,6)));
+ __attribute__((format(printf, 5, 6)));
extern void class_device_destroy(struct class *cls, dev_t devt);

/*
@@ -335,8 +342,8 @@ struct device_type {
struct attribute_group **groups;
int (*uevent)(struct device *dev, struct kobj_uevent_env *env);
void (*release)(struct device *dev);
- int (*suspend)(struct device * dev, pm_message_t state);
- int (*resume)(struct device * dev);
+ int (*suspend)(struct device *dev, pm_message_t state);
+ int (*resume)(struct device *dev);
};

/* interface for exporting device attributes */
@@ -348,18 +355,19 @@ struct device_attribute {
const char *buf, size_t count);
};

-#define DEVICE_ATTR(_name,_mode,_show,_store) \
-struct device_attribute dev_attr_##_name = __ATTR(_name,_mode,_show,_store)
+#define DEVICE_ATTR(_name, _mode, _show, _store) \
+struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)

extern int __must_check device_create_file(struct device *device,
- struct device_attribute * entry);
-extern void device_remove_file(struct device * dev, struct device_attribute * attr);
+ struct device_attribute *entry);
+extern void device_remove_file(struct device *dev,
+ struct device_attribute *attr);
extern int __must_check device_create_bin_file(struct device *dev,
struct bin_attribute *attr);
extern void device_remove_bin_file(struct device *dev,
struct bin_attribute *attr);
extern int device_schedule_callback_owner(struct device *dev,
- void (*func)(struct device *), struct module *owner);
+ void (*func)(struct device *dev), struct module *owner);

/* This is a macro to avoid include problems with THIS_MODULE */
#define device_schedule_callback(dev, func) \
@@ -370,21 +378,21 @@ typedef void (*dr_release_t)(struct device *dev, void *res);
typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);

#ifdef CONFIG_DEBUG_DEVRES
-extern void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
+extern void *__devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
const char *name);
#define devres_alloc(release, size, gfp) \
__devres_alloc(release, size, gfp, #release)
#else
-extern void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
+extern void *devres_alloc(dr_release_t release, size_t size, gfp_t gfp);
#endif
extern void devres_free(void *res);
extern void devres_add(struct device *dev, void *res);
-extern void * devres_find(struct device *dev, dr_release_t release,
- dr_match_t match, void *match_data);
-extern void * devres_get(struct device *dev, void *new_res,
+extern void *devres_find(struct device *dev, dr_release_t release,
dr_match_t match, void *match_data);
-extern void * devres_remove(struct device *dev, dr_release_t release,
- dr_match_t match, void *match_data);
+extern void *devres_get(struct device *dev, void *new_res,
+ dr_match_t match, void *match_data);
+extern void *devres_remove(struct device *dev, dr_release_t release,
+ dr_match_t match, void *match_data);
extern int devres_destroy(struct device *dev, dr_release_t release,
dr_match_t match, void *match_data);

@@ -401,7 +409,7 @@ extern void devm_kfree(struct device *dev, void *p);

struct device {
struct klist klist_children;
- struct klist_node knode_parent; /* node in sibling list */
+ struct klist_node knode_parent; /* node in sibling list */
struct klist_node knode_driver;
struct klist_node knode_bus;
struct device *parent;
@@ -416,7 +424,7 @@ struct device {
* its driver.
*/

- struct bus_type * bus; /* type of bus device is on */
+ struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this
device */
void *driver_data; /* data private to the driver */
@@ -447,10 +455,10 @@ struct device {
/* class_device migration path */
struct list_head node;
struct class *class;
- dev_t devt; /* dev_t, creates the sysfs "dev" */
+ dev_t devt; /* dev_t, creates the sysfs "dev" */
struct attribute_group **groups; /* optional groups */

- void (*release)(struct device * dev);
+ void (*release)(struct device *dev);
};

#ifdef CONFIG_NUMA
@@ -472,14 +480,12 @@ static inline void set_dev_node(struct device *dev, int node)
}
#endif

-static inline void *
-dev_get_drvdata (struct device *dev)
+static inline void *dev_get_drvdata(struct device *dev)
{
return dev->driver_data;
}

-static inline void
-dev_set_drvdata (struct device *dev, void *data)
+static inline void dev_set_drvdata(struct device *dev, void *data)
{
dev->driver_data = data;
}
@@ -494,15 +500,15 @@ void driver_init(void);
/*
* High level routines for use by the bus drivers
*/
-extern int __must_check device_register(struct device * dev);
-extern void device_unregister(struct device * dev);
-extern void device_initialize(struct device * dev);
-extern int __must_check device_add(struct device * dev);
-extern void device_del(struct device * dev);
-extern int device_for_each_child(struct device *, void *,
- int (*fn)(struct device *, void *));
-extern struct device *device_find_child(struct device *, void *data,
- int (*match)(struct device *, void *));
+extern int __must_check device_register(struct device *dev);
+extern void device_unregister(struct device *dev);
+extern void device_initialize(struct device *dev);
+extern int __must_check device_add(struct device *dev);
+extern void device_del(struct device *dev);
+extern int device_for_each_child(struct device *dev, void *data,
+ int (*fn)(struct device *dev, void *data));
+extern struct device *device_find_child(struct device *dev, void *data,
+ int (*match)(struct device *dev, void *data));
extern int device_rename(struct device *dev, char *new_name);
extern int device_move(struct device *dev, struct device *new_parent);

@@ -511,8 +517,8 @@ extern int device_move(struct device *dev, struct device *new_parent);
* for information on use.
*/
extern int __must_check device_bind_driver(struct device *dev);
-extern void device_release_driver(struct device * dev);
-extern int __must_check device_attach(struct device * dev);
+extern void device_release_driver(struct device *dev);
+extern int __must_check device_attach(struct device *dev);
extern int __must_check driver_attach(struct device_driver *drv);
extern int __must_check device_reprobe(struct device *dev);

@@ -521,7 +527,7 @@ extern int __must_check device_reprobe(struct device *dev);
*/
extern struct device *device_create(struct class *cls, struct device *parent,
dev_t devt, const char *fmt, ...)
- __attribute__((format(printf,4,5)));
+ __attribute__((format(printf, 4, 5)));
extern void device_destroy(struct class *cls, dev_t devt);
#ifdef CONFIG_PM_SLEEP
extern void destroy_suspended_device(struct class *cls, dev_t devt);
@@ -538,17 +544,17 @@ static inline void destroy_suspended_device(struct class *cls, dev_t devt)
* know about.
*/
/* Notify platform of device discovery */
-extern int (*platform_notify)(struct device * dev);
+extern int (*platform_notify)(struct device *dev);

-extern int (*platform_notify_remove)(struct device * dev);
+extern int (*platform_notify_remove)(struct device *dev);


/**
* get_device - atomically increment the reference count for the device.
*
*/
-extern struct device * get_device(struct device * dev);
-extern void put_device(struct device * dev);
+extern struct device *get_device(struct device *dev);
+extern void put_device(struct device *dev);


/* drivers/base/power/shutdown.c */
@@ -560,7 +566,8 @@ extern void sysdev_shutdown(void);
/* debugging and troubleshooting/diagnostic helpers. */
extern const char *dev_driver_string(struct device *dev);
#define dev_printk(level, dev, format, arg...) \
- printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)
+ printk(level "%s %s: " format , dev_driver_string(dev) , \
+ (dev)->bus_id , ## arg)

#define dev_emerg(dev, format, arg...) \
dev_printk(KERN_EMERG , dev , format , ## arg)
@@ -582,7 +589,7 @@ extern const char *dev_driver_string(struct device *dev);
dev_printk(KERN_DEBUG , dev , format , ## arg)
#else
static inline int __attribute__ ((format (printf, 2, 3)))
-dev_dbg(struct device * dev, const char * fmt, ...)
+dev_dbg(struct device *dev, const char *fmt, ...)
{
return 0;
}
@@ -592,7 +599,7 @@ dev_dbg(struct device * dev, const char * fmt, ...)
#define dev_vdbg dev_dbg
#else
static inline int __attribute__ ((format (printf, 2, 3)))
-dev_vdbg(struct device * dev, const char * fmt, ...)
+dev_vdbg(struct device *dev, const char *fmt, ...)
{
return 0;
}
--
1.5.3.8

2008-01-25 08:21:40

by Greg KH

[permalink] [raw]
Subject: [PATCH 116/196] Kobject: change drivers/pci/hotplug/pci_hotplug_core.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Kristen Carlson Accardi <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pci/hotplug/pci_hotplug_core.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 175e0c8..0f05e6a 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -630,19 +630,19 @@ int pci_hp_register (struct hotplug_slot *slot)
return -EINVAL;
}

- kobject_set_name(&slot->kobj, "%s", slot->name);
- slot->kobj.kset = pci_hotplug_slots_kset;
- slot->kobj.ktype = &hotplug_slot_ktype;
-
/* this can fail if we have already registered a slot with the same name */
- if (kobject_register(&slot->kobj)) {
- err("Unable to register kobject");
+ slot->kobj.kset = pci_hotplug_slots_kset;
+ result = kobject_init_and_add(&slot->kobj, &hotplug_slot_ktype, NULL,
+ "%s", slot->name);
+ if (result) {
+ err("Unable to register kobject '%s'", slot->name);
return -EINVAL;
}
-
+
list_add (&slot->slot_list, &pci_hotplug_slot_list);

result = fs_add_slot (slot);
+ kobject_uevent(&slot->kobj, KOBJ_ADD);
dbg ("Added slot %s to the list\n", slot->name);
return result;
}
--
1.5.3.8

2008-01-25 08:21:59

by Greg KH

[permalink] [raw]
Subject: [PATCH 176/196] Driver core: change sysdev classes to use dynamic kobject names

From: Kay Sievers <[email protected]>

All kobjects require a dynamically allocated name now. We no longer
need to keep track if the name is statically assigned, we can just
unconditionally free() all kobject names on cleanup.

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/arm/kernel/time.c | 4 ++--
arch/arm/mach-integrator/integrator_ap.c | 2 +-
arch/arm/mach-pxa/cm-x270.c | 2 +-
arch/arm/mach-pxa/lpd270.c | 2 +-
arch/arm/mach-pxa/lubbock.c | 2 +-
arch/arm/mach-pxa/mainstone.c | 2 +-
arch/arm/mach-s3c2410/s3c2410.c | 2 +-
arch/arm/mach-s3c2412/s3c2412.c | 2 +-
arch/arm/mach-s3c2440/mach-osiris.c | 2 +-
arch/arm/mach-s3c2443/s3c2443.c | 2 +-
arch/arm/mach-sa1100/irq.c | 2 +-
arch/arm/oprofile/common.c | 2 +-
arch/arm/plat-omap/gpio.c | 2 +-
arch/arm/plat-s3c24xx/dma.c | 2 +-
arch/arm/plat-s3c24xx/s3c244x.c | 4 ++--
arch/avr32/kernel/time.c | 2 +-
arch/mips/kernel/i8259.c | 2 +-
arch/powerpc/platforms/cell/spu_base.c | 2 +-
arch/powerpc/platforms/powermac/pic.c | 2 +-
arch/powerpc/sysdev/ipic.c | 2 +-
arch/powerpc/sysdev/mpic.c | 2 +-
arch/powerpc/sysdev/qe_lib/qe_ic.c | 2 +-
arch/ppc/syslib/ipic.c | 2 +-
arch/ppc/syslib/open_pic.c | 2 +-
arch/ppc/syslib/open_pic2.c | 2 +-
arch/s390/kernel/time.c | 2 +-
arch/sh/drivers/dma/dma-sysfs.c | 2 +-
arch/sh/kernel/time.c | 2 +-
arch/x86/kernel/apic_32.c | 2 +-
arch/x86/kernel/apic_64.c | 2 +-
arch/x86/kernel/cpu/mcheck/mce_64.c | 2 +-
arch/x86/kernel/i8237.c | 2 +-
arch/x86/kernel/i8259_32.c | 2 +-
arch/x86/kernel/i8259_64.c | 2 +-
arch/x86/kernel/io_apic_32.c | 2 +-
arch/x86/kernel/io_apic_64.c | 2 +-
arch/x86/kernel/nmi_32.c | 2 +-
arch/x86/kernel/nmi_64.c | 2 +-
arch/x86/oprofile/nmi_int.c | 2 +-
drivers/acpi/pci_link.c | 2 +-
drivers/base/class.c | 2 +-
drivers/base/cpu.c | 2 +-
drivers/base/memory.c | 2 +-
drivers/base/node.c | 2 +-
drivers/base/sys.c | 1 +
drivers/edac/edac_module.c | 2 +-
drivers/kvm/kvm_main.c | 2 +-
drivers/macintosh/via-pmu.c | 2 +-
drivers/scsi/libsas/sas_scsi_host.c | 2 +-
include/linux/kobject.h | 13 ++-----------
include/linux/sysdev.h | 1 +
kernel/rtmutex-tester.c | 2 +-
kernel/time/clocksource.c | 2 +-
kernel/time/timekeeping.c | 2 +-
lib/kobject.c | 14 +++++---------
55 files changed, 62 insertions(+), 73 deletions(-)

diff --git a/arch/arm/kernel/time.c b/arch/arm/kernel/time.c
index 1533d3e..f6f3689 100644
--- a/arch/arm/kernel/time.c
+++ b/arch/arm/kernel/time.c
@@ -195,7 +195,7 @@ static int leds_shutdown(struct sys_device *dev)
}

static struct sysdev_class leds_sysclass = {
- set_kset_name("leds"),
+ .name = "leds",
.shutdown = leds_shutdown,
.suspend = leds_suspend,
.resume = leds_resume,
@@ -369,7 +369,7 @@ static int timer_resume(struct sys_device *dev)
#endif

static struct sysdev_class timer_sysclass = {
- set_kset_name("timer"),
+ .name = "timer",
.suspend = timer_suspend,
.resume = timer_resume,
};
diff --git a/arch/arm/mach-integrator/integrator_ap.c b/arch/arm/mach-integrator/integrator_ap.c
index 7228075..df37e93 100644
--- a/arch/arm/mach-integrator/integrator_ap.c
+++ b/arch/arm/mach-integrator/integrator_ap.c
@@ -214,7 +214,7 @@ static int irq_resume(struct sys_device *dev)
#endif

static struct sysdev_class irq_class = {
- set_kset_name("irq"),
+ .name = "irq",
.suspend = irq_suspend,
.resume = irq_resume,
};
diff --git a/arch/arm/mach-pxa/cm-x270.c b/arch/arm/mach-pxa/cm-x270.c
index 177664c..a163492 100644
--- a/arch/arm/mach-pxa/cm-x270.c
+++ b/arch/arm/mach-pxa/cm-x270.c
@@ -566,7 +566,7 @@ static int cmx270_resume(struct sys_device *dev)
}

static struct sysdev_class cmx270_pm_sysclass = {
- set_kset_name("pm"),
+ .name = "pm",
.resume = cmx270_resume,
.suspend = cmx270_suspend,
};
diff --git a/arch/arm/mach-pxa/lpd270.c b/arch/arm/mach-pxa/lpd270.c
index 2611644..78ebad0 100644
--- a/arch/arm/mach-pxa/lpd270.c
+++ b/arch/arm/mach-pxa/lpd270.c
@@ -122,7 +122,7 @@ static int lpd270_irq_resume(struct sys_device *dev)
}

static struct sysdev_class lpd270_irq_sysclass = {
- set_kset_name("cpld_irq"),
+ .name = "cpld_irq",
.resume = lpd270_irq_resume,
};

diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
index 011a1a7..1d3112d 100644
--- a/arch/arm/mach-pxa/lubbock.c
+++ b/arch/arm/mach-pxa/lubbock.c
@@ -126,7 +126,7 @@ static int lubbock_irq_resume(struct sys_device *dev)
}

static struct sysdev_class lubbock_irq_sysclass = {
- set_kset_name("cpld_irq"),
+ .name = "cpld_irq",
.resume = lubbock_irq_resume,
};

diff --git a/arch/arm/mach-pxa/mainstone.c b/arch/arm/mach-pxa/mainstone.c
index a4bc348..41d8c6c 100644
--- a/arch/arm/mach-pxa/mainstone.c
+++ b/arch/arm/mach-pxa/mainstone.c
@@ -120,7 +120,7 @@ static int mainstone_irq_resume(struct sys_device *dev)
}

static struct sysdev_class mainstone_irq_sysclass = {
- set_kset_name("cpld_irq"),
+ .name = "cpld_irq",
.resume = mainstone_irq_resume,
};

diff --git a/arch/arm/mach-s3c2410/s3c2410.c b/arch/arm/mach-s3c2410/s3c2410.c
index e580303..0e79919 100644
--- a/arch/arm/mach-s3c2410/s3c2410.c
+++ b/arch/arm/mach-s3c2410/s3c2410.c
@@ -100,7 +100,7 @@ void __init s3c2410_init_clocks(int xtal)
}

struct sysdev_class s3c2410_sysclass = {
- set_kset_name("s3c2410-core"),
+ .name = "s3c2410-core",
};

static struct sys_device s3c2410_sysdev = {
diff --git a/arch/arm/mach-s3c2412/s3c2412.c b/arch/arm/mach-s3c2412/s3c2412.c
index 4f92a15..265cd3f 100644
--- a/arch/arm/mach-s3c2412/s3c2412.c
+++ b/arch/arm/mach-s3c2412/s3c2412.c
@@ -196,7 +196,7 @@ void __init s3c2412_init_clocks(int xtal)
*/

struct sysdev_class s3c2412_sysclass = {
- set_kset_name("s3c2412-core"),
+ .name = "s3c2412-core",
};

static int __init s3c2412_core_init(void)
diff --git a/arch/arm/mach-s3c2440/mach-osiris.c b/arch/arm/mach-s3c2440/mach-osiris.c
index c326983..78af766 100644
--- a/arch/arm/mach-s3c2440/mach-osiris.c
+++ b/arch/arm/mach-s3c2440/mach-osiris.c
@@ -312,7 +312,7 @@ static int osiris_pm_resume(struct sys_device *sd)
#endif

static struct sysdev_class osiris_pm_sysclass = {
- set_kset_name("mach-osiris"),
+ .name = "mach-osiris",
.suspend = osiris_pm_suspend,
.resume = osiris_pm_resume,
};
diff --git a/arch/arm/mach-s3c2443/s3c2443.c b/arch/arm/mach-s3c2443/s3c2443.c
index 8d81171..9ce4905 100644
--- a/arch/arm/mach-s3c2443/s3c2443.c
+++ b/arch/arm/mach-s3c2443/s3c2443.c
@@ -43,7 +43,7 @@ static struct map_desc s3c2443_iodesc[] __initdata = {
};

struct sysdev_class s3c2443_sysclass = {
- set_kset_name("s3c2443-core"),
+ .name = "s3c2443-core",
};

static struct sys_device s3c2443_sysdev = {
diff --git a/arch/arm/mach-sa1100/irq.c b/arch/arm/mach-sa1100/irq.c
index edf3347..3dc17d7 100644
--- a/arch/arm/mach-sa1100/irq.c
+++ b/arch/arm/mach-sa1100/irq.c
@@ -283,7 +283,7 @@ static int sa1100irq_resume(struct sys_device *dev)
}

static struct sysdev_class sa1100irq_sysclass = {
- set_kset_name("sa11x0-irq"),
+ .name = "sa11x0-irq",
.suspend = sa1100irq_suspend,
.resume = sa1100irq_resume,
};
diff --git a/arch/arm/oprofile/common.c b/arch/arm/oprofile/common.c
index a9de727..0a5cf3a 100644
--- a/arch/arm/oprofile/common.c
+++ b/arch/arm/oprofile/common.c
@@ -96,7 +96,7 @@ static int op_arm_resume(struct sys_device *dev)
}

static struct sysdev_class oprofile_sysclass = {
- set_kset_name("oprofile"),
+ .name = "oprofile",
.resume = op_arm_resume,
.suspend = op_arm_suspend,
};
diff --git a/arch/arm/plat-omap/gpio.c b/arch/arm/plat-omap/gpio.c
index 6097753..b2a87b8 100644
--- a/arch/arm/plat-omap/gpio.c
+++ b/arch/arm/plat-omap/gpio.c
@@ -1455,7 +1455,7 @@ static int omap_gpio_resume(struct sys_device *dev)
}

static struct sysdev_class omap_gpio_sysclass = {
- set_kset_name("gpio"),
+ .name = "gpio",
.suspend = omap_gpio_suspend,
.resume = omap_gpio_resume,
};
diff --git a/arch/arm/plat-s3c24xx/dma.c b/arch/arm/plat-s3c24xx/dma.c
index 29696e4..aae1b9c 100644
--- a/arch/arm/plat-s3c24xx/dma.c
+++ b/arch/arm/plat-s3c24xx/dma.c
@@ -1265,7 +1265,7 @@ static int s3c2410_dma_resume(struct sys_device *dev)
#endif /* CONFIG_PM */

struct sysdev_class dma_sysclass = {
- set_kset_name("s3c24xx-dma"),
+ .name = "s3c24xx-dma",
.suspend = s3c2410_dma_suspend,
.resume = s3c2410_dma_resume,
};
diff --git a/arch/arm/plat-s3c24xx/s3c244x.c b/arch/arm/plat-s3c24xx/s3c244x.c
index 3444b13..f197bb3 100644
--- a/arch/arm/plat-s3c24xx/s3c244x.c
+++ b/arch/arm/plat-s3c24xx/s3c244x.c
@@ -151,13 +151,13 @@ static int s3c244x_resume(struct sys_device *dev)
/* Since the S3C2442 and S3C2440 share items, put both sysclasses here */

struct sysdev_class s3c2440_sysclass = {
- set_kset_name("s3c2440-core"),
+ .name = "s3c2440-core",
.suspend = s3c244x_suspend,
.resume = s3c244x_resume
};

struct sysdev_class s3c2442_sysclass = {
- set_kset_name("s3c2442-core"),
+ .name = "s3c2442-core",
.suspend = s3c244x_suspend,
.resume = s3c244x_resume
};
diff --git a/arch/avr32/kernel/time.c b/arch/avr32/kernel/time.c
index 7014a35..36a46c3 100644
--- a/arch/avr32/kernel/time.c
+++ b/arch/avr32/kernel/time.c
@@ -214,7 +214,7 @@ void __init time_init(void)
}

static struct sysdev_class timer_class = {
- set_kset_name("timer"),
+ .name = "timer",
};

static struct sys_device timer_device = {
diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
index 4710135..197d797 100644
--- a/arch/mips/kernel/i8259.c
+++ b/arch/mips/kernel/i8259.c
@@ -238,7 +238,7 @@ static int i8259A_shutdown(struct sys_device *dev)
}

static struct sysdev_class i8259_sysdev_class = {
- set_kset_name("i8259"),
+ .name = "i8259",
.resume = i8259A_resume,
.shutdown = i8259A_shutdown,
};
diff --git a/arch/powerpc/platforms/cell/spu_base.c b/arch/powerpc/platforms/cell/spu_base.c
index c83c3e3..a088622 100644
--- a/arch/powerpc/platforms/cell/spu_base.c
+++ b/arch/powerpc/platforms/cell/spu_base.c
@@ -459,7 +459,7 @@ static int spu_shutdown(struct sys_device *sysdev)
}

static struct sysdev_class spu_sysdev_class = {
- set_kset_name("spu"),
+ .name = "spu",
.shutdown = spu_shutdown,
};

diff --git a/arch/powerpc/platforms/powermac/pic.c b/arch/powerpc/platforms/powermac/pic.c
index 999f5e1..84c0d4e 100644
--- a/arch/powerpc/platforms/powermac/pic.c
+++ b/arch/powerpc/platforms/powermac/pic.c
@@ -663,7 +663,7 @@ static int pmacpic_resume(struct sys_device *sysdev)
#endif /* CONFIG_PM && CONFIG_PPC32 */

static struct sysdev_class pmacpic_sysclass = {
- set_kset_name("pmac_pic"),
+ .name = "pmac_pic",
};

static struct sys_device device_pmacpic = {
diff --git a/arch/powerpc/sysdev/ipic.c b/arch/powerpc/sysdev/ipic.c
index 05a56e5..e898ff4 100644
--- a/arch/powerpc/sysdev/ipic.c
+++ b/arch/powerpc/sysdev/ipic.c
@@ -725,7 +725,7 @@ unsigned int ipic_get_irq(void)
}

static struct sysdev_class ipic_sysclass = {
- set_kset_name("ipic"),
+ .name = "ipic",
};

static struct sys_device device_ipic = {
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index e479388..212a94f 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1584,7 +1584,7 @@ static struct sysdev_class mpic_sysclass = {
.resume = mpic_resume,
.suspend = mpic_suspend,
#endif
- set_kset_name("mpic"),
+ .name = "mpic",
};

static int mpic_init_sys(void)
diff --git a/arch/powerpc/sysdev/qe_lib/qe_ic.c b/arch/powerpc/sysdev/qe_lib/qe_ic.c
index e1c0fd6..f59444d 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_ic.c
+++ b/arch/powerpc/sysdev/qe_lib/qe_ic.c
@@ -483,7 +483,7 @@ int qe_ic_set_high_priority(unsigned int virq, unsigned int priority, int high)
}

static struct sysdev_class qe_ic_sysclass = {
- set_kset_name("qe_ic"),
+ .name = "qe_ic",
};

static struct sys_device device_qe_ic = {
diff --git a/arch/ppc/syslib/ipic.c b/arch/ppc/syslib/ipic.c
index 9192777..4f163e2 100644
--- a/arch/ppc/syslib/ipic.c
+++ b/arch/ppc/syslib/ipic.c
@@ -614,7 +614,7 @@ int ipic_get_irq(void)
}

static struct sysdev_class ipic_sysclass = {
- set_kset_name("ipic"),
+ .name = "ipic",
};

static struct sys_device device_ipic = {
diff --git a/arch/ppc/syslib/open_pic.c b/arch/ppc/syslib/open_pic.c
index 18ec947..da36522 100644
--- a/arch/ppc/syslib/open_pic.c
+++ b/arch/ppc/syslib/open_pic.c
@@ -1043,7 +1043,7 @@ int openpic_resume(struct sys_device *sysdev)
#endif /* CONFIG_PM */

static struct sysdev_class openpic_sysclass = {
- set_kset_name("openpic"),
+ .name = "openpic",
};

static struct sys_device device_openpic = {
diff --git a/arch/ppc/syslib/open_pic2.c b/arch/ppc/syslib/open_pic2.c
index d585207..449075a 100644
--- a/arch/ppc/syslib/open_pic2.c
+++ b/arch/ppc/syslib/open_pic2.c
@@ -666,7 +666,7 @@ int openpic2_resume(struct sys_device *sysdev)

/* HACK ALERT */
static struct sysdev_class openpic2_sysclass = {
- set_kset_name("openpic2"),
+ .name = "openpic2",
};

static struct sys_device device_openpic2 = {
diff --git a/arch/s390/kernel/time.c b/arch/s390/kernel/time.c
index 22b800c..3bbac12 100644
--- a/arch/s390/kernel/time.c
+++ b/arch/s390/kernel/time.c
@@ -1145,7 +1145,7 @@ static void etr_work_fn(struct work_struct *work)
* Sysfs interface functions
*/
static struct sysdev_class etr_sysclass = {
- set_kset_name("etr")
+ .name = "etr",
};

static struct sys_device etr_port0_dev = {
diff --git a/arch/sh/drivers/dma/dma-sysfs.c b/arch/sh/drivers/dma/dma-sysfs.c
index eebcd47..51b57c0 100644
--- a/arch/sh/drivers/dma/dma-sysfs.c
+++ b/arch/sh/drivers/dma/dma-sysfs.c
@@ -19,7 +19,7 @@
#include <asm/dma.h>

static struct sysdev_class dma_sysclass = {
- set_kset_name("dma"),
+ .name = "dma",
};
EXPORT_SYMBOL(dma_sysclass);

diff --git a/arch/sh/kernel/time.c b/arch/sh/kernel/time.c
index a3a67d1..2bc04bf 100644
--- a/arch/sh/kernel/time.c
+++ b/arch/sh/kernel/time.c
@@ -174,7 +174,7 @@ int timer_resume(struct sys_device *dev)
#endif

static struct sysdev_class timer_sysclass = {
- set_kset_name("timer"),
+ .name = "timer",
.suspend = timer_suspend,
.resume = timer_resume,
};
diff --git a/arch/x86/kernel/apic_32.c b/arch/x86/kernel/apic_32.c
index edb5108..a56c782 100644
--- a/arch/x86/kernel/apic_32.c
+++ b/arch/x86/kernel/apic_32.c
@@ -1530,7 +1530,7 @@ static int lapic_resume(struct sys_device *dev)
*/

static struct sysdev_class lapic_sysclass = {
- set_kset_name("lapic"),
+ .name = "lapic",
.resume = lapic_resume,
.suspend = lapic_suspend,
};
diff --git a/arch/x86/kernel/apic_64.c b/arch/x86/kernel/apic_64.c
index f28ccb5..fa6cdee 100644
--- a/arch/x86/kernel/apic_64.c
+++ b/arch/x86/kernel/apic_64.c
@@ -639,7 +639,7 @@ static int lapic_resume(struct sys_device *dev)
}

static struct sysdev_class lapic_sysclass = {
- set_kset_name("lapic"),
+ .name = "lapic",
.resume = lapic_resume,
.suspend = lapic_suspend,
};
diff --git a/arch/x86/kernel/cpu/mcheck/mce_64.c b/arch/x86/kernel/cpu/mcheck/mce_64.c
index 4b21d29..242e866 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -745,7 +745,7 @@ static void mce_restart(void)

static struct sysdev_class mce_sysclass = {
.resume = mce_resume,
- set_kset_name("machinecheck"),
+ .name = "machinecheck",
};

DEFINE_PER_CPU(struct sys_device, device_mce);
diff --git a/arch/x86/kernel/i8237.c b/arch/x86/kernel/i8237.c
index 2931383..dbd6c1d 100644
--- a/arch/x86/kernel/i8237.c
+++ b/arch/x86/kernel/i8237.c
@@ -51,7 +51,7 @@ static int i8237A_suspend(struct sys_device *dev, pm_message_t state)
}

static struct sysdev_class i8237_sysdev_class = {
- set_kset_name("i8237"),
+ .name = "i8237",
.suspend = i8237A_suspend,
.resume = i8237A_resume,
};
diff --git a/arch/x86/kernel/i8259_32.c b/arch/x86/kernel/i8259_32.c
index f634fc7..5f3496d 100644
--- a/arch/x86/kernel/i8259_32.c
+++ b/arch/x86/kernel/i8259_32.c
@@ -258,7 +258,7 @@ static int i8259A_shutdown(struct sys_device *dev)
}

static struct sysdev_class i8259_sysdev_class = {
- set_kset_name("i8259"),
+ .name = "i8259",
.suspend = i8259A_suspend,
.resume = i8259A_resume,
.shutdown = i8259A_shutdown,
diff --git a/arch/x86/kernel/i8259_64.c b/arch/x86/kernel/i8259_64.c
index 3f27ea0..ba6d572 100644
--- a/arch/x86/kernel/i8259_64.c
+++ b/arch/x86/kernel/i8259_64.c
@@ -370,7 +370,7 @@ static int i8259A_shutdown(struct sys_device *dev)
}

static struct sysdev_class i8259_sysdev_class = {
- set_kset_name("i8259"),
+ .name = "i8259",
.suspend = i8259A_suspend,
.resume = i8259A_resume,
.shutdown = i8259A_shutdown,
diff --git a/arch/x86/kernel/io_apic_32.c b/arch/x86/kernel/io_apic_32.c
index a6b1490..ab77f19 100644
--- a/arch/x86/kernel/io_apic_32.c
+++ b/arch/x86/kernel/io_apic_32.c
@@ -2401,7 +2401,7 @@ static int ioapic_resume(struct sys_device *dev)
}

static struct sysdev_class ioapic_sysdev_class = {
- set_kset_name("ioapic"),
+ .name = "ioapic",
.suspend = ioapic_suspend,
.resume = ioapic_resume,
};
diff --git a/arch/x86/kernel/io_apic_64.c b/arch/x86/kernel/io_apic_64.c
index cbac167..23a3ac0 100644
--- a/arch/x86/kernel/io_apic_64.c
+++ b/arch/x86/kernel/io_apic_64.c
@@ -1850,7 +1850,7 @@ static int ioapic_resume(struct sys_device *dev)
}

static struct sysdev_class ioapic_sysdev_class = {
- set_kset_name("ioapic"),
+ .name = "ioapic",
.suspend = ioapic_suspend,
.resume = ioapic_resume,
};
diff --git a/arch/x86/kernel/nmi_32.c b/arch/x86/kernel/nmi_32.c
index 852db29..4f4bfd3 100644
--- a/arch/x86/kernel/nmi_32.c
+++ b/arch/x86/kernel/nmi_32.c
@@ -176,7 +176,7 @@ static int lapic_nmi_resume(struct sys_device *dev)


static struct sysdev_class nmi_sysclass = {
- set_kset_name("lapic_nmi"),
+ .name = "lapic_nmi",
.resume = lapic_nmi_resume,
.suspend = lapic_nmi_suspend,
};
diff --git a/arch/x86/kernel/nmi_64.c b/arch/x86/kernel/nmi_64.c
index 4253c4e..c3d1476 100644
--- a/arch/x86/kernel/nmi_64.c
+++ b/arch/x86/kernel/nmi_64.c
@@ -211,7 +211,7 @@ static int lapic_nmi_resume(struct sys_device *dev)
}

static struct sysdev_class nmi_sysclass = {
- set_kset_name("lapic_nmi"),
+ .name = "lapic_nmi",
.resume = lapic_nmi_resume,
.suspend = lapic_nmi_suspend,
};
diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 944bbcd..c8ab79e 100644
--- a/arch/x86/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
@@ -51,7 +51,7 @@ static int nmi_resume(struct sys_device *dev)


static struct sysdev_class oprofile_sysclass = {
- set_kset_name("oprofile"),
+ .name = "oprofile",
.resume = nmi_resume,
.suspend = nmi_suspend,
};
diff --git a/drivers/acpi/pci_link.c b/drivers/acpi/pci_link.c
index c9f526e..5400ea1 100644
--- a/drivers/acpi/pci_link.c
+++ b/drivers/acpi/pci_link.c
@@ -911,7 +911,7 @@ __setup("acpi_irq_balance", acpi_irq_balance_set);

/* FIXME: we will remove this interface after all drivers call pci_disable_device */
static struct sysdev_class irqrouter_sysdev_class = {
- set_kset_name("irqrouter"),
+ .name = "irqrouter",
.resume = irqrouter_resume,
};

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 61fd26c..b962a76 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -466,7 +466,6 @@ static struct kset_uevent_ops class_uevent_ops = {
* entirely soon.
*/
static struct kset class_obj_subsys = {
- .kobj = { .k_name = "class_obj", },
.uevent_ops = &class_uevent_ops,
};

@@ -872,6 +871,7 @@ int __init classes_init(void)
/* ick, this is ugly, the things we go through to keep from showing up
* in sysfs... */
kset_init(&class_obj_subsys);
+ kobject_set_name(&class_obj_subsys.kobj, "class_obj");
if (!class_obj_subsys.kobj.parent)
class_obj_subsys.kobj.parent = &class_obj_subsys.kobj;
return 0;
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 4054507..c5885f5 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -14,7 +14,7 @@
#include "base.h"

struct sysdev_class cpu_sysdev_class = {
- set_kset_name("cpu"),
+ .name = "cpu",
};
EXPORT_SYMBOL(cpu_sysdev_class);

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 7868707..7ae413f 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -26,7 +26,7 @@
#define MEMORY_CLASS_NAME "memory"

static struct sysdev_class memory_sysdev_class = {
- set_kset_name(MEMORY_CLASS_NAME),
+ .name = MEMORY_CLASS_NAME,
};

static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj)
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 88eeed7..e59861f 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -15,7 +15,7 @@
#include <linux/device.h>

static struct sysdev_class node_class = {
- set_kset_name("node"),
+ .name = "node",
};


diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index e666441..2f79c55 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -136,6 +136,7 @@ int sysdev_class_register(struct sysdev_class * cls)
cls->kset.kobj.parent = &system_kset->kobj;
cls->kset.kobj.ktype = &ktype_sysdev_class;
cls->kset.kobj.kset = system_kset;
+ kobject_set_name(&cls->kset.kobj, cls->name);
return kset_register(&cls->kset);
}

diff --git a/drivers/edac/edac_module.c b/drivers/edac/edac_module.c
index e0c4a40..7e1374a 100644
--- a/drivers/edac/edac_module.c
+++ b/drivers/edac/edac_module.c
@@ -31,7 +31,7 @@ struct workqueue_struct *edac_workqueue;
* need to export to other files in this modules
*/
static struct sysdev_class edac_class = {
- set_kset_name("edac"),
+ .name = "edac",
};
static int edac_class_valid;

diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 47c10b8..c0f372f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -3451,7 +3451,7 @@ static int kvm_resume(struct sys_device *dev)
}

static struct sysdev_class kvm_sysdev_class = {
- set_kset_name("kvm"),
+ .name = "kvm",
.suspend = kvm_suspend,
.resume = kvm_resume,
};
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 6123c70..ac420b1 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -2796,7 +2796,7 @@ static int pmu_sys_resume(struct sys_device *sysdev)
#endif /* CONFIG_PM_SLEEP && CONFIG_PPC32 */

static struct sysdev_class pmu_sysclass = {
- set_kset_name("pmu"),
+ .name = "pmu",
};

static struct sys_device device_pmu = {
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 7663841..a3fdc57 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -464,7 +464,7 @@ int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd)
res = sas_phy_reset(phy, 1);
if (res)
SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
- phy->dev.kobj.k_name,
+ kobject_name(&phy->dev.kobj),
res);
if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
return SUCCESS;
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 504ac0e..4adbe1d 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -61,7 +61,7 @@ enum kobject_action {
};

struct kobject {
- const char * k_name;
+ const char *name;
struct kref kref;
struct list_head entry;
struct kobject * parent;
@@ -69,7 +69,6 @@ struct kobject {
struct kobj_type * ktype;
struct sysfs_dirent * sd;
unsigned int state_initialized:1;
- unsigned int state_name_set:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
@@ -80,7 +79,7 @@ extern int kobject_set_name(struct kobject *, const char *, ...)

static inline const char * kobject_name(const struct kobject * kobj)
{
- return kobj->k_name;
+ return kobj->name;
}

extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
@@ -189,14 +188,6 @@ static inline struct kobj_type *get_ktype(struct kobject *kobj)

extern struct kobject * kset_find_obj(struct kset *, const char *);

-
-/*
- * Use this when initializing an embedded kset with no other
- * fields to initialize.
- */
-#define set_kset_name(str) .kset = { .kobj = { .k_name = str } }
-
-
/* The global /sys/kernel/ kobject for people to chain off of */
extern struct kobject *kernel_kobj;
/* The global /sys/hypervisor/ kobject for people to chain off of */
diff --git a/include/linux/sysdev.h b/include/linux/sysdev.h
index e285746..f752e73 100644
--- a/include/linux/sysdev.h
+++ b/include/linux/sysdev.h
@@ -29,6 +29,7 @@
struct sys_device;

struct sysdev_class {
+ const char *name;
struct list_head drivers;

/* Default operations for these types of devices */
diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
index e3055ba..092e4c6 100644
--- a/kernel/rtmutex-tester.c
+++ b/kernel/rtmutex-tester.c
@@ -394,7 +394,7 @@ static SYSDEV_ATTR(status, 0600, sysfs_test_status, NULL);
static SYSDEV_ATTR(command, 0600, NULL, sysfs_test_command);

static struct sysdev_class rttest_sysclass = {
- set_kset_name("rttest"),
+ .name = "rttest",
};

static int init_test_thread(int id)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index c8a9d13..8d6125a 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -441,7 +441,7 @@ static SYSDEV_ATTR(available_clocksource, 0600,
sysfs_show_available_clocksources, NULL);

static struct sysdev_class clocksource_sysclass = {
- set_kset_name("clocksource"),
+ .name = "clocksource",
};

static struct sys_device device_clocksource = {
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index e5e466b..ab46ae8 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -335,9 +335,9 @@ static int timekeeping_suspend(struct sys_device *dev, pm_message_t state)

/* sysfs resume/suspend bits for timekeeping */
static struct sysdev_class timekeeping_sysclass = {
+ .name = "timekeeping",
.resume = timekeeping_resume,
.suspend = timekeeping_suspend,
- set_kset_name("timekeeping"),
};

static struct sys_device device_timer = {
diff --git a/lib/kobject.c b/lib/kobject.c
index a077373..8dc3245 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -165,7 +165,7 @@ static int kobject_add_internal(struct kobject *kobj)
if (!kobj)
return -ENOENT;

- if (!kobj->k_name || !kobj->k_name[0]) {
+ if (!kobj->name || !kobj->name[0]) {
pr_debug("kobject: (%p): attempted to be registered with empty "
"name!\n", kobj);
WARN_ON(1);
@@ -228,13 +228,11 @@ static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
if (!name)
return -ENOMEM;

-
/* Free the old name, if necessary. */
- kfree(kobj->k_name);
+ kfree(kobj->name);

/* Now, set the new name */
- kobj->k_name = name;
- kobj->state_name_set = 1;
+ kobj->name = name;

return 0;
}
@@ -295,7 +293,6 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
kref_init(&kobj->kref);
INIT_LIST_HEAD(&kobj->entry);
kobj->ktype = ktype;
- kobj->state_name_set = 0;
kobj->state_in_sysfs = 0;
kobj->state_add_uevent_sent = 0;
kobj->state_remove_uevent_sent = 0;
@@ -551,8 +548,7 @@ struct kobject * kobject_get(struct kobject * kobj)
static void kobject_cleanup(struct kobject *kobj)
{
struct kobj_type *t = get_ktype(kobj);
- const char *name = kobj->k_name;
- int name_set = kobj->state_name_set;
+ const char *name = kobj->name;

pr_debug("kobject: '%s' (%p): %s\n",
kobject_name(kobj), kobj, __FUNCTION__);
@@ -583,7 +579,7 @@ static void kobject_cleanup(struct kobject *kobj)
}

/* free name if we allocated it */
- if (name_set && name) {
+ if (name) {
pr_debug("kobject: '%s': free name\n", name);
kfree(name);
}
--
1.5.3.8

2008-01-25 08:22:35

by Greg KH

[permalink] [raw]
Subject: [PATCH 175/196] Kobject: remove kobject_unregister() as no one uses it anymore

There are no in-kernel users of kobject_unregister() so it should be
removed.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 2 --
lib/kobject.c | 17 -----------------
2 files changed, 0 insertions(+), 19 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index be03ce8..504ac0e 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -101,8 +101,6 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,
extern int __must_check kobject_rename(struct kobject *, const char *new_name);
extern int __must_check kobject_move(struct kobject *, struct kobject *);

-extern void kobject_unregister(struct kobject *);
-
extern struct kobject * kobject_get(struct kobject *);
extern void kobject_put(struct kobject *);

diff --git a/lib/kobject.c b/lib/kobject.c
index 462946e..a077373 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -533,22 +533,6 @@ void kobject_del(struct kobject * kobj)
}

/**
- * kobject_unregister - remove object from hierarchy and decrement refcount.
- * @kobj: object going away.
- */
-
-void kobject_unregister(struct kobject * kobj)
-{
- if (!kobj)
- return;
- pr_debug("kobject: '%s' (%p): %s\n",
- kobject_name(kobj), kobj, __FUNCTION__);
- kobject_uevent(kobj, KOBJ_REMOVE);
- kobject_del(kobj);
- kobject_put(kobj);
-}
-
-/**
* kobject_get - increment refcount for object.
* @kobj: object.
*/
@@ -877,7 +861,6 @@ struct kset *kset_create_and_add(const char *name,
}
EXPORT_SYMBOL_GPL(kset_create_and_add);

-EXPORT_SYMBOL(kobject_unregister);
EXPORT_SYMBOL(kobject_get);
EXPORT_SYMBOL(kobject_put);
EXPORT_SYMBOL(kobject_del);
--
1.5.3.8

2008-01-25 08:22:52

by Greg KH

[permalink] [raw]
Subject: [PATCH 195/196] Kobject: fix coding style issues in kobject c files

Clean up the kobject.c and kobject_uevent.c files to follow the
proper coding style rules.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
lib/kobject.c | 139 +++++++++++++++++++++++---------------------------
lib/kobject_uevent.c | 7 +--
2 files changed, 67 insertions(+), 79 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index 8dc3245..1d63ead 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -18,58 +18,57 @@
#include <linux/stat.h>
#include <linux/slab.h>

-/**
- * populate_dir - populate directory with attributes.
- * @kobj: object we're working on.
- *
- * Most subsystems have a set of default attributes that
- * are associated with an object that registers with them.
- * This is a helper called during object registration that
- * loops through the default attributes of the subsystem
- * and creates attributes files for them in sysfs.
+/*
+ * populate_dir - populate directory with attributes.
+ * @kobj: object we're working on.
*
+ * Most subsystems have a set of default attributes that are associated
+ * with an object that registers with them. This is a helper called during
+ * object registration that loops through the default attributes of the
+ * subsystem and creates attributes files for them in sysfs.
*/
-
-static int populate_dir(struct kobject * kobj)
+static int populate_dir(struct kobject *kobj)
{
- struct kobj_type * t = get_ktype(kobj);
- struct attribute * attr;
+ struct kobj_type *t = get_ktype(kobj);
+ struct attribute *attr;
int error = 0;
int i;
-
+
if (t && t->default_attrs) {
for (i = 0; (attr = t->default_attrs[i]) != NULL; i++) {
- if ((error = sysfs_create_file(kobj,attr)))
+ error = sysfs_create_file(kobj, attr);
+ if (error)
break;
}
}
return error;
}

-static int create_dir(struct kobject * kobj)
+static int create_dir(struct kobject *kobj)
{
int error = 0;
if (kobject_name(kobj)) {
error = sysfs_create_dir(kobj);
if (!error) {
- if ((error = populate_dir(kobj)))
+ error = populate_dir(kobj);
+ if (error)
sysfs_remove_dir(kobj);
}
}
return error;
}

-static inline struct kobject * to_kobj(struct list_head * entry)
+static inline struct kobject *to_kobj(struct list_head *entry)
{
- return container_of(entry,struct kobject,entry);
+ return container_of(entry, struct kobject, entry);
}

static int get_kobj_path_length(struct kobject *kobj)
{
int length = 1;
- struct kobject * parent = kobj;
+ struct kobject *parent = kobj;

- /* walk up the ancestors until we hit the one pointing to the
+ /* walk up the ancestors until we hit the one pointing to the
* root.
* Add 1 to strlen for leading '/' of each level.
*/
@@ -84,19 +83,19 @@ static int get_kobj_path_length(struct kobject *kobj)

static void fill_kobj_path(struct kobject *kobj, char *path, int length)
{
- struct kobject * parent;
+ struct kobject *parent;

--length;
for (parent = kobj; parent; parent = parent->parent) {
int cur = strlen(kobject_name(parent));
/* back up enough to print this name with '/' */
length -= cur;
- strncpy (path + length, kobject_name(parent), cur);
+ strncpy(path + length, kobject_name(parent), cur);
*(path + --length) = '/';
}

pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
- kobj, __FUNCTION__,path);
+ kobj, __FUNCTION__, path);
}

/**
@@ -148,7 +147,7 @@ static void kobj_kset_leave(struct kobject *kobj)
kset_put(kobj->kset);
}

-static void kobject_init_internal(struct kobject * kobj)
+static void kobject_init_internal(struct kobject *kobj)
{
if (!kobj)
return;
@@ -160,7 +159,7 @@ static void kobject_init_internal(struct kobject * kobj)
static int kobject_add_internal(struct kobject *kobj)
{
int error = 0;
- struct kobject * parent;
+ struct kobject *parent;

if (!kobj)
return -ENOENT;
@@ -185,7 +184,7 @@ static int kobject_add_internal(struct kobject *kobj)
pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
kobject_name(kobj), kobj, __FUNCTION__,
parent ? kobject_name(parent) : "<NULL>",
- kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>" );
+ kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>");

error = create_dir(kobj);
if (error) {
@@ -399,12 +398,11 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
EXPORT_SYMBOL_GPL(kobject_init_and_add);

/**
- * kobject_rename - change the name of an object
- * @kobj: object in question.
- * @new_name: object's new name
+ * kobject_rename - change the name of an object
+ * @kobj: object in question.
+ * @new_name: object's new name
*/
-
-int kobject_rename(struct kobject * kobj, const char *new_name)
+int kobject_rename(struct kobject *kobj, const char *new_name)
{
int error = 0;
const char *devpath = NULL;
@@ -461,11 +459,10 @@ out:
}

/**
- * kobject_move - move object to another parent
- * @kobj: object in question.
- * @new_parent: object's new parent (can be NULL)
+ * kobject_move - move object to another parent
+ * @kobj: object in question.
+ * @new_parent: object's new parent (can be NULL)
*/
-
int kobject_move(struct kobject *kobj, struct kobject *new_parent)
{
int error;
@@ -513,11 +510,10 @@ out:
}

/**
- * kobject_del - unlink kobject from hierarchy.
- * @kobj: object.
+ * kobject_del - unlink kobject from hierarchy.
+ * @kobj: object.
*/
-
-void kobject_del(struct kobject * kobj)
+void kobject_del(struct kobject *kobj)
{
if (!kobj)
return;
@@ -530,11 +526,10 @@ void kobject_del(struct kobject * kobj)
}

/**
- * kobject_get - increment refcount for object.
- * @kobj: object.
+ * kobject_get - increment refcount for object.
+ * @kobj: object.
*/
-
-struct kobject * kobject_get(struct kobject * kobj)
+struct kobject *kobject_get(struct kobject *kobj)
{
if (kobj)
kref_get(&kobj->kref);
@@ -591,12 +586,12 @@ static void kobject_release(struct kref *kref)
}

/**
- * kobject_put - decrement refcount for object.
- * @kobj: object.
+ * kobject_put - decrement refcount for object.
+ * @kobj: object.
*
- * Decrement the refcount, and if 0, call kobject_cleanup().
+ * Decrement the refcount, and if 0, call kobject_cleanup().
*/
-void kobject_put(struct kobject * kobj)
+void kobject_put(struct kobject *kobj)
{
if (kobj)
kref_put(&kobj->kref, kobject_release);
@@ -670,11 +665,10 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
EXPORT_SYMBOL_GPL(kobject_create_and_add);

/**
- * kset_init - initialize a kset for use
- * @k: kset
+ * kset_init - initialize a kset for use
+ * @k: kset
*/
-
-void kset_init(struct kset * k)
+void kset_init(struct kset *k)
{
kobject_init_internal(&k->kobj);
INIT_LIST_HEAD(&k->list);
@@ -712,11 +706,10 @@ struct sysfs_ops kobj_sysfs_ops = {
};

/**
- * kset_register - initialize and add a kset.
- * @k: kset.
+ * kset_register - initialize and add a kset.
+ * @k: kset.
*/
-
-int kset_register(struct kset * k)
+int kset_register(struct kset *k)
{
int err;

@@ -731,39 +724,35 @@ int kset_register(struct kset * k)
return 0;
}

-
/**
- * kset_unregister - remove a kset.
- * @k: kset.
+ * kset_unregister - remove a kset.
+ * @k: kset.
*/
-
-void kset_unregister(struct kset * k)
+void kset_unregister(struct kset *k)
{
if (!k)
return;
kobject_put(&k->kobj);
}

-
/**
- * kset_find_obj - search for object in kset.
- * @kset: kset we're looking in.
- * @name: object's name.
+ * kset_find_obj - search for object in kset.
+ * @kset: kset we're looking in.
+ * @name: object's name.
*
- * Lock kset via @kset->subsys, and iterate over @kset->list,
- * looking for a matching kobject. If matching object is found
- * take a reference and return the object.
+ * Lock kset via @kset->subsys, and iterate over @kset->list,
+ * looking for a matching kobject. If matching object is found
+ * take a reference and return the object.
*/
-
-struct kobject * kset_find_obj(struct kset * kset, const char * name)
+struct kobject *kset_find_obj(struct kset *kset, const char *name)
{
- struct list_head * entry;
- struct kobject * ret = NULL;
+ struct list_head *entry;
+ struct kobject *ret = NULL;

spin_lock(&kset->list_lock);
- list_for_each(entry,&kset->list) {
- struct kobject * k = to_kobj(entry);
- if (kobject_name(k) && !strcmp(kobject_name(k),name)) {
+ list_for_each(entry, &kset->list) {
+ struct kobject *k = to_kobj(entry);
+ if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
ret = kobject_get(k);
break;
}
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index b021e67..5a402e2 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -238,11 +238,12 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
retval = add_uevent_var(env, "HOME=/");
if (retval)
goto exit;
- retval = add_uevent_var(env, "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
+ retval = add_uevent_var(env,
+ "PATH=/sbin:/bin:/usr/sbin:/usr/bin");
if (retval)
goto exit;

- call_usermodehelper (argv[0], argv, env->envp, UMH_WAIT_EXEC);
+ call_usermodehelper(argv[0], argv, env->envp, UMH_WAIT_EXEC);
}

exit:
@@ -250,7 +251,6 @@ exit:
kfree(env);
return retval;
}
-
EXPORT_SYMBOL_GPL(kobject_uevent_env);

/**
@@ -266,7 +266,6 @@ int kobject_uevent(struct kobject *kobj, enum kobject_action action)
{
return kobject_uevent_env(kobj, action, NULL);
}
-
EXPORT_SYMBOL_GPL(kobject_uevent);

/**
--
1.5.3.8

2008-01-25 08:23:24

by Greg KH

[permalink] [raw]
Subject: [PATCH 152/196] Driver core: clean up debugging messages

The driver core debugging messages are a mess. This provides a unified
message that makes them actually useful.

The format for new kobject debug messages should be:
driver/bus/class: 'OBJECT_NAME': FUNCTION_NAME: message.\n

Note, the class code is not changed in this patch due to pending patches
in my queue that this would conflict with. A later patch will clean
them up.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 14 +++++++-------
drivers/base/core.c | 23 +++++++++++++----------
drivers/base/dd.c | 16 ++++++++--------
3 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index aa0c986..937fc10 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -80,7 +80,7 @@ static void driver_release(struct kobject *kobj)
{
struct driver_private *drv_priv = to_driver(kobj);

- pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
+ pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__);
kfree(drv_priv);
}

@@ -446,7 +446,7 @@ int bus_add_device(struct device * dev)
int error = 0;

if (bus) {
- pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
+ pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id);
error = device_add_attrs(bus, dev);
if (error)
goto out_put;
@@ -519,7 +519,7 @@ void bus_remove_device(struct device * dev)
dev->is_registered = 0;
klist_del(&dev->knode_bus);
}
- pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id);
+ pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev->bus_id);
device_release_driver(dev);
bus_put(dev->bus);
}
@@ -637,7 +637,7 @@ int bus_add_driver(struct device_driver *drv)
if (!bus)
return -EINVAL;

- pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
+ pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);

priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -707,7 +707,7 @@ void bus_remove_driver(struct device_driver * drv)
driver_remove_attrs(drv->bus, drv);
driver_remove_file(drv, &driver_attr_uevent);
klist_remove(&drv->p->knode_bus);
- pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
+ pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name);
driver_detach(drv);
module_remove_driver(drv);
kobject_unregister(&drv->p->kobj);
@@ -907,7 +907,7 @@ int bus_register(struct bus_type * bus)
if (retval)
goto bus_attrs_fail;

- pr_debug("bus type '%s' registered\n", bus->name);
+ pr_debug("bus: '%s': registered\n", bus->name);
return 0;

bus_attrs_fail:
@@ -934,7 +934,7 @@ out:
*/
void bus_unregister(struct bus_type * bus)
{
- pr_debug("bus %s: unregistering\n", bus->name);
+ pr_debug("bus: '%s': unregistering\n", bus->name);
bus_remove_attrs(bus);
remove_probe_files(bus);
kset_unregister(bus->p->drivers_kset);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 414a480..22fdf32 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -193,15 +193,16 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
if (dev->bus && dev->bus->uevent) {
retval = dev->bus->uevent(dev, env);
if (retval)
- pr_debug ("%s: bus uevent() returned %d\n",
- __FUNCTION__, retval);
+ pr_debug("device: '%s': %s: bus uevent() returned %d\n",
+ dev->bus_id, __FUNCTION__, retval);
}

/* have the class specific function add its stuff */
if (dev->class && dev->class->dev_uevent) {
retval = dev->class->dev_uevent(dev, env);
if (retval)
- pr_debug("%s: class uevent() returned %d\n",
+ pr_debug("device: '%s': %s: class uevent() "
+ "returned %d\n", dev->bus_id,
__FUNCTION__, retval);
}

@@ -209,7 +210,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
if (dev->type && dev->type->uevent) {
retval = dev->type->uevent(dev, env);
if (retval)
- pr_debug("%s: dev_type uevent() returned %d\n",
+ pr_debug("device: '%s': %s: dev_type uevent() "
+ "returned %d\n", dev->bus_id,
__FUNCTION__, retval);
}

@@ -751,7 +753,7 @@ int device_add(struct device *dev)
goto Error;
}

- pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
+ pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);

parent = get_device(dev->parent);
error = setup_parent(dev, parent);
@@ -1020,7 +1022,7 @@ void device_del(struct device * dev)
*/
void device_unregister(struct device * dev)
{
- pr_debug("DEV: Unregistering device. ID = '%s'\n", dev->bus_id);
+ pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
device_del(dev);
put_device(dev);
}
@@ -1116,7 +1118,7 @@ EXPORT_SYMBOL_GPL(device_remove_file);

static void device_create_release(struct device *dev)
{
- pr_debug("%s called for %s\n", __FUNCTION__, dev->bus_id);
+ pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
kfree(dev);
}

@@ -1259,7 +1261,8 @@ int device_rename(struct device *dev, char *new_name)
if (!dev)
return -EINVAL;

- pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name);
+ pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id,
+ __FUNCTION__, new_name);

#ifdef CONFIG_SYSFS_DEPRECATED
if ((dev->class) && (dev->parent))
@@ -1378,8 +1381,8 @@ int device_move(struct device *dev, struct device *new_parent)
put_device(new_parent);
goto out;
}
- pr_debug("DEVICE: moving '%s' to '%s'\n", dev->bus_id,
- new_parent ? new_parent->bus_id : "<NULL>");
+ pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
+ __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
error = kobject_move(&dev->kobj, new_parent_kobj);
if (error) {
put_device(new_parent);
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 87a348c..5492264 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -34,8 +34,8 @@ static void driver_bound(struct device *dev)
return;
}

- pr_debug("bound device '%s' to driver '%s'\n",
- dev->bus_id, dev->driver->name);
+ pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id,
+ __FUNCTION__, dev->driver->name);

if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -102,8 +102,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
int ret = 0;

atomic_inc(&probe_count);
- pr_debug("%s: Probing driver %s with device %s\n",
- drv->bus->name, drv->name, dev->bus_id);
+ pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
+ drv->bus->name, __FUNCTION__, drv->name, dev->bus_id);
WARN_ON(!list_empty(&dev->devres_head));

dev->driver = drv;
@@ -125,8 +125,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)

driver_bound(dev);
ret = 1;
- pr_debug("%s: Bound Device %s to Driver %s\n",
- drv->bus->name, dev->bus_id, drv->name);
+ pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
+ drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);
goto done;

probe_failed:
@@ -192,8 +192,8 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
if (drv->bus->match && !drv->bus->match(dev, drv))
goto done;

- pr_debug("%s: Matched Device %s with Driver %s\n",
- drv->bus->name, dev->bus_id, drv->name);
+ pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
+ drv->bus->name, __FUNCTION__, dev->bus_id, drv->name);

ret = really_probe(dev, drv);

--
1.5.3.8

2008-01-25 08:23:46

by Greg KH

[permalink] [raw]
Subject: [PATCH 133/196] Kobject: convert kernel/params.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/params.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/kernel/params.c b/kernel/params.c
index 97e0923..1078b14 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -561,11 +561,9 @@ static void __init kernel_param_sysfs_setup(const char *name,

mk->mod = THIS_MODULE;
mk->kobj.kset = module_kset;
- mk->kobj.ktype = &module_ktype;
- kobject_set_name(&mk->kobj, name);
- kobject_init(&mk->kobj);
- ret = kobject_add(&mk->kobj);
+ ret = kobject_init_and_add(&mk->kobj, &module_ktype, NULL, "%s", name);
if (ret) {
+ kobject_put(&mk->kobj);
printk(KERN_ERR "Module '%s' failed to be added to sysfs, "
"error number %d\n", name, ret);
printk(KERN_ERR "The system will be unstable now.\n");
--
1.5.3.8

2008-01-25 08:24:20

by Greg KH

[permalink] [raw]
Subject: [PATCH 194/196] Kobject: fix coding style issues in kobject.h

Finally clean up the odd spaces and other mess in kobject.h

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
include/linux/kobject.h | 67 ++++++++++++++++++++++++-----------------------
1 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 4adbe1d..caa3f41 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -3,15 +3,14 @@
*
* Copyright (c) 2002-2003 Patrick Mochel
* Copyright (c) 2002-2003 Open Source Development Labs
- * Copyright (c) 2006-2007 Greg Kroah-Hartman <[email protected]>
- * Copyright (c) 2006-2007 Novell Inc.
+ * Copyright (c) 2006-2008 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2006-2008 Novell Inc.
*
* This file is released under the GPLv2.
*
- *
* Please read Documentation/kobject.txt before using the kobject
* interface, ESPECIALLY the parts about reference counts and object
- * destructors.
+ * destructors.
*/

#ifndef _KOBJECT_H_
@@ -64,20 +63,20 @@ struct kobject {
const char *name;
struct kref kref;
struct list_head entry;
- struct kobject * parent;
- struct kset * kset;
- struct kobj_type * ktype;
- struct sysfs_dirent * sd;
+ struct kobject *parent;
+ struct kset *kset;
+ struct kobj_type *ktype;
+ struct sysfs_dirent *sd;
unsigned int state_initialized:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
};

-extern int kobject_set_name(struct kobject *, const char *, ...)
- __attribute__((format(printf,2,3)));
+extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
+ __attribute__((format(printf, 2, 3)));

-static inline const char * kobject_name(const struct kobject * kobj)
+static inline const char *kobject_name(const struct kobject *kobj)
{
return kobj->name;
}
@@ -91,7 +90,7 @@ extern int __must_check kobject_init_and_add(struct kobject *kobj,
struct kobject *parent,
const char *fmt, ...);

-extern void kobject_del(struct kobject *);
+extern void kobject_del(struct kobject *kobj);

extern struct kobject * __must_check kobject_create(void);
extern struct kobject * __must_check kobject_create_and_add(const char *name,
@@ -100,15 +99,15 @@ extern struct kobject * __must_check kobject_create_and_add(const char *name,
extern int __must_check kobject_rename(struct kobject *, const char *new_name);
extern int __must_check kobject_move(struct kobject *, struct kobject *);

-extern struct kobject * kobject_get(struct kobject *);
-extern void kobject_put(struct kobject *);
+extern struct kobject *kobject_get(struct kobject *kobj);
+extern void kobject_put(struct kobject *kobj);

-extern char * kobject_get_path(struct kobject *, gfp_t);
+extern char *kobject_get_path(struct kobject *kobj, gfp_t flag);

struct kobj_type {
- void (*release)(struct kobject *);
- struct sysfs_ops * sysfs_ops;
- struct attribute ** default_attrs;
+ void (*release)(struct kobject *kobj);
+ struct sysfs_ops *sysfs_ops;
+ struct attribute **default_attrs;
};

struct kobj_uevent_env {
@@ -153,30 +152,30 @@ extern struct sysfs_ops kobj_sysfs_ops;
* desired.
*/
struct kset {
- struct list_head list;
- spinlock_t list_lock;
- struct kobject kobj;
- struct kset_uevent_ops *uevent_ops;
+ struct list_head list;
+ spinlock_t list_lock;
+ struct kobject kobj;
+ struct kset_uevent_ops *uevent_ops;
};

-extern void kset_init(struct kset * k);
-extern int __must_check kset_register(struct kset * k);
-extern void kset_unregister(struct kset * k);
+extern void kset_init(struct kset *kset);
+extern int __must_check kset_register(struct kset *kset);
+extern void kset_unregister(struct kset *kset);
extern struct kset * __must_check kset_create_and_add(const char *name,
struct kset_uevent_ops *u,
struct kobject *parent_kobj);

-static inline struct kset * to_kset(struct kobject * kobj)
+static inline struct kset *to_kset(struct kobject *kobj)
{
- return kobj ? container_of(kobj,struct kset,kobj) : NULL;
+ return kobj ? container_of(kobj, struct kset, kobj) : NULL;
}

-static inline struct kset * kset_get(struct kset * k)
+static inline struct kset *kset_get(struct kset *k)
{
return k ? to_kset(kobject_get(&k->kobj)) : NULL;
}

-static inline void kset_put(struct kset * k)
+static inline void kset_put(struct kset *k)
{
kobject_put(&k->kobj);
}
@@ -186,7 +185,7 @@ static inline struct kobj_type *get_ktype(struct kobject *kobj)
return kobj->ktype;
}

-extern struct kobject * kset_find_obj(struct kset *, const char *);
+extern struct kobject *kset_find_obj(struct kset *, const char *);

/* The global /sys/kernel/ kobject for people to chain off of */
extern struct kobject *kernel_kobj;
@@ -208,18 +207,20 @@ int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
int kobject_action_type(const char *buf, size_t count,
enum kobject_action *type);
#else
-static inline int kobject_uevent(struct kobject *kobj, enum kobject_action action)
+static inline int kobject_uevent(struct kobject *kobj,
+ enum kobject_action action)
{ return 0; }
static inline int kobject_uevent_env(struct kobject *kobj,
enum kobject_action action,
char *envp[])
{ return 0; }

-static inline int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
+static inline int add_uevent_var(struct kobj_uevent_env *env,
+ const char *format, ...)
{ return 0; }

static inline int kobject_action_type(const char *buf, size_t count,
- enum kobject_action *type)
+ enum kobject_action *type)
{ return -EINVAL; }
#endif

--
1.5.3.8

2008-01-25 08:24:42

by Greg KH

[permalink] [raw]
Subject: [PATCH 138/196] driver core: add way to get to bus kset

This allows an easier way to get to the kset associated with a struct
bus_type (you have three to choose from...) This will make it easier to
move these fields to be dynamic in a future patch.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 6 ++++++
drivers/pci/hotplug/pci_hotplug_core.c | 5 ++++-
include/linux/device.h | 2 ++
3 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 871607b..8335a10 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -935,6 +935,12 @@ int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
}
EXPORT_SYMBOL_GPL(bus_unregister_notifier);

+struct kset *bus_get_kset(struct bus_type *bus)
+{
+ return &bus->subsys;
+}
+EXPORT_SYMBOL_GPL(bus_get_kset);
+
int __init buses_init(void)
{
bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL);
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 0f05e6a..3606d5b 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -699,9 +699,12 @@ int __must_check pci_hp_change_slot_info(struct hotplug_slot *slot,
static int __init pci_hotplug_init (void)
{
int result;
+ struct kset *pci_bus_kset;
+
+ pci_bus_kset = bus_get_kset(&pci_bus_type);

pci_hotplug_slots_kset = kset_create_and_add("slots", NULL,
- &pci_bus_type.subsys.kobj);
+ &pci_bus_kset->kobj);
if (!pci_hotplug_slots_kset) {
result = -ENOMEM;
err("Register subsys error\n");
diff --git a/include/linux/device.h b/include/linux/device.h
index 313e0b3..3cc13c3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -117,6 +117,8 @@ extern int bus_unregister_notifier(struct bus_type *bus,
#define BUS_NOTIFY_UNBIND_DRIVER 0x00000004 /* driver about to be
unbound */

+extern struct kset *bus_get_kset(struct bus_type *bus);
+
struct device_driver {
const char * name;
struct bus_type * bus;
--
1.5.3.8

2008-01-25 08:25:12

by Greg KH

[permalink] [raw]
Subject: [PATCH 187/196] Driver Core: add class iteration api

From: Dave Young <[email protected]>

Add the following class iteration functions for driver use:
class_for_each_device
class_find_device
class_for_each_child
class_find_child

Signed-off-by: Dave Young <[email protected]>
Acked-by: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/class.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/device.h | 9 +++-
2 files changed, 140 insertions(+), 2 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index b962a76..9f737ff 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -809,6 +809,139 @@ void class_device_put(struct class_device *class_dev)
kobject_put(&class_dev->kobj);
}

+/**
+ * class_for_each_device - device iterator
+ * @class: the class we're iterating
+ * @data: data for the callback
+ * @fn: function to be called for each device
+ *
+ * Iterate over @class's list of devices, and call @fn for each,
+ * passing it @data.
+ *
+ * We check the return of @fn each time. If it returns anything
+ * other than 0, we break out and return that value.
+ *
+ * Note, we hold class->sem in this function, so it can not be
+ * re-acquired in @fn, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+int class_for_each_device(struct class *class, void *data,
+ int (*fn)(struct device *, void *))
+{
+ struct device *dev;
+ int error = 0;
+
+ if (!class)
+ return -EINVAL;
+ down(&class->sem);
+ list_for_each_entry(dev, &class->devices, node) {
+ dev = get_device(dev);
+ if (dev) {
+ error = fn(dev, data);
+ put_device(dev);
+ } else
+ error = -ENODEV;
+ if (error)
+ break;
+ }
+ up(&class->sem);
+
+ return error;
+}
+EXPORT_SYMBOL_GPL(class_for_each_device);
+
+/**
+ * class_find_device - device iterator for locating a particular device
+ * @class: the class we're iterating
+ * @data: data for the match function
+ * @match: function to check device
+ *
+ * This is similar to the class_for_each_dev() function above, but it
+ * returns a reference to a device that is 'found' for later use, as
+ * determined by the @match callback.
+ *
+ * The callback should return 0 if the device doesn't match and non-zero
+ * if it does. If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more devices.
+
+ * Note, you will need to drop the reference with put_device() after use.
+ *
+ * We hold class->sem in this function, so it can not be
+ * re-acquired in @match, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+struct device *class_find_device(struct class *class, void *data,
+ int (*match)(struct device *, void *))
+{
+ struct device *dev;
+ int found = 0;
+
+ if (!class)
+ return NULL;
+
+ down(&class->sem);
+ list_for_each_entry(dev, &class->devices, node) {
+ dev = get_device(dev);
+ if (dev) {
+ if (match(dev, data)) {
+ found = 1;
+ break;
+ } else
+ put_device(dev);
+ } else
+ break;
+ }
+ up(&class->sem);
+
+ return found ? dev : NULL;
+}
+EXPORT_SYMBOL_GPL(class_find_device);
+
+/**
+ * class_find_child - device iterator for locating a particular class_device
+ * @class: the class we're iterating
+ * @data: data for the match function
+ * @match: function to check class_device
+ *
+ * This function returns a reference to a class_device that is 'found' for
+ * later use, as determined by the @match callback.
+ *
+ * The callback should return 0 if the class_device doesn't match and non-zero
+ * if it does. If the callback returns non-zero, this function will
+ * return to the caller and not iterate over any more class_devices.
+ *
+ * Note, you will need to drop the reference with class_device_put() after use.
+ *
+ * We hold class->sem in this function, so it can not be
+ * re-acquired in @match, otherwise it will self-deadlocking. For
+ * example, calls to add or remove class members would be verboten.
+ */
+struct class_device *class_find_child(struct class *class, void *data,
+ int (*match)(struct class_device *, void *))
+{
+ struct class_device *dev;
+ int found = 0;
+
+ if (!class)
+ return NULL;
+
+ down(&class->sem);
+ list_for_each_entry(dev, &class->children, node) {
+ dev = class_device_get(dev);
+ if (dev) {
+ if (match(dev, data)) {
+ found = 1;
+ break;
+ } else
+ class_device_put(dev);
+ } else
+ break;
+ }
+ up(&class->sem);
+
+ return found ? dev : NULL;
+}
+EXPORT_SYMBOL_GPL(class_find_child);

int class_interface_register(struct class_interface *class_intf)
{
diff --git a/include/linux/device.h b/include/linux/device.h
index 92ba3a8..cdaf57b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -177,8 +177,7 @@ struct class {
struct list_head devices;
struct list_head interfaces;
struct kset class_dirs;
- struct semaphore sem; /* locks both the children and interfaces lists */
-
+ struct semaphore sem; /* locks children, devices, interfaces */
struct class_attribute * class_attrs;
struct class_device_attribute * class_dev_attrs;
struct device_attribute * dev_attrs;
@@ -196,6 +195,12 @@ struct class {

extern int __must_check class_register(struct class *);
extern void class_unregister(struct class *);
+extern int class_for_each_device(struct class *class, void *data,
+ int (*fn)(struct device *dev, void *data));
+extern struct device *class_find_device(struct class *class, void *data,
+ int (*match)(struct device *, void *));
+extern struct class_device *class_find_child(struct class *class, void *data,
+ int (*match)(struct class_device *, void *));


struct class_attribute {
--
1.5.3.8

2008-01-25 08:25:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 146/196] netiucv: Use device_driver default attribute groups.

From: Cornelia Huck <[email protected]>

CC: Ursula Braun <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/s390/net/netiucv.c | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index c7ea938..d6e93f1 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -2089,6 +2089,11 @@ static struct attribute_group netiucv_drv_attr_group = {
.attrs = netiucv_drv_attrs,
};

+static struct attribute_group *netiucv_drv_attr_groups[] = {
+ &netiucv_drv_attr_group,
+ NULL,
+};
+
static void netiucv_banner(void)
{
PRINT_INFO("NETIUCV driver initialized\n");
@@ -2113,7 +2118,6 @@ static void __exit netiucv_exit(void)
netiucv_unregister_device(dev);
}

- sysfs_remove_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
driver_unregister(&netiucv_driver);
iucv_unregister(&netiucv_handler, 1);
iucv_unregister_dbf_views();
@@ -2133,6 +2137,7 @@ static int __init netiucv_init(void)
if (rc)
goto out_dbf;
IUCV_DBF_TEXT(trace, 3, __FUNCTION__);
+ netiucv_driver.groups = netiucv_drv_attr_groups;
rc = driver_register(&netiucv_driver);
if (rc) {
PRINT_ERR("NETIUCV: failed to register driver.\n");
@@ -2140,18 +2145,9 @@ static int __init netiucv_init(void)
goto out_iucv;
}

- rc = sysfs_create_group(&netiucv_driver.kobj, &netiucv_drv_attr_group);
- if (rc) {
- PRINT_ERR("NETIUCV: failed to add driver attributes.\n");
- IUCV_DBF_TEXT_(setup, 2,
- "ret %d - netiucv_drv_attr_group\n", rc);
- goto out_driver;
- }
netiucv_banner();
return rc;

-out_driver:
- driver_unregister(&netiucv_driver);
out_iucv:
iucv_unregister(&netiucv_handler, 1);
out_dbf:
--
1.5.3.8

2008-01-25 08:26:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 112/196] Kobject: change drivers/firmware/efivars.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Matt Domsch <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/firmware/efivars.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 7f9f086..b61a72f 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -617,16 +617,16 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
*(short_name + strlen(short_name)) = '-';
efi_guid_unparse(vendor_guid, short_name + strlen(short_name));

- kobject_set_name(&new_efivar->kobj, "%s", short_name);
new_efivar->kobj.kset = vars_kset;
- new_efivar->kobj.ktype = &efivar_ktype;
- i = kobject_register(&new_efivar->kobj);
+ i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL,
+ "%s", short_name);
if (i) {
kfree(short_name);
kfree(new_efivar);
return 1;
}

+ kobject_uevent(&new_efivar->kobj, KOBJ_ADD);
kfree(short_name);
short_name = NULL;

--
1.5.3.8

2008-01-25 08:26:49

by Greg KH

[permalink] [raw]
Subject: [PATCH 132/196] Kobject: convert fs/char_dev.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
fs/char_dev.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/char_dev.c b/fs/char_dev.c
index c3bfa76..b2dd5a0 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -510,9 +510,8 @@ struct cdev *cdev_alloc(void)
{
struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
if (p) {
- p->kobj.ktype = &ktype_cdev_dynamic;
INIT_LIST_HEAD(&p->list);
- kobject_init(&p->kobj);
+ kobject_init_ng(&p->kobj, &ktype_cdev_dynamic);
}
return p;
}
@@ -529,8 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
- cdev->kobj.ktype = &ktype_cdev_default;
- kobject_init(&cdev->kobj);
+ kobject_init_ng(&cdev->kobj, &ktype_cdev_default);
cdev->ops = fops;
}

--
1.5.3.8

2008-01-25 08:27:19

by Greg KH

[permalink] [raw]
Subject: [PATCH 156/196] sysfs: fix /sys/module/*/holders after sysfs logic change

From: Kay Sievers <[email protected]>

Sysfs symlinks now require fully registered kobjects as a target,
otherwise the call to create a symlink will fail. Here we register
the kobject before we request the symlink in the holders directory.

Signed-off-by: Kay Sievers <[email protected]>
Cc: Tejun Heo <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/module.c | 15 +++++++--------
1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index dc4d3f5..0ae8117 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1227,6 +1227,8 @@ int mod_sysfs_init(struct module *mod)

kobject_init(&mod->mkobj.kobj);

+ /* delay uevent until full sysfs population */
+ err = kobject_add(&mod->mkobj.kobj);
out:
return err;
}
@@ -1237,11 +1239,6 @@ int mod_sysfs_setup(struct module *mod,
{
int err;

- /* delay uevent until full sysfs population */
- err = kobject_add(&mod->mkobj.kobj);
- if (err)
- goto out;
-
mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj);
if (!mod->holders_dir) {
err = -ENOMEM;
@@ -1266,7 +1263,6 @@ out_unreg_holders:
out_unreg:
kobject_del(&mod->mkobj.kobj);
kobject_put(&mod->mkobj.kobj);
-out:
return err;
}
#endif
@@ -1883,10 +1879,10 @@ static struct module *load_module(void __user *umod,
/* Now we've moved module, initialize linked lists, etc. */
module_unload_init(mod);

- /* Initialize kobject, so we can reference it. */
+ /* add kobject, so we can reference it. */
err = mod_sysfs_init(mod);
if (err)
- goto cleanup;
+ goto free_unload;

/* Set up license info based on the info section */
set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
@@ -2056,6 +2052,9 @@ static struct module *load_module(void __user *umod,
arch_cleanup:
module_arch_cleanup(mod);
cleanup:
+ kobject_del(&mod->mkobj.kobj);
+ kobject_put(&mod->mkobj.kobj);
+ free_unload:
module_unload_free(mod);
module_free(mod, mod->module_init);
free_core:
--
1.5.3.8

2008-01-25 08:27:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 186/196] Driver core: Cleanup get_device_parent() in device_add() and device_move()

From: Cornelia Huck <[email protected]>

Make setup_parent() void as get_device_parent() will always return
either a valid kobject or NULL.
Introduce cleanup_glue_dir() to drop reference grabbed on "glue"
directory by get_device_parent(). Use it for cleanup in device_move()
and device_add() on errors.

This should fix the refcounting problem reported in
http://marc.info/?l=linux-kernel&m=120052487909200&w=2

Signed-off-by: Cornelia Huck <[email protected]>
Cc: Dave Young <[email protected]>
Cc: Gabor Gombas <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: David Miller <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 29 ++++++++++++++---------------
1 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index d5d542d..f09dde3 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -552,6 +552,8 @@ static struct kobject *get_device_parent(struct device *dev,
}

static inline void cleanup_device_parent(struct device *dev) {}
+static inline void cleanup_glue_dir(struct device *dev,
+ struct kobject *glue_dir) {}
#else
static struct kobject *virtual_device_parent(struct device *dev)
{
@@ -616,27 +618,27 @@ static struct kobject *get_device_parent(struct device *dev,
return NULL;
}

-static void cleanup_device_parent(struct device *dev)
+static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
{
- struct kobject *glue_dir = dev->kobj.parent;
-
/* see if we live in a "glue" directory */
if (!dev->class || glue_dir->kset != &dev->class->class_dirs)
return;

kobject_put(glue_dir);
}
+
+static void cleanup_device_parent(struct device *dev)
+{
+ cleanup_glue_dir(dev, dev->kobj.parent);
+}
#endif

-static int setup_parent(struct device *dev, struct device *parent)
+static void setup_parent(struct device *dev, struct device *parent)
{
struct kobject *kobj;
kobj = get_device_parent(dev, parent);
- if (IS_ERR(kobj))
- return PTR_ERR(kobj);
if (kobj)
dev->kobj.parent = kobj;
- return 0;
}

static int device_add_class_symlinks(struct device *dev)
@@ -784,9 +786,7 @@ int device_add(struct device *dev)
pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);

parent = get_device(dev->parent);
- error = setup_parent(dev, parent);
- if (error)
- goto Error;
+ setup_parent(dev, parent);

/* first, register with generic layer. */
error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
@@ -864,6 +864,7 @@ int device_add(struct device *dev)
kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj);
Error:
+ cleanup_device_parent(dev);
if (parent)
put_device(parent);
goto Done;
@@ -1344,15 +1345,12 @@ int device_move(struct device *dev, struct device *new_parent)

new_parent = get_device(new_parent);
new_parent_kobj = get_device_parent (dev, new_parent);
- if (IS_ERR(new_parent_kobj)) {
- error = PTR_ERR(new_parent_kobj);
- put_device(new_parent);
- goto out;
- }
+
pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
__FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
error = kobject_move(&dev->kobj, new_parent_kobj);
if (error) {
+ cleanup_glue_dir(dev, new_parent_kobj);
put_device(new_parent);
goto out;
}
@@ -1375,6 +1373,7 @@ int device_move(struct device *dev, struct device *new_parent)
klist_add_tail(&dev->knode_parent,
&old_parent->klist_children);
}
+ cleanup_glue_dir(dev, new_parent_kobj);
put_device(new_parent);
goto out;
}
--
1.5.3.8

2008-01-25 08:28:20

by Greg KH

[permalink] [raw]
Subject: [PATCH 128/196] Kobject: the cris iop_fw_load.c code is broken

This code is really really really broken. So much so that it's almost
impossible to fix with a simple patch, so just comment out the offending
registration with the kobject core, and mark the driver as broken.

The problem is that the code is trying to register a "raw" struct
device, which is not allowed. struct device is only for use within the
driver model. This is being done to try to use the firmware layer which
wants a struct device. To properly fix this, use something easy, like a
platform device, which is a struct device and can be used for this kind
of thing.

Cc: Mikael Starvik <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/cris/arch-v32/drivers/iop_fw_load.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/iop_fw_load.c b/arch/cris/arch-v32/drivers/iop_fw_load.c
index 11f9895..f4bdc1d 100644
--- a/arch/cris/arch-v32/drivers/iop_fw_load.c
+++ b/arch/cris/arch-v32/drivers/iop_fw_load.c
@@ -20,6 +20,9 @@

#define IOP_TIMEOUT 100

+#error "This driver is broken with regard to its driver core usage."
+#error "Please contact <[email protected]> for details on how to fix it properly."
+
static struct device iop_spu_device[2] = {
{ .bus_id = "iop-spu0", },
{ .bus_id = "iop-spu1", },
@@ -192,6 +195,13 @@ int iop_start_mpu(unsigned int start_addr)

static int __init iop_fw_load_init(void)
{
+#if 0
+ /*
+ * static struct devices can not be added directly to sysfs by ignoring
+ * the driver model infrastructure. To fix this properly, please use
+ * the platform_bus to register these devices to be able to properly
+ * use the firmware infrastructure.
+ */
device_initialize(&iop_spu_device[0]);
kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0");
kobject_add(&iop_spu_device[0].kobj);
@@ -201,6 +211,7 @@ static int __init iop_fw_load_init(void)
device_initialize(&iop_mpu_device);
kobject_set_name(&iop_mpu_device.kobj, "iop-mpu");
kobject_add(&iop_mpu_device.kobj);
+#endif
return 0;
}

--
1.5.3.8

2008-01-25 08:28:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 131/196] Kobject: convert drivers/net/iseries_veth.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kyle A. Lucke <[email protected]>
Cc: David Gibson <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/net/iseries_veth.c | 19 ++++++-------------
1 files changed, 6 insertions(+), 13 deletions(-)

diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 97bd9dc..90ff4ec 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -815,7 +815,7 @@ static int veth_init_connection(u8 rlp)
{
struct veth_lpar_connection *cnx;
struct veth_msg *msgs;
- int i, rc;
+ int i;

if ( (rlp == this_lp)
|| ! HvLpConfig_doLpsCommunicateOnVirtualLan(this_lp, rlp) )
@@ -844,11 +844,7 @@ static int veth_init_connection(u8 rlp)

/* This gets us 1 reference, which is held on behalf of the driver
* infrastructure. It's released at module unload. */
- kobject_init(&cnx->kobject);
- cnx->kobject.ktype = &veth_lpar_connection_ktype;
- rc = kobject_set_name(&cnx->kobject, "cnx%.2d", rlp);
- if (rc != 0)
- return rc;
+ kobject_init_ng(&cnx->kobject, &veth_lpar_connection_ktype);

msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL);
if (! msgs) {
@@ -1087,11 +1083,8 @@ static struct net_device * __init veth_probe_one(int vlan,
return NULL;
}

- kobject_init(&port->kobject);
- port->kobject.parent = &dev->dev.kobj;
- port->kobject.ktype = &veth_port_ktype;
- kobject_set_name(&port->kobject, "veth_port");
- if (0 != kobject_add(&port->kobject))
+ kobject_init_ng(&port->kobject, &veth_port_ktype);
+ if (0 != kobject_add_ng(&port->kobject, &dev->dev.kobj, "veth_port"))
veth_error("Failed adding port for %s to sysfs.\n", dev->name);

veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
@@ -1711,9 +1704,9 @@ static int __init veth_module_init(void)
continue;

kobj = &veth_cnx[i]->kobject;
- kobj->parent = &veth_driver.driver.kobj;
/* If the add failes, complain but otherwise continue */
- if (0 != kobject_add(kobj))
+ if (0 != kobject_add_ng(kobj, &veth_driver.driver.kobj,
+ "cnx%.2d", veth_cnx[i]->remote_lp))
veth_error("cnx %d: Failed adding to sysfs.\n", i);
}

--
1.5.3.8

2008-01-25 08:29:15

by Greg KH

[permalink] [raw]
Subject: [PATCH 125/196] Kobject: change drivers/md/md.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Neil Brown <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/md/md.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index cef9ebd..c503086 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -3054,6 +3054,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
int partitioned = (MAJOR(dev) != MD_MAJOR);
int shift = partitioned ? MdpMinorShift : 0;
int unit = MINOR(dev) >> shift;
+ int error;

if (!mddev)
return NULL;
@@ -3082,12 +3083,13 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
add_disk(disk);
mddev->gendisk = disk;
mutex_unlock(&disks_mutex);
- mddev->kobj.parent = &disk->kobj;
- kobject_set_name(&mddev->kobj, "%s", "md");
- mddev->kobj.ktype = &md_ktype;
- if (kobject_register(&mddev->kobj))
+ error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->kobj,
+ "%s", "md");
+ if (error)
printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
disk->disk_name);
+ else
+ kobject_uevent(&mddev->kobj, KOBJ_ADD);
return NULL;
}

--
1.5.3.8

2008-01-25 08:29:39

by Greg KH

[permalink] [raw]
Subject: [PATCH 120/196] Kobject: change drivers/block/pktcdvd.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Jens Axboe <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/block/pktcdvd.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 17da699..d1ee383 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -110,17 +110,18 @@ static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
struct kobj_type* ktype)
{
struct pktcdvd_kobj *p;
+ int error;
+
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return NULL;
- kobject_set_name(&p->kobj, "%s", name);
- p->kobj.parent = parent;
- p->kobj.ktype = ktype;
p->pd = pd;
- if (kobject_register(&p->kobj) != 0) {
+ error = kobject_init_and_add(&p->kobj, ktype, parent, "%s", name);
+ if (error) {
kobject_put(&p->kobj);
return NULL;
}
+ kobject_uevent(&p->kobj, KOBJ_ADD);
return p;
}
/*
--
1.5.3.8

2008-01-25 08:29:58

by Greg KH

[permalink] [raw]
Subject: [PATCH 147/196] zfcp: Use device_driver default attribute groups.

From: Cornelia Huck <[email protected]>

CC: Swen Schillig <[email protected]>
Signed-off-by: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/s390/scsi/zfcp_ccw.c | 14 ++++----------
drivers/s390/scsi/zfcp_ext.h | 3 +--
drivers/s390/scsi/zfcp_sysfs_driver.c | 27 ++++-----------------------
3 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index e01cbf1..86c3f65 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -52,6 +52,9 @@ static struct ccw_driver zfcp_ccw_driver = {
.set_offline = zfcp_ccw_set_offline,
.notify = zfcp_ccw_notify,
.shutdown = zfcp_ccw_shutdown,
+ .driver = {
+ .groups = zfcp_driver_attr_groups,
+ },
};

MODULE_DEVICE_TABLE(ccw, zfcp_ccw_device_id);
@@ -251,16 +254,7 @@ zfcp_ccw_notify(struct ccw_device *ccw_device, int event)
int __init
zfcp_ccw_register(void)
{
- int retval;
-
- retval = ccw_driver_register(&zfcp_ccw_driver);
- if (retval)
- goto out;
- retval = zfcp_sysfs_driver_create_files(&zfcp_ccw_driver.driver);
- if (retval)
- ccw_driver_unregister(&zfcp_ccw_driver);
- out:
- return retval;
+ return ccw_driver_register(&zfcp_ccw_driver);
}

/**
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 8534cf0..06b1079 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -27,8 +27,7 @@
extern struct zfcp_data zfcp_data;

/******************************** SYSFS *************************************/
-extern int zfcp_sysfs_driver_create_files(struct device_driver *);
-extern void zfcp_sysfs_driver_remove_files(struct device_driver *);
+extern struct attribute_group *zfcp_driver_attr_groups[];
extern int zfcp_sysfs_adapter_create_files(struct device *);
extern void zfcp_sysfs_adapter_remove_files(struct device *);
extern int zfcp_sysfs_port_create_files(struct device *, u32);
diff --git a/drivers/s390/scsi/zfcp_sysfs_driver.c b/drivers/s390/scsi/zfcp_sysfs_driver.c
index 005e62f..651edd5 100644
--- a/drivers/s390/scsi/zfcp_sysfs_driver.c
+++ b/drivers/s390/scsi/zfcp_sysfs_driver.c
@@ -98,28 +98,9 @@ static struct attribute_group zfcp_driver_attr_group = {
.attrs = zfcp_driver_attrs,
};

-/**
- * zfcp_sysfs_create_driver_files - create sysfs driver files
- * @dev: pointer to belonging device
- *
- * Create all sysfs attributes of the zfcp device driver
- */
-int
-zfcp_sysfs_driver_create_files(struct device_driver *drv)
-{
- return sysfs_create_group(&drv->kobj, &zfcp_driver_attr_group);
-}
-
-/**
- * zfcp_sysfs_remove_driver_files - remove sysfs driver files
- * @dev: pointer to belonging device
- *
- * Remove all sysfs attributes of the zfcp device driver
- */
-void
-zfcp_sysfs_driver_remove_files(struct device_driver *drv)
-{
- sysfs_remove_group(&drv->kobj, &zfcp_driver_attr_group);
-}
+struct attribute_group *zfcp_driver_attr_groups[] = {
+ &zfcp_driver_attr_group,
+ NULL,
+};

#undef ZFCP_LOG_AREA
--
1.5.3.8

2008-01-25 08:30:32

by Greg KH

[permalink] [raw]
Subject: [PATCH 135/196] Kobject: convert mm/slub.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Christoph Lameter <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
mm/slub.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index d26177f..5cc4b7d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -4025,13 +4025,12 @@ static int sysfs_slab_add(struct kmem_cache *s)
name = create_unique_id(s);
}

- kobject_set_name(&s->kobj, name);
s->kobj.kset = slab_kset;
- s->kobj.ktype = &slab_ktype;
- kobject_init(&s->kobj);
- err = kobject_add(&s->kobj);
- if (err)
+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
+ if (err) {
+ kobject_put(&s->kobj);
return err;
+ }

err = sysfs_create_group(&s->kobj, &slab_attr_group);
if (err)
--
1.5.3.8

2008-01-25 08:30:56

by Greg KH

[permalink] [raw]
Subject: [PATCH 139/196] driver core: add way to get to bus device klist

This allows an easier way to get to the device klist associated with a
struct bus_type (you have three to choose from...) This will make it
easier to move these fields to be dynamic in a future patch.

The only user of this is the PCI core which horribly abuses this
interface to rearrange the order of the pci devices. This should be
done using the existing bus device walking functions, but that's left
for future patches.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/bus.c | 6 ++++++
drivers/pci/probe.c | 11 +++++++----
include/linux/device.h | 1 +
3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8335a10..9c9027b 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -941,6 +941,12 @@ struct kset *bus_get_kset(struct bus_type *bus)
}
EXPORT_SYMBOL_GPL(bus_get_kset);

+struct klist *bus_get_device_klist(struct bus_type *bus)
+{
+ return &bus->klist_devices;
+}
+EXPORT_SYMBOL_GPL(bus_get_device_klist);
+
int __init buses_init(void)
{
bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index c5ca313..5fd5852 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1210,16 +1210,19 @@ static void __init pci_sort_breadthfirst_klist(void)
struct klist_node *n;
struct device *dev;
struct pci_dev *pdev;
+ struct klist *device_klist;

- spin_lock(&pci_bus_type.klist_devices.k_lock);
- list_for_each_safe(pos, tmp, &pci_bus_type.klist_devices.k_list) {
+ device_klist = bus_get_device_klist(&pci_bus_type);
+
+ spin_lock(&device_klist->k_lock);
+ list_for_each_safe(pos, tmp, &device_klist->k_list) {
n = container_of(pos, struct klist_node, n_node);
dev = container_of(n, struct device, knode_bus);
pdev = to_pci_dev(dev);
pci_insertion_sort_klist(pdev, &sorted_devices);
}
- list_splice(&sorted_devices, &pci_bus_type.klist_devices.k_list);
- spin_unlock(&pci_bus_type.klist_devices.k_lock);
+ list_splice(&sorted_devices, &device_klist->k_list);
+ spin_unlock(&device_klist->k_lock);
}

static void __init pci_insertion_sort_devices(struct pci_dev *a, struct list_head *list)
diff --git a/include/linux/device.h b/include/linux/device.h
index 3cc13c3..62e695b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -118,6 +118,7 @@ extern int bus_unregister_notifier(struct bus_type *bus,
unbound */

extern struct kset *bus_get_kset(struct bus_type *bus);
+extern struct klist *bus_get_device_klist(struct bus_type *bus);

struct device_driver {
const char * name;
--
1.5.3.8

2008-01-25 08:31:29

by Greg KH

[permalink] [raw]
Subject: [PATCH 162/196] Kobject: convert kernel/module.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/module.c | 14 ++++++--------
1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 0ae8117..89cd4c7 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1217,18 +1217,16 @@ int mod_sysfs_init(struct module *mod)
err = -EINVAL;
goto out;
}
- memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
- err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name);
- if (err)
- goto out;
- mod->mkobj.kobj.kset = module_kset;
- mod->mkobj.kobj.ktype = &module_ktype;
mod->mkobj.mod = mod;

- kobject_init(&mod->mkobj.kobj);
+ memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
+ mod->mkobj.kobj.kset = module_kset;
+ err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL,
+ "%s", mod->name);
+ if (err)
+ kobject_put(&mod->mkobj.kobj);

/* delay uevent until full sysfs population */
- err = kobject_add(&mod->mkobj.kobj);
out:
return err;
}
--
1.5.3.8

2008-01-25 08:31:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 150/196] Driver core: move the driver specific module code into the driver core

The module driver specific code should belong in the driver core, not in
the kernel/ directory. So move this code. This is done in preparation
for some struct device_driver rework that should be confined to the
driver core code only.

This also lets us keep from exporting these functions, as no external
code should ever be calling it.

Thanks to Andrew Morton for the !CONFIG_MODULES fix.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/Makefile | 1 +
drivers/base/base.h | 9 +++++
drivers/base/module.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++
include/linux/module.h | 15 --------
kernel/module.c | 87 --------------------------------------------
5 files changed, 104 insertions(+), 102 deletions(-)
create mode 100644 drivers/base/module.c

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index b39ea3f..ff26968 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o
obj-$(CONFIG_NUMA) += node.o
obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o
obj-$(CONFIG_SMP) += topology.o
+obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o

ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index ca6d273..0547236 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -73,3 +73,12 @@ extern char *make_class_name(const char *name, struct kobject *kobj);
extern int devres_release_all(struct device *dev);

extern struct kset *devices_kset;
+
+#ifdef CONFIG_MODULES
+extern void module_add_driver(struct module *mod, struct device_driver *drv);
+extern void module_remove_driver(struct device_driver *drv);
+#else
+static inline void module_add_driver(struct module *mod,
+ struct device_driver *drv) { }
+static inline void module_remove_driver(struct device_driver *drv) { }
+#endif
diff --git a/drivers/base/module.c b/drivers/base/module.c
new file mode 100644
index 0000000..cad07be
--- /dev/null
+++ b/drivers/base/module.c
@@ -0,0 +1,94 @@
+/*
+ * module.c - module sysfs fun for drivers
+ *
+ * This file is released under the GPLv2
+ *
+ */
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include "base.h"
+
+static char *make_driver_name(struct device_driver *drv)
+{
+ char *driver_name;
+
+ driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
+ GFP_KERNEL);
+ if (!driver_name)
+ return NULL;
+
+ sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
+ return driver_name;
+}
+
+static void module_create_drivers_dir(struct module_kobject *mk)
+{
+ if (!mk || mk->drivers_dir)
+ return;
+
+ mk->drivers_dir = kobject_create_and_add("drivers", &mk->kobj);
+}
+
+void module_add_driver(struct module *mod, struct device_driver *drv)
+{
+ char *driver_name;
+ int no_warn;
+ struct module_kobject *mk = NULL;
+
+ if (!drv)
+ return;
+
+ if (mod)
+ mk = &mod->mkobj;
+ else if (drv->mod_name) {
+ struct kobject *mkobj;
+
+ /* Lookup built-in module entry in /sys/modules */
+ mkobj = kset_find_obj(module_kset, drv->mod_name);
+ if (mkobj) {
+ mk = container_of(mkobj, struct module_kobject, kobj);
+ /* remember our module structure */
+ drv->mkobj = mk;
+ /* kset_find_obj took a reference */
+ kobject_put(mkobj);
+ }
+ }
+
+ if (!mk)
+ return;
+
+ /* Don't check return codes; these calls are idempotent */
+ no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
+ driver_name = make_driver_name(drv);
+ if (driver_name) {
+ module_create_drivers_dir(mk);
+ no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
+ driver_name);
+ kfree(driver_name);
+ }
+}
+
+void module_remove_driver(struct device_driver *drv)
+{
+ struct module_kobject *mk = NULL;
+ char *driver_name;
+
+ if (!drv)
+ return;
+
+ sysfs_remove_link(&drv->kobj, "module");
+
+ if (drv->owner)
+ mk = &drv->owner->mkobj;
+ else if (drv->mkobj)
+ mk = drv->mkobj;
+ if (mk && mk->drivers_dir) {
+ driver_name = make_driver_name(drv);
+ if (driver_name) {
+ sysfs_remove_link(mk->drivers_dir, driver_name);
+ kfree(driver_name);
+ }
+ }
+}
diff --git a/include/linux/module.h b/include/linux/module.h
index fbe930b..c97bdb7 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -609,21 +609,6 @@ static inline void module_remove_modinfo_attrs(struct module *mod)

#endif /* CONFIG_SYSFS */

-#if defined(CONFIG_SYSFS) && defined(CONFIG_MODULES)
-
-void module_add_driver(struct module *mod, struct device_driver *drv);
-void module_remove_driver(struct device_driver *drv);
-
-#else /* not both CONFIG_SYSFS && CONFIG_MODULES */
-
-static inline void module_add_driver(struct module *mod, struct device_driver *drv)
-{ }
-
-static inline void module_remove_driver(struct device_driver *drv)
-{ }
-
-#endif
-
#define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)

/* BELOW HERE ALL THESE ARE OBSOLETE AND WILL VANISH */
diff --git a/kernel/module.c b/kernel/module.c
index d03fcd9..dc4d3f5 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2501,93 +2501,6 @@ void print_modules(void)
printk("\n");
}

-#ifdef CONFIG_SYSFS
-static char *make_driver_name(struct device_driver *drv)
-{
- char *driver_name;
-
- driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2,
- GFP_KERNEL);
- if (!driver_name)
- return NULL;
-
- sprintf(driver_name, "%s:%s", drv->bus->name, drv->name);
- return driver_name;
-}
-
-static void module_create_drivers_dir(struct module_kobject *mk)
-{
- if (!mk || mk->drivers_dir)
- return;
-
- mk->drivers_dir = kobject_create_and_add("drivers", &mk->kobj);
-}
-
-void module_add_driver(struct module *mod, struct device_driver *drv)
-{
- char *driver_name;
- int no_warn;
- struct module_kobject *mk = NULL;
-
- if (!drv)
- return;
-
- if (mod)
- mk = &mod->mkobj;
- else if (drv->mod_name) {
- struct kobject *mkobj;
-
- /* Lookup built-in module entry in /sys/modules */
- mkobj = kset_find_obj(module_kset, drv->mod_name);
- if (mkobj) {
- mk = container_of(mkobj, struct module_kobject, kobj);
- /* remember our module structure */
- drv->mkobj = mk;
- /* kset_find_obj took a reference */
- kobject_put(mkobj);
- }
- }
-
- if (!mk)
- return;
-
- /* Don't check return codes; these calls are idempotent */
- no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
- driver_name = make_driver_name(drv);
- if (driver_name) {
- module_create_drivers_dir(mk);
- no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
- driver_name);
- kfree(driver_name);
- }
-}
-EXPORT_SYMBOL(module_add_driver);
-
-void module_remove_driver(struct device_driver *drv)
-{
- struct module_kobject *mk = NULL;
- char *driver_name;
-
- if (!drv)
- return;
-
- sysfs_remove_link(&drv->kobj, "module");
-
- if (drv->owner)
- mk = &drv->owner->mkobj;
- else if (drv->mkobj)
- mk = drv->mkobj;
- if (mk && mk->drivers_dir) {
- driver_name = make_driver_name(drv);
- if (driver_name) {
- sysfs_remove_link(mk->drivers_dir, driver_name);
- kfree(driver_name);
- }
- }
-}
-EXPORT_SYMBOL(module_remove_driver);
-#endif
-
#ifdef CONFIG_MODVERSIONS
/* Generate the signature for struct module here, too, for modversions. */
void struct_module(struct module *mod) { return; }
--
1.5.3.8

2008-01-25 08:32:16

by Greg KH

[permalink] [raw]
Subject: [PATCH 180/196] kobject: add sample code for how to use ksets/ktypes/kobjects

This is a more complex example showing how to create a kset and a ktype
and some default attributes for a group of kobjects.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
samples/kobject/Makefile | 2 +-
samples/kobject/kset-example.c | 278 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 279 insertions(+), 1 deletions(-)
create mode 100644 samples/kobject/kset-example.c

diff --git a/samples/kobject/Makefile b/samples/kobject/Makefile
index cce16e9..4a19420 100644
--- a/samples/kobject/Makefile
+++ b/samples/kobject/Makefile
@@ -1 +1 @@
-obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o
+obj-$(CONFIG_SAMPLE_KOBJECT) += kobject-example.o kset-example.o
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
new file mode 100644
index 0000000..b0a1b4f
--- /dev/null
+++ b/samples/kobject/kset-example.c
@@ -0,0 +1,278 @@
+/*
+ * Sample kset and ktype implementation
+ *
+ * Copyright (C) 2004-2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (C) 2007 Novell Inc.
+ *
+ * Released under the GPL version 2 only.
+ *
+ */
+#include <linux/kobject.h>
+#include <linux/string.h>
+#include <linux/sysfs.h>
+#include <linux/module.h>
+#include <linux/init.h>
+
+/*
+ * This module shows how to create a kset in sysfs called
+ * /sys/kernel/kset-example
+ * Then tree kobjects are created and assigned to this kset, "foo", "baz",
+ * and "bar". In those kobjects, attributes of the same name are also
+ * created and if an integer is written to these files, it can be later
+ * read out of it.
+ */
+
+
+/*
+ * This is our "object" that we will create a few of and register them with
+ * sysfs.
+ */
+struct foo_obj {
+ struct kobject kobj;
+ int foo;
+ int baz;
+ int bar;
+};
+#define to_foo_obj(x) container_of(x, struct foo_obj, kobj)
+
+/* a custom attribute that works just for a struct foo_obj. */
+struct foo_attribute {
+ struct attribute attr;
+ ssize_t (*show)(struct foo_obj *foo, struct foo_attribute *attr, char *buf);
+ ssize_t (*store)(struct foo_obj *foo, struct foo_attribute *attr, const char *buf, size_t count);
+};
+#define to_foo_attr(x) container_of(x, struct foo_attribute, attr)
+
+/*
+ * The default show function that must be passed to sysfs. This will be
+ * called by sysfs for whenever a show function is called by the user on a
+ * sysfs file associated with the kobjects we have registered. We need to
+ * transpose back from a "default" kobject to our custom struct foo_obj and
+ * then call the show function for that specific object.
+ */
+static ssize_t foo_attr_show(struct kobject *kobj,
+ struct attribute *attr,
+ char *buf)
+{
+ struct foo_attribute *attribute;
+ struct foo_obj *foo;
+
+ attribute = to_foo_attr(attr);
+ foo = to_foo_obj(kobj);
+
+ if (!attribute->show)
+ return -EIO;
+
+ return attribute->show(foo, attribute, buf);
+}
+
+/*
+ * Just like the default show function above, but this one is for when the
+ * sysfs "store" is requested (when a value is written to a file.)
+ */
+static ssize_t foo_attr_store(struct kobject *kobj,
+ struct attribute *attr,
+ const char *buf, size_t len)
+{
+ struct foo_attribute *attribute;
+ struct foo_obj *foo;
+
+ attribute = to_foo_attr(attr);
+ foo = to_foo_obj(kobj);
+
+ if (!attribute->store)
+ return -EIO;
+
+ return attribute->store(foo, attribute, buf, len);
+}
+
+/* Our custom sysfs_ops that we will associate with our ktype later on */
+static struct sysfs_ops foo_sysfs_ops = {
+ .show = foo_attr_show,
+ .store = foo_attr_store,
+};
+
+/*
+ * The release function for our object. This is REQUIRED by the kernel to
+ * have. We free the memory held in our object here.
+ *
+ * NEVER try to get away with just a "blank" release function to try to be
+ * smarter than the kernel. Turns out, no one ever is...
+ */
+static void foo_release(struct kobject *kobj)
+{
+ struct foo_obj *foo;
+
+ foo = to_foo_obj(kobj);
+ kfree(foo);
+}
+
+/*
+ * The "foo" file where the .foo variable is read from and written to.
+ */
+static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%d\n", foo_obj->foo);
+}
+
+static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
+ const char *buf, size_t count)
+{
+ sscanf(buf, "%du", &foo_obj->foo);
+ return count;
+}
+
+static struct foo_attribute foo_attribute =
+ __ATTR(foo, 0666, foo_show, foo_store);
+
+/*
+ * More complex function where we determine which varible is being accessed by
+ * looking at the attribute for the "baz" and "bar" files.
+ */
+static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
+ char *buf)
+{
+ int var;
+
+ if (strcmp(attr->attr.name, "baz") == 0)
+ var = foo_obj->baz;
+ else
+ var = foo_obj->bar;
+ return sprintf(buf, "%d\n", var);
+}
+
+static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
+ const char *buf, size_t count)
+{
+ int var;
+
+ sscanf(buf, "%du", &var);
+ if (strcmp(attr->attr.name, "baz") == 0)
+ foo_obj->baz = var;
+ else
+ foo_obj->bar = var;
+ return count;
+}
+
+static struct foo_attribute baz_attribute =
+ __ATTR(baz, 0666, b_show, b_store);
+static struct foo_attribute bar_attribute =
+ __ATTR(bar, 0666, b_show, b_store);
+
+/*
+ * Create a group of attributes so that we can create and destory them all
+ * at once.
+ */
+static struct attribute *foo_default_attrs[] = {
+ &foo_attribute.attr,
+ &baz_attribute.attr,
+ &bar_attribute.attr,
+ NULL, /* need to NULL terminate the list of attributes */
+};
+
+/*
+ * Our own ktype for our kobjects. Here we specify our sysfs ops, the
+ * release function, and the set of default attributes we want created
+ * whenever a kobject of this type is registered with the kernel.
+ */
+static struct kobj_type foo_ktype = {
+ .sysfs_ops = &foo_sysfs_ops,
+ .release = foo_release,
+ .default_attrs = foo_default_attrs,
+};
+
+static struct kset *example_kset;
+static struct foo_obj *foo_obj;
+static struct foo_obj *bar_obj;
+static struct foo_obj *baz_obj;
+
+static struct foo_obj *create_foo_obj(const char *name)
+{
+ struct foo_obj *foo;
+ int retval;
+
+ /* allocate the memory for the whole object */
+ foo = kzalloc(sizeof(*foo), GFP_KERNEL);
+ if (!foo)
+ return NULL;
+
+ /*
+ * As we have a kset for this kobject, we need to set it before calling
+ * the kobject core.
+ */
+ foo->kobj.kset = example_kset;
+
+ /*
+ * Initialize and add the kobject to the kernel. All the default files
+ * will be created here. As we have already specified a kset for this
+ * kobject, we don't have to set a parent for the kobject, the kobject
+ * will be placed beneath that kset automatically.
+ */
+ retval = kobject_init_and_add(&foo->kobj, &foo_ktype, NULL, "%s", name);
+ if (retval) {
+ kfree(foo);
+ return NULL;
+ }
+
+ /*
+ * We are always responsible for sending the uevent that the kobject
+ * was added to the system.
+ */
+ kobject_uevent(&foo->kobj, KOBJ_ADD);
+
+ return foo;
+}
+
+static void destroy_foo_obj(struct foo_obj *foo)
+{
+ kobject_put(&foo->kobj);
+}
+
+static int example_init(void)
+{
+ /*
+ * Create a kset with the name of "kset_example",
+ * located under /sys/kernel/
+ */
+ example_kset = kset_create_and_add("kset_example", NULL, kernel_kobj);
+ if (!example_kset)
+ return -ENOMEM;
+
+ /*
+ * Create three objects and register them with our kset
+ */
+ foo_obj = create_foo_obj("foo");
+ if (!foo_obj)
+ goto foo_error;
+
+ bar_obj = create_foo_obj("bar");
+ if (!bar_obj)
+ goto bar_error;
+
+ baz_obj = create_foo_obj("baz");
+ if (!baz_obj)
+ goto baz_error;
+
+ return 0;
+
+baz_error:
+ destroy_foo_obj(bar_obj);
+bar_error:
+ destroy_foo_obj(foo_obj);
+foo_error:
+ return -EINVAL;
+}
+
+static void example_exit(void)
+{
+ destroy_foo_obj(baz_obj);
+ destroy_foo_obj(bar_obj);
+ destroy_foo_obj(foo_obj);
+ kset_unregister(example_kset);
+}
+
+module_init(example_init);
+module_exit(example_exit);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Greg Kroah-Hartman <[email protected]>");
--
1.5.3.8

2008-01-25 08:32:38

by Greg KH

[permalink] [raw]
Subject: [PATCH 126/196] Kobject: change arch/x86/kernel/cpu/mcheck/mce_amd_64.c to use kobject_create_and_add

Make this kobject dynamic and convert it to not use kobject_register,
which is going away.

Cc: Jacob Shin <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/x86/kernel/cpu/mcheck/mce_amd_64.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
index 752fb16..2d65311 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_amd_64.c
@@ -65,7 +65,7 @@ static struct threshold_block threshold_defaults = {
};

struct threshold_bank {
- struct kobject kobj;
+ struct kobject *kobj;
struct threshold_block *blocks;
cpumask_t cpus;
};
@@ -433,7 +433,7 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
per_cpu(threshold_banks, cpu)[bank]->blocks = b;

kobject_set_name(&b->kobj, "misc%i", block);
- b->kobj.parent = &per_cpu(threshold_banks, cpu)[bank]->kobj;
+ b->kobj.parent = per_cpu(threshold_banks, cpu)[bank]->kobj;
b->kobj.ktype = &threshold_ktype;
err = kobject_register(&b->kobj);
if (err)
@@ -489,7 +489,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
goto out;

err = sysfs_create_link(&per_cpu(device_mce, cpu).kobj,
- &b->kobj, name);
+ b->kobj, name);
if (err)
goto out;

@@ -505,16 +505,15 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
goto out;
}

- kobject_set_name(&b->kobj, "threshold_bank%i", bank);
- b->kobj.parent = &per_cpu(device_mce, cpu).kobj;
+ b->kobj = kobject_create_and_add(name, &per_cpu(device_mce, cpu).kobj);
+ if (!b->kobj)
+ goto out_free;
+
#ifndef CONFIG_SMP
b->cpus = CPU_MASK_ALL;
#else
b->cpus = per_cpu(cpu_core_map, cpu);
#endif
- err = kobject_register(&b->kobj);
- if (err)
- goto out_free;

per_cpu(threshold_banks, cpu)[bank] = b;

@@ -531,7 +530,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
continue;

err = sysfs_create_link(&per_cpu(device_mce, i).kobj,
- &b->kobj, name);
+ b->kobj, name);
if (err)
goto out;

@@ -627,7 +626,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
deallocate_threshold_block(cpu, bank);

free_out:
- kobject_unregister(&b->kobj);
+ kobject_unregister(b->kobj);
kfree(b);
per_cpu(threshold_banks, cpu)[bank] = NULL;
}
--
1.5.3.8

2008-01-25 08:33:03

by Greg KH

[permalink] [raw]
Subject: [PATCH 158/196] Driver core: convert block from raw kobjects to core devices

From: Kay Sievers <[email protected]>

This moves the block devices to /sys/class/block. It will create a
flat list of all block devices, with the disks and partitions in one
directory. For compatibility /sys/block is created and contains symlinks
to the disks.

/sys/class/block
|-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
|-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
|-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10
|-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5
|-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6
|-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7
|-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8
|-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9
`-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0

/sys/block/
|-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
`-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/genhd.c | 416 +++++++++++++++++++-------------------------
block/ll_rw_blk.c | 4 +-
drivers/base/class.c | 7 +
drivers/base/core.c | 20 ++-
drivers/block/aoe/aoeblk.c | 51 +++---
drivers/block/nbd.c | 15 +-
drivers/ide/ide-probe.c | 2 +-
drivers/md/dm.c | 4 +-
drivers/md/md.c | 8 +-
fs/block_dev.c | 8 +-
fs/partitions/check.c | 315 +++++++++++----------------------
include/linux/genhd.h | 37 +++--
init/do_mounts.c | 108 +-----------
13 files changed, 385 insertions(+), 610 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index 69aa738..5e4ab4b 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -17,9 +17,10 @@
#include <linux/buffer_head.h>
#include <linux/mutex.h>

-struct kset *block_kset;
-static struct kset_uevent_ops block_uevent_ops;
-static DEFINE_MUTEX(block_subsys_lock);
+static DEFINE_MUTEX(block_class_lock);
+#ifndef CONFIG_SYSFS_DEPRECATED
+struct kobject *block_depr;
+#endif

/*
* Can be deleted altogether. Later.
@@ -38,19 +39,17 @@ static inline int major_to_index(int major)
}

#ifdef CONFIG_PROC_FS
-
void blkdev_show(struct seq_file *f, off_t offset)
{
struct blk_major_name *dp;

if (offset < BLKDEV_MAJOR_HASH_SIZE) {
- mutex_lock(&block_subsys_lock);
+ mutex_lock(&block_class_lock);
for (dp = major_names[offset]; dp; dp = dp->next)
seq_printf(f, "%3d %s\n", dp->major, dp->name);
- mutex_unlock(&block_subsys_lock);
+ mutex_unlock(&block_class_lock);
}
}
-
#endif /* CONFIG_PROC_FS */

int register_blkdev(unsigned int major, const char *name)
@@ -58,7 +57,7 @@ int register_blkdev(unsigned int major, const char *name)
struct blk_major_name **n, *p;
int index, ret = 0;

- mutex_lock(&block_subsys_lock);
+ mutex_lock(&block_class_lock);

/* temporary */
if (major == 0) {
@@ -103,7 +102,7 @@ int register_blkdev(unsigned int major, const char *name)
kfree(p);
}
out:
- mutex_unlock(&block_subsys_lock);
+ mutex_unlock(&block_class_lock);
return ret;
}

@@ -115,7 +114,7 @@ void unregister_blkdev(unsigned int major, const char *name)
struct blk_major_name *p = NULL;
int index = major_to_index(major);

- mutex_lock(&block_subsys_lock);
+ mutex_lock(&block_class_lock);
for (n = &major_names[index]; *n; n = &(*n)->next)
if ((*n)->major == major)
break;
@@ -125,7 +124,7 @@ void unregister_blkdev(unsigned int major, const char *name)
p = *n;
*n = p->next;
}
- mutex_unlock(&block_subsys_lock);
+ mutex_unlock(&block_class_lock);
kfree(p);
}

@@ -138,29 +137,30 @@ static struct kobj_map *bdev_map;
* range must be nonzero
* The hash chain is sorted on range, so that subranges can override.
*/
-void blk_register_region(dev_t dev, unsigned long range, struct module *module,
+void blk_register_region(dev_t devt, unsigned long range, struct module *module,
struct kobject *(*probe)(dev_t, int *, void *),
int (*lock)(dev_t, void *), void *data)
{
- kobj_map(bdev_map, dev, range, module, probe, lock, data);
+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
}

EXPORT_SYMBOL(blk_register_region);

-void blk_unregister_region(dev_t dev, unsigned long range)
+void blk_unregister_region(dev_t devt, unsigned long range)
{
- kobj_unmap(bdev_map, dev, range);
+ kobj_unmap(bdev_map, devt, range);
}

EXPORT_SYMBOL(blk_unregister_region);

-static struct kobject *exact_match(dev_t dev, int *part, void *data)
+static struct kobject *exact_match(dev_t devt, int *part, void *data)
{
struct gendisk *p = data;
- return &p->kobj;
+
+ return &p->dev.kobj;
}

-static int exact_lock(dev_t dev, void *data)
+static int exact_lock(dev_t devt, void *data)
{
struct gendisk *p = data;

@@ -195,8 +195,6 @@ void unlink_gendisk(struct gendisk *disk)
disk->minors);
}

-#define to_disk(obj) container_of(obj,struct gendisk,kobj)
-
/**
* get_gendisk - get partitioning information for a given device
* @dev: device to get partitioning information for
@@ -204,10 +202,12 @@ void unlink_gendisk(struct gendisk *disk)
* This function gets the structure containing partitioning
* information for the given device @dev.
*/
-struct gendisk *get_gendisk(dev_t dev, int *part)
+struct gendisk *get_gendisk(dev_t devt, int *part)
{
- struct kobject *kobj = kobj_lookup(bdev_map, dev, part);
- return kobj ? to_disk(kobj) : NULL;
+ struct kobject *kobj = kobj_lookup(bdev_map, devt, part);
+ struct device *dev = kobj_to_dev(kobj);
+
+ return kobj ? dev_to_disk(dev) : NULL;
}

/*
@@ -217,13 +217,17 @@ struct gendisk *get_gendisk(dev_t dev, int *part)
*/
void __init printk_all_partitions(void)
{
- int n;
+ struct device *dev;
struct gendisk *sgp;
+ char buf[BDEVNAME_SIZE];
+ int n;

- mutex_lock(&block_subsys_lock);
+ mutex_lock(&block_class_lock);
/* For each block device... */
- list_for_each_entry(sgp, &block_kset->list, kobj.entry) {
- char buf[BDEVNAME_SIZE];
+ list_for_each_entry(dev, &block_class.devices, node) {
+ if (dev->type != &disk_type)
+ continue;
+ sgp = dev_to_disk(dev);
/*
* Don't show empty devices or things that have been surpressed
*/
@@ -256,38 +260,46 @@ void __init printk_all_partitions(void)
sgp->major, n + 1 + sgp->first_minor,
(unsigned long long)sgp->part[n]->nr_sects >> 1,
disk_name(sgp, n + 1, buf));
- } /* partition subloop */
- } /* Block device loop */
+ }
+ }

- mutex_unlock(&block_subsys_lock);
- return;
+ mutex_unlock(&block_class_lock);
}

#ifdef CONFIG_PROC_FS
/* iterator */
static void *part_start(struct seq_file *part, loff_t *pos)
{
- struct list_head *p;
- loff_t l = *pos;
+ loff_t k = *pos;
+ struct device *dev;

- mutex_lock(&block_subsys_lock);
- list_for_each(p, &block_kset->list)
- if (!l--)
- return list_entry(p, struct gendisk, kobj.entry);
+ mutex_lock(&block_class_lock);
+ list_for_each_entry(dev, &block_class.devices, node) {
+ if (dev->type != &disk_type)
+ continue;
+ if (!k--)
+ return dev_to_disk(dev);
+ }
return NULL;
}

static void *part_next(struct seq_file *part, void *v, loff_t *pos)
{
- struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
+ struct gendisk *gp = v;
+ struct device *dev;
++*pos;
- return p==&block_kset->list ? NULL :
- list_entry(p, struct gendisk, kobj.entry);
+ list_for_each_entry(dev, &gp->dev.node, node) {
+ if (&dev->node == &block_class.devices)
+ return NULL;
+ if (dev->type == &disk_type)
+ return dev_to_disk(dev);
+ }
+ return NULL;
}

static void part_stop(struct seq_file *part, void *v)
{
- mutex_unlock(&block_subsys_lock);
+ mutex_unlock(&block_class_lock);
}

static int show_partition(struct seq_file *part, void *v)
@@ -296,7 +308,7 @@ static int show_partition(struct seq_file *part, void *v)
int n;
char buf[BDEVNAME_SIZE];

- if (&sgp->kobj.entry == block_kset->list.next)
+ if (&sgp->dev.node == block_class.devices.next)
seq_puts(part, "major minor #blocks name\n\n");

/* Don't show non-partitionable removeable devices or empty devices */
@@ -326,109 +338,81 @@ static int show_partition(struct seq_file *part, void *v)
}

struct seq_operations partitions_op = {
- .start =part_start,
- .next = part_next,
- .stop = part_stop,
- .show = show_partition
+ .start = part_start,
+ .next = part_next,
+ .stop = part_stop,
+ .show = show_partition
};
#endif


extern int blk_dev_init(void);

-static struct kobject *base_probe(dev_t dev, int *part, void *data)
+static struct kobject *base_probe(dev_t devt, int *part, void *data)
{
- if (request_module("block-major-%d-%d", MAJOR(dev), MINOR(dev)) > 0)
+ if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
/* Make old-style 2.4 aliases work */
- request_module("block-major-%d", MAJOR(dev));
+ request_module("block-major-%d", MAJOR(devt));
return NULL;
}

static int __init genhd_device_init(void)
{
- bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
+ class_register(&block_class);
+ bdev_map = kobj_map_init(base_probe, &block_class_lock);
blk_dev_init();
- block_kset = kset_create_and_add("block", &block_uevent_ops, NULL);
- if (!block_kset) {
- printk(KERN_WARNING "%s: kset_create error\n", __FUNCTION__);
- return -ENOMEM;
- }
+
+#ifndef CONFIG_SYSFS_DEPRECATED
+ /* create top-level block dir */
+ block_depr = kobject_create_and_add("block", NULL);
+#endif
return 0;
}

subsys_initcall(genhd_device_init);

-
-
-/*
- * kobject & sysfs bindings for block devices
- */
-static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr,
- char *page)
+static ssize_t disk_range_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- struct gendisk *disk = to_disk(kobj);
- struct disk_attribute *disk_attr =
- container_of(attr,struct disk_attribute,attr);
- ssize_t ret = -EIO;
+ struct gendisk *disk = dev_to_disk(dev);

- if (disk_attr->show)
- ret = disk_attr->show(disk,page);
- return ret;
+ return sprintf(buf, "%d\n", disk->minors);
}

-static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr,
- const char *page, size_t count)
+static ssize_t disk_removable_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- struct gendisk *disk = to_disk(kobj);
- struct disk_attribute *disk_attr =
- container_of(attr,struct disk_attribute,attr);
- ssize_t ret = 0;
+ struct gendisk *disk = dev_to_disk(dev);

- if (disk_attr->store)
- ret = disk_attr->store(disk, page, count);
- return ret;
+ return sprintf(buf, "%d\n",
+ (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
}

-static struct sysfs_ops disk_sysfs_ops = {
- .show = &disk_attr_show,
- .store = &disk_attr_store,
-};
-
-static ssize_t disk_uevent_store(struct gendisk * disk,
- const char *buf, size_t count)
+static ssize_t disk_size_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- kobject_uevent(&disk->kobj, KOBJ_ADD);
- return count;
-}
-static ssize_t disk_dev_read(struct gendisk * disk, char *page)
-{
- dev_t base = MKDEV(disk->major, disk->first_minor);
- return print_dev_t(page, base);
-}
-static ssize_t disk_range_read(struct gendisk * disk, char *page)
-{
- return sprintf(page, "%d\n", disk->minors);
-}
-static ssize_t disk_removable_read(struct gendisk * disk, char *page)
-{
- return sprintf(page, "%d\n",
- (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
+ struct gendisk *disk = dev_to_disk(dev);

+ return sprintf(buf, "%llu\n", (unsigned long long)get_capacity(disk));
}
-static ssize_t disk_size_read(struct gendisk * disk, char *page)
-{
- return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
-}
-static ssize_t disk_capability_read(struct gendisk *disk, char *page)
+
+static ssize_t disk_capability_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- return sprintf(page, "%x\n", disk->flags);
+ struct gendisk *disk = dev_to_disk(dev);
+
+ return sprintf(buf, "%x\n", disk->flags);
}
-static ssize_t disk_stats_read(struct gendisk * disk, char *page)
+
+static ssize_t disk_stat_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
+ struct gendisk *disk = dev_to_disk(dev);
+
preempt_disable();
disk_round_stats(disk);
preempt_enable();
- return sprintf(page,
+ return sprintf(buf,
"%8lu %8lu %8llu %8u "
"%8lu %8lu %8llu %8u "
"%8u %8u %8u"
@@ -445,40 +429,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
}
-static struct disk_attribute disk_attr_uevent = {
- .attr = {.name = "uevent", .mode = S_IWUSR },
- .store = disk_uevent_store
-};
-static struct disk_attribute disk_attr_dev = {
- .attr = {.name = "dev", .mode = S_IRUGO },
- .show = disk_dev_read
-};
-static struct disk_attribute disk_attr_range = {
- .attr = {.name = "range", .mode = S_IRUGO },
- .show = disk_range_read
-};
-static struct disk_attribute disk_attr_removable = {
- .attr = {.name = "removable", .mode = S_IRUGO },
- .show = disk_removable_read
-};
-static struct disk_attribute disk_attr_size = {
- .attr = {.name = "size", .mode = S_IRUGO },
- .show = disk_size_read
-};
-static struct disk_attribute disk_attr_capability = {
- .attr = {.name = "capability", .mode = S_IRUGO },
- .show = disk_capability_read
-};
-static struct disk_attribute disk_attr_stat = {
- .attr = {.name = "stat", .mode = S_IRUGO },
- .show = disk_stats_read
-};

#ifdef CONFIG_FAIL_MAKE_REQUEST
+static ssize_t disk_fail_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+
+ return sprintf(buf, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
+}

-static ssize_t disk_fail_store(struct gendisk * disk,
+static ssize_t disk_fail_store(struct device *dev,
+ struct device_attribute *attr,
const char *buf, size_t count)
{
+ struct gendisk *disk = dev_to_disk(dev);
int i;

if (count > 0 && sscanf(buf, "%d", &i) > 0) {
@@ -490,134 +455,100 @@ static ssize_t disk_fail_store(struct gendisk * disk,

return count;
}
-static ssize_t disk_fail_read(struct gendisk * disk, char *page)
-{
- return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
-}
-static struct disk_attribute disk_attr_fail = {
- .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
- .store = disk_fail_store,
- .show = disk_fail_read
-};

#endif

-static struct attribute * default_attrs[] = {
- &disk_attr_uevent.attr,
- &disk_attr_dev.attr,
- &disk_attr_range.attr,
- &disk_attr_removable.attr,
- &disk_attr_size.attr,
- &disk_attr_stat.attr,
- &disk_attr_capability.attr,
+static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
+static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL);
+static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
+static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);
#ifdef CONFIG_FAIL_MAKE_REQUEST
- &disk_attr_fail.attr,
+static struct device_attribute dev_attr_fail =
+ __ATTR(make-it-fail, S_IRUGO|S_IWUSR, disk_fail_show, disk_fail_store);
#endif
- NULL,
+
+static struct attribute *disk_attrs[] = {
+ &dev_attr_range.attr,
+ &dev_attr_removable.attr,
+ &dev_attr_size.attr,
+ &dev_attr_capability.attr,
+ &dev_attr_stat.attr,
+#ifdef CONFIG_FAIL_MAKE_REQUEST
+ &dev_attr_fail.attr,
+#endif
+ NULL
+};
+
+static struct attribute_group disk_attr_group = {
+ .attrs = disk_attrs,
+};
+
+static struct attribute_group *disk_attr_groups[] = {
+ &disk_attr_group,
+ NULL
};

-static void disk_release(struct kobject * kobj)
+static void disk_release(struct device *dev)
{
- struct gendisk *disk = to_disk(kobj);
+ struct gendisk *disk = dev_to_disk(dev);
+
kfree(disk->random);
kfree(disk->part);
free_disk_stats(disk);
kfree(disk);
}
-
-static struct kobj_type ktype_block = {
- .release = disk_release,
- .sysfs_ops = &disk_sysfs_ops,
- .default_attrs = default_attrs,
+struct class block_class = {
+ .name = "block",
};

-extern struct kobj_type ktype_part;
-
-static int block_uevent_filter(struct kset *kset, struct kobject *kobj)
-{
- struct kobj_type *ktype = get_ktype(kobj);
-
- return ((ktype == &ktype_block) || (ktype == &ktype_part));
-}
-
-static int block_uevent(struct kset *kset, struct kobject *kobj,
- struct kobj_uevent_env *env)
-{
- struct kobj_type *ktype = get_ktype(kobj);
- struct device *physdev;
- struct gendisk *disk;
- struct hd_struct *part;
-
- if (ktype == &ktype_block) {
- disk = container_of(kobj, struct gendisk, kobj);
- add_uevent_var(env, "MINOR=%u", disk->first_minor);
- } else if (ktype == &ktype_part) {
- disk = container_of(kobj->parent, struct gendisk, kobj);
- part = container_of(kobj, struct hd_struct, kobj);
- add_uevent_var(env, "MINOR=%u",
- disk->first_minor + part->partno);
- } else
- return 0;
-
- add_uevent_var(env, "MAJOR=%u", disk->major);
-
- /* add physical device, backing this device */
- physdev = disk->driverfs_dev;
- if (physdev) {
- char *path = kobject_get_path(&physdev->kobj, GFP_KERNEL);
-
- add_uevent_var(env, "PHYSDEVPATH=%s", path);
- kfree(path);
-
- if (physdev->bus)
- add_uevent_var(env, "PHYSDEVBUS=%s", physdev->bus->name);
-
- if (physdev->driver)
- add_uevent_var(env, physdev->driver->name);
- }
-
- return 0;
-}
-
-static struct kset_uevent_ops block_uevent_ops = {
- .filter = block_uevent_filter,
- .uevent = block_uevent,
+struct device_type disk_type = {
+ .name = "disk",
+ .groups = disk_attr_groups,
+ .release = disk_release,
};

/*
* aggregate disk stat collector. Uses the same stats that the sysfs
* entries do, above, but makes them available through one seq_file.
- * Watching a few disks may be efficient through sysfs, but watching
- * all of them will be more efficient through this interface.
*
* The output looks suspiciously like /proc/partitions with a bunch of
* extra fields.
*/

-/* iterator */
static void *diskstats_start(struct seq_file *part, loff_t *pos)
{
loff_t k = *pos;
- struct list_head *p;
+ struct device *dev;

- mutex_lock(&block_subsys_lock);
- list_for_each(p, &block_kset->list)
+ mutex_lock(&block_class_lock);
+ list_for_each_entry(dev, &block_class.devices, node) {
+ if (dev->type != &disk_type)
+ continue;
if (!k--)
- return list_entry(p, struct gendisk, kobj.entry);
+ return dev_to_disk(dev);
+ }
return NULL;
}

static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
{
- struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
+ struct gendisk *gp = v;
+ struct device *dev;
+
++*pos;
- return p==&block_kset->list ? NULL :
- list_entry(p, struct gendisk, kobj.entry);
+ list_for_each_entry(dev, &gp->dev.node, node) {
+ if (&dev->node == &block_class.devices)
+ return NULL;
+ if (dev->type == &disk_type)
+ return dev_to_disk(dev);
+ }
+ return NULL;
}

static void diskstats_stop(struct seq_file *part, void *v)
{
- mutex_unlock(&block_subsys_lock);
+ mutex_unlock(&block_class_lock);
}

static int diskstats_show(struct seq_file *s, void *v)
@@ -627,7 +558,7 @@ static int diskstats_show(struct seq_file *s, void *v)
int n = 0;

/*
- if (&sgp->kobj.entry == block_kset->list.next)
+ if (&gp->dev.kobj.entry == block_class.devices.next)
seq_puts(s, "major minor name"
" rio rmerge rsect ruse wio wmerge "
"wsect wuse running use aveq"
@@ -681,7 +612,7 @@ static void media_change_notify_thread(struct work_struct *work)
* set enviroment vars to indicate which event this is for
* so that user space will know to go check the media status.
*/
- kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp);
+ kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp);
put_device(gd->driverfs_dev);
}

@@ -692,6 +623,25 @@ void genhd_media_change_notify(struct gendisk *disk)
}
EXPORT_SYMBOL_GPL(genhd_media_change_notify);

+dev_t blk_lookup_devt(const char *name)
+{
+ struct device *dev;
+ dev_t devt = MKDEV(0, 0);
+
+ mutex_lock(&block_class_lock);
+ list_for_each_entry(dev, &block_class.devices, node) {
+ if (strcmp(dev->bus_id, name) == 0) {
+ devt = dev->devt;
+ break;
+ }
+ }
+ mutex_unlock(&block_class_lock);
+
+ return devt;
+}
+
+EXPORT_SYMBOL(blk_lookup_devt);
+
struct gendisk *alloc_disk(int minors)
{
return alloc_disk_node(minors, -1);
@@ -719,10 +669,10 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
}
}
disk->minors = minors;
- disk->kobj.kset = block_kset;
- disk->kobj.ktype = &ktype_block;
- kobject_init(&disk->kobj);
rand_initialize_disk(disk);
+ disk->dev.class = &block_class;
+ disk->dev.type = &disk_type;
+ device_initialize(&disk->dev);
INIT_WORK(&disk->async_notify,
media_change_notify_thread);
}
@@ -742,7 +692,7 @@ struct kobject *get_disk(struct gendisk *disk)
owner = disk->fops->owner;
if (owner && !try_module_get(owner))
return NULL;
- kobj = kobject_get(&disk->kobj);
+ kobj = kobject_get(&disk->dev.kobj);
if (kobj == NULL) {
module_put(owner);
return NULL;
@@ -756,7 +706,7 @@ EXPORT_SYMBOL(get_disk);
void put_disk(struct gendisk *disk)
{
if (disk)
- kobject_put(&disk->kobj);
+ kobject_put(&disk->dev.kobj);
}

EXPORT_SYMBOL(put_disk);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 8b91994..3887b2a 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -4182,7 +4182,7 @@ int blk_register_queue(struct gendisk *disk)
if (!q || !q->request_fn)
return -ENXIO;

- q->kobj.parent = kobject_get(&disk->kobj);
+ q->kobj.parent = kobject_get(&disk->dev.kobj);

ret = kobject_add(&q->kobj);
if (ret < 0)
@@ -4209,6 +4209,6 @@ void blk_unregister_queue(struct gendisk *disk)

kobject_uevent(&q->kobj, KOBJ_REMOVE);
kobject_del(&q->kobj);
- kobject_put(&disk->kobj);
+ kobject_put(&disk->dev.kobj);
}
}
diff --git a/drivers/base/class.c b/drivers/base/class.c
index ba6745b..624b331 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -17,6 +17,7 @@
#include <linux/kdev_t.h>
#include <linux/err.h>
#include <linux/slab.h>
+#include <linux/genhd.h>
#include "base.h"

#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
@@ -149,7 +150,13 @@ int class_register(struct class * cls)
if (error)
return error;

+#ifdef CONFIG_SYSFS_DEPRECATED
+ /* let the block class directory show up in the root of sysfs */
+ if (cls != &block_class)
+ cls->subsys.kobj.kset = class_kset;
+#else
cls->subsys.kobj.kset = class_kset;
+#endif
cls->subsys.kobj.ktype = &class_ktype;

error = kset_register(&cls->subsys);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 13cae18..06e8738 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev)

#ifdef CONFIG_SYSFS_DEPRECATED
/* stacked class devices need a symlink in the class directory */
- if (dev->kobj.parent != &dev->class->subsys.kobj) {
+ if (dev->kobj.parent != &dev->class->subsys.kobj &&
+ dev->type != &part_type) {
error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
dev->bus_id);
if (error)
goto out_subsys;
}

- if (dev->parent) {
+ if (dev->parent && dev->type != &part_type) {
struct device *parent = dev->parent;
char *class_name;

@@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev)
return 0;

out_device:
- if (dev->parent)
+ if (dev->parent && dev->type != &part_type)
sysfs_remove_link(&dev->kobj, "device");
out_busid:
- if (dev->kobj.parent != &dev->class->subsys.kobj)
+ if (dev->kobj.parent != &dev->class->subsys.kobj &&
+ dev->type != &part_type)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
#else
/* link in the class directory pointing to the device */
@@ -719,7 +721,7 @@ out_busid:
if (error)
goto out_subsys;

- if (dev->parent) {
+ if (dev->parent && dev->type != &part_type) {
error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
"device");
if (error)
@@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev)
return;

#ifdef CONFIG_SYSFS_DEPRECATED
- if (dev->parent) {
+ if (dev->parent && dev->type != &part_type) {
char *class_name;

class_name = make_class_name(dev->class->name, &dev->kobj);
@@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev)
sysfs_remove_link(&dev->kobj, "device");
}

- if (dev->kobj.parent != &dev->class->subsys.kobj)
+ if (dev->kobj.parent != &dev->class->subsys.kobj &&
+ dev->type != &part_type)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
#else
- if (dev->parent)
+ if (dev->parent && dev->type != &part_type)
sysfs_remove_link(&dev->kobj, "device");

sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
@@ -925,6 +928,7 @@ struct device * get_device(struct device * dev)
*/
void put_device(struct device * dev)
{
+ /* might_sleep(); */
if (dev)
kobject_put(&dev->kobj);
}
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index ad00b3d..826d123 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -15,8 +15,10 @@

static struct kmem_cache *buf_pool_cache;

-static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
+static ssize_t aoedisk_show_state(struct device *dev,
+ struct device_attribute *attr, char *page)
{
+ struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data;

return snprintf(page, PAGE_SIZE,
@@ -26,50 +28,47 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
(d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
/* I'd rather see nopen exported so we can ditch closewait */
}
-static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page)
+static ssize_t aoedisk_show_mac(struct device *dev,
+ struct device_attribute *attr, char *page)
{
+ struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data;

return snprintf(page, PAGE_SIZE, "%012llx\n",
(unsigned long long)mac_addr(d->addr));
}
-static ssize_t aoedisk_show_netif(struct gendisk * disk, char *page)
+static ssize_t aoedisk_show_netif(struct device *dev,
+ struct device_attribute *attr, char *page)
{
+ struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data;

return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name);
}
/* firmware version */
-static ssize_t aoedisk_show_fwver(struct gendisk * disk, char *page)
+static ssize_t aoedisk_show_fwver(struct device *dev,
+ struct device_attribute *attr, char *page)
{
+ struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data;

return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver);
}

-static struct disk_attribute disk_attr_state = {
- .attr = {.name = "state", .mode = S_IRUGO },
- .show = aoedisk_show_state
-};
-static struct disk_attribute disk_attr_mac = {
- .attr = {.name = "mac", .mode = S_IRUGO },
- .show = aoedisk_show_mac
-};
-static struct disk_attribute disk_attr_netif = {
- .attr = {.name = "netif", .mode = S_IRUGO },
- .show = aoedisk_show_netif
-};
-static struct disk_attribute disk_attr_fwver = {
- .attr = {.name = "firmware-version", .mode = S_IRUGO },
- .show = aoedisk_show_fwver
+static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL);
+static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL);
+static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL);
+static struct device_attribute dev_attr_firmware_version = {
+ .attr = { .name = "firmware-version", .mode = S_IRUGO, .owner = THIS_MODULE },
+ .show = aoedisk_show_fwver,
};

static struct attribute *aoe_attrs[] = {
- &disk_attr_state.attr,
- &disk_attr_mac.attr,
- &disk_attr_netif.attr,
- &disk_attr_fwver.attr,
- NULL
+ &dev_attr_state.attr,
+ &dev_attr_mac.attr,
+ &dev_attr_netif.attr,
+ &dev_attr_firmware_version.attr,
+ NULL,
};

static const struct attribute_group attr_group = {
@@ -79,12 +78,12 @@ static const struct attribute_group attr_group = {
static int
aoedisk_add_sysfs(struct aoedev *d)
{
- return sysfs_create_group(&d->gd->kobj, &attr_group);
+ return sysfs_create_group(&d->gd->dev.kobj, &attr_group);
}
void
aoedisk_rm_sysfs(struct aoedev *d)
{
- sysfs_remove_group(&d->gd->kobj, &attr_group);
+ sysfs_remove_group(&d->gd->dev.kobj, &attr_group);
}

static int
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index b4c0888..ba9b17e 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -375,14 +375,17 @@ harderror:
return NULL;
}

-static ssize_t pid_show(struct gendisk *disk, char *page)
+static ssize_t pid_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- return sprintf(page, "%ld\n",
+ struct gendisk *disk = dev_to_disk(dev);
+
+ return sprintf(buf, "%ld\n",
(long) ((struct nbd_device *)disk->private_data)->pid);
}

-static struct disk_attribute pid_attr = {
- .attr = { .name = "pid", .mode = S_IRUGO },
+static struct device_attribute pid_attr = {
+ .attr = { .name = "pid", .mode = S_IRUGO, .owner = THIS_MODULE },
.show = pid_show,
};

@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo)
BUG_ON(lo->magic != LO_MAGIC);

lo->pid = current->pid;
- ret = sysfs_create_file(&lo->disk->kobj, &pid_attr.attr);
+ ret = sysfs_create_file(&lo->disk->dev.kobj, &pid_attr.attr);
if (ret) {
printk(KERN_ERR "nbd: sysfs_create_file failed!");
return ret;
@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)
while ((req = nbd_read_stat(lo)) != NULL)
nbd_end_request(req);

- sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr);
+ sysfs_remove_file(&lo->disk->dev.kobj, &pid_attr.attr);
return 0;
}

diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 2994523..0cb3d2b 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
{
struct gendisk *p = data;
*part &= (1 << PARTN_BITS) - 1;
- return &p->kobj;
+ return &p->dev.kobj;
}

static int exact_lock(dev_t dev, void *data)
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 88c0fd6..f2d24eb 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1109,7 +1109,7 @@ static void event_callback(void *context)
list_splice_init(&md->uevent_list, &uevents);
spin_unlock_irqrestore(&md->uevent_lock, flags);

- dm_send_uevents(&uevents, &md->disk->kobj);
+ dm_send_uevents(&uevents, &md->disk->dev.kobj);

atomic_inc(&md->event_nr);
wake_up(&md->eventq);
@@ -1530,7 +1530,7 @@ out:
*---------------------------------------------------------------*/
void dm_kobject_uevent(struct mapped_device *md)
{
- kobject_uevent(&md->disk->kobj, KOBJ_CHANGE);
+ kobject_uevent(&md->disk->dev.kobj, KOBJ_CHANGE);
}

uint32_t dm_next_uevent_seq(struct mapped_device *md)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index c503086..f79efb3 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1396,9 +1396,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
goto fail;

if (rdev->bdev->bd_part)
- ko = &rdev->bdev->bd_part->kobj;
+ ko = &rdev->bdev->bd_part->dev.kobj;
else
- ko = &rdev->bdev->bd_disk->kobj;
+ ko = &rdev->bdev->bd_disk->dev.kobj;
if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
kobject_del(&rdev->kobj);
goto fail;
@@ -3083,7 +3083,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
add_disk(disk);
mddev->gendisk = disk;
mutex_unlock(&disks_mutex);
- error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->kobj,
+ error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
"%s", "md");
if (error)
printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
@@ -3361,7 +3361,7 @@ static int do_md_run(mddev_t * mddev)

mddev->changed = 1;
md_new_event(mddev);
- kobject_uevent(&mddev->gendisk->kobj, KOBJ_CHANGE);
+ kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
return 0;
}

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 993f78c..e48a630 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release);
static struct kobject *bdev_get_kobj(struct block_device *bdev)
{
if (bdev->bd_contains != bdev)
- return kobject_get(&bdev->bd_part->kobj);
+ return kobject_get(&bdev->bd_part->dev.kobj);
else
- return kobject_get(&bdev->bd_disk->kobj);
+ return kobject_get(&bdev->bd_disk->dev.kobj);
}

static struct kobject *bdev_get_holder(struct block_device *bdev)
@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
ret = -ENXIO;
goto out_first;
}
- kobject_get(&p->kobj);
+ kobject_get(&p->dev.kobj);
bdev->bd_part = p;
bd_set_size(bdev, (loff_t) p->nr_sects << 9);
}
@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
module_put(owner);

if (bdev->bd_contains != bdev) {
- kobject_put(&bdev->bd_part->kobj);
+ kobject_put(&bdev->bd_part->dev.kobj);
bdev->bd_part = NULL;
}
bdev->bd_disk = NULL;
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 9184215..97f3f5f 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -195,96 +195,45 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
return ERR_PTR(res);
}

-/*
- * sysfs bindings for partitions
- */
-
-struct part_attribute {
- struct attribute attr;
- ssize_t (*show)(struct hd_struct *,char *);
- ssize_t (*store)(struct hd_struct *,const char *, size_t);
-};
-
-static ssize_t
-part_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
+static ssize_t part_start_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- struct hd_struct * p = container_of(kobj,struct hd_struct,kobj);
- struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
- ssize_t ret = 0;
- if (part_attr->show)
- ret = part_attr->show(p, page);
- return ret;
-}
-static ssize_t
-part_attr_store(struct kobject * kobj, struct attribute * attr,
- const char *page, size_t count)
-{
- struct hd_struct * p = container_of(kobj,struct hd_struct,kobj);
- struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
- ssize_t ret = 0;
+ struct hd_struct *p = dev_to_part(dev);

- if (part_attr->store)
- ret = part_attr->store(p, page, count);
- return ret;
+ return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
}

-static struct sysfs_ops part_sysfs_ops = {
- .show = part_attr_show,
- .store = part_attr_store,
-};
-
-static ssize_t part_uevent_store(struct hd_struct * p,
- const char *page, size_t count)
+static ssize_t part_size_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- kobject_uevent(&p->kobj, KOBJ_ADD);
- return count;
+ struct hd_struct *p = dev_to_part(dev);
+ return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
}
-static ssize_t part_dev_read(struct hd_struct * p, char *page)
-{
- struct gendisk *disk = container_of(p->kobj.parent,struct gendisk,kobj);
- dev_t dev = MKDEV(disk->major, disk->first_minor + p->partno);
- return print_dev_t(page, dev);
-}
-static ssize_t part_start_read(struct hd_struct * p, char *page)
-{
- return sprintf(page, "%llu\n",(unsigned long long)p->start_sect);
-}
-static ssize_t part_size_read(struct hd_struct * p, char *page)
-{
- return sprintf(page, "%llu\n",(unsigned long long)p->nr_sects);
-}
-static ssize_t part_stat_read(struct hd_struct * p, char *page)
+
+static ssize_t part_stat_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
{
- return sprintf(page, "%8u %8llu %8u %8llu\n",
+ struct hd_struct *p = dev_to_part(dev);
+
+ return sprintf(buf, "%8u %8llu %8u %8llu\n",
p->ios[0], (unsigned long long)p->sectors[0],
p->ios[1], (unsigned long long)p->sectors[1]);
}
-static struct part_attribute part_attr_uevent = {
- .attr = {.name = "uevent", .mode = S_IWUSR },
- .store = part_uevent_store
-};
-static struct part_attribute part_attr_dev = {
- .attr = {.name = "dev", .mode = S_IRUGO },
- .show = part_dev_read
-};
-static struct part_attribute part_attr_start = {
- .attr = {.name = "start", .mode = S_IRUGO },
- .show = part_start_read
-};
-static struct part_attribute part_attr_size = {
- .attr = {.name = "size", .mode = S_IRUGO },
- .show = part_size_read
-};
-static struct part_attribute part_attr_stat = {
- .attr = {.name = "stat", .mode = S_IRUGO },
- .show = part_stat_read
-};

#ifdef CONFIG_FAIL_MAKE_REQUEST
+static ssize_t part_fail_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct hd_struct *p = dev_to_part(dev);

-static ssize_t part_fail_store(struct hd_struct * p,
+ return sprintf(buf, "%d\n", p->make_it_fail);
+}
+
+static ssize_t part_fail_store(struct device *dev,
+ struct device_attribute *attr,
const char *buf, size_t count)
{
+ struct hd_struct *p = dev_to_part(dev);
int i;

if (count > 0 && sscanf(buf, "%d", &i) > 0)
@@ -292,49 +241,52 @@ static ssize_t part_fail_store(struct hd_struct * p,

return count;
}
-static ssize_t part_fail_read(struct hd_struct * p, char *page)
-{
- return sprintf(page, "%d\n", p->make_it_fail);
-}
-static struct part_attribute part_attr_fail = {
- .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
- .store = part_fail_store,
- .show = part_fail_read
-};
+#endif

+static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
+static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
+#ifdef CONFIG_FAIL_MAKE_REQUEST
+static struct device_attribute dev_attr_fail =
+ __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
#endif

-static struct attribute * default_attrs[] = {
- &part_attr_uevent.attr,
- &part_attr_dev.attr,
- &part_attr_start.attr,
- &part_attr_size.attr,
- &part_attr_stat.attr,
+static struct attribute *part_attrs[] = {
+ &dev_attr_start.attr,
+ &dev_attr_size.attr,
+ &dev_attr_stat.attr,
#ifdef CONFIG_FAIL_MAKE_REQUEST
- &part_attr_fail.attr,
+ &dev_attr_fail.attr,
#endif
- NULL,
+ NULL
};

-extern struct kset *block_kset;
+static struct attribute_group part_attr_group = {
+ .attrs = part_attrs,
+};

-static void part_release(struct kobject *kobj)
+static struct attribute_group *part_attr_groups[] = {
+ &part_attr_group,
+ NULL
+};
+
+static void part_release(struct device *dev)
{
- struct hd_struct * p = container_of(kobj,struct hd_struct,kobj);
+ struct hd_struct *p = dev_to_part(dev);
kfree(p);
}

-struct kobj_type ktype_part = {
+struct device_type part_type = {
+ .name = "partition",
+ .groups = part_attr_groups,
.release = part_release,
- .default_attrs = default_attrs,
- .sysfs_ops = &part_sysfs_ops,
};

static inline void partition_sysfs_add_subdir(struct hd_struct *p)
{
struct kobject *k;

- k = kobject_get(&p->kobj);
+ k = kobject_get(&p->dev.kobj);
p->holder_dir = kobject_create_and_add("holders", k);
kobject_put(k);
}
@@ -343,7 +295,7 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
{
struct kobject *k;

- k = kobject_get(&disk->kobj);
+ k = kobject_get(&disk->dev.kobj);
disk->holder_dir = kobject_create_and_add("holders", k);
disk->slave_dir = kobject_create_and_add("slaves", k);
kobject_put(k);
@@ -352,6 +304,7 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
void delete_partition(struct gendisk *disk, int part)
{
struct hd_struct *p = disk->part[part-1];
+
if (!p)
return;
if (!p->nr_sects)
@@ -361,113 +314,55 @@ void delete_partition(struct gendisk *disk, int part)
p->nr_sects = 0;
p->ios[0] = p->ios[1] = 0;
p->sectors[0] = p->sectors[1] = 0;
- sysfs_remove_link(&p->kobj, "subsystem");
kobject_unregister(p->holder_dir);
- kobject_uevent(&p->kobj, KOBJ_REMOVE);
- kobject_del(&p->kobj);
- kobject_put(&p->kobj);
+ device_del(&p->dev);
+ put_device(&p->dev);
}

void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags)
{
struct hd_struct *p;
+ int err;

p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p)
return;
-
+
p->start_sect = start;
p->nr_sects = len;
p->partno = part;
p->policy = disk->policy;

- if (isdigit(disk->kobj.k_name[strlen(disk->kobj.k_name)-1]))
- kobject_set_name(&p->kobj, "%sp%d",
- kobject_name(&disk->kobj), part);
+ if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1]))
+ snprintf(p->dev.bus_id, BUS_ID_SIZE,
+ "%sp%d", disk->dev.bus_id, part);
else
- kobject_set_name(&p->kobj, "%s%d",
- kobject_name(&disk->kobj),part);
- p->kobj.parent = &disk->kobj;
- p->kobj.ktype = &ktype_part;
- kobject_init(&p->kobj);
- kobject_add(&p->kobj);
- if (!disk->part_uevent_suppress)
- kobject_uevent(&p->kobj, KOBJ_ADD);
- sysfs_create_link(&p->kobj, &block_kset->kobj, "subsystem");
+ snprintf(p->dev.bus_id, BUS_ID_SIZE,
+ "%s%d", disk->dev.bus_id, part);
+
+ device_initialize(&p->dev);
+ p->dev.devt = MKDEV(disk->major, disk->first_minor + part);
+ p->dev.class = &block_class;
+ p->dev.type = &part_type;
+ p->dev.parent = &disk->dev;
+ disk->part[part-1] = p;
+
+ /* delay uevent until 'holders' subdir is created */
+ p->dev.uevent_suppress = 1;
+ device_add(&p->dev);
+ partition_sysfs_add_subdir(p);
+ p->dev.uevent_suppress = 0;
if (flags & ADDPART_FLAG_WHOLEDISK) {
static struct attribute addpartattr = {
.name = "whole_disk",
.mode = S_IRUSR | S_IRGRP | S_IROTH,
};
-
- sysfs_create_file(&p->kobj, &addpartattr);
+ err = sysfs_create_file(&p->dev.kobj, &addpartattr);
}
- partition_sysfs_add_subdir(p);
- disk->part[part-1] = p;
-}

-static char *make_block_name(struct gendisk *disk)
-{
- char *name;
- static char *block_str = "block:";
- int size;
- char *s;
-
- size = strlen(block_str) + strlen(disk->disk_name) + 1;
- name = kmalloc(size, GFP_KERNEL);
- if (!name)
- return NULL;
- strcpy(name, block_str);
- strcat(name, disk->disk_name);
- /* ewww... some of these buggers have / in name... */
- s = strchr(name, '/');
- if (s)
- *s = '!';
- return name;
-}
-
-static int disk_sysfs_symlinks(struct gendisk *disk)
-{
- struct device *target = get_device(disk->driverfs_dev);
- int err;
- char *disk_name = NULL;
-
- if (target) {
- disk_name = make_block_name(disk);
- if (!disk_name) {
- err = -ENOMEM;
- goto err_out;
- }
-
- err = sysfs_create_link(&disk->kobj, &target->kobj, "device");
- if (err)
- goto err_out_disk_name;
-
- err = sysfs_create_link(&target->kobj, &disk->kobj, disk_name);
- if (err)
- goto err_out_dev_link;
- }
-
- err = sysfs_create_link(&disk->kobj, &block_kset->kobj,
- "subsystem");
- if (err)
- goto err_out_disk_name_lnk;
-
- kfree(disk_name);
-
- return 0;
-
-err_out_disk_name_lnk:
- if (target) {
- sysfs_remove_link(&target->kobj, disk_name);
-err_out_dev_link:
- sysfs_remove_link(&disk->kobj, "device");
-err_out_disk_name:
- kfree(disk_name);
-err_out:
- put_device(target);
- }
- return err;
+ /* suppress uevent if the disk supresses it */
+ if (!disk->dev.uevent_suppress)
+ kobject_uevent(&p->dev.kobj, KOBJ_ADD);
}

/* Not exported, helper to add_disk(). */
@@ -479,19 +374,29 @@ void register_disk(struct gendisk *disk)
struct hd_struct *p;
int err;

- kobject_set_name(&disk->kobj, "%s", disk->disk_name);
- /* ewww... some of these buggers have / in name... */
- s = strchr(disk->kobj.k_name, '/');
+ disk->dev.parent = disk->driverfs_dev;
+ disk->dev.devt = MKDEV(disk->major, disk->first_minor);
+
+ strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN);
+ /* ewww... some of these buggers have / in the name... */
+ s = strchr(disk->dev.bus_id, '/');
if (s)
*s = '!';
- if ((err = kobject_add(&disk->kobj)))
+
+ /* delay uevents, until we scanned partition table */
+ disk->dev.uevent_suppress = 1;
+
+ if (device_add(&disk->dev))
return;
- err = disk_sysfs_symlinks(disk);
+#ifndef CONFIG_SYSFS_DEPRECATED
+ err = sysfs_create_link(block_depr, &disk->dev.kobj,
+ kobject_name(&disk->dev.kobj));
if (err) {
- kobject_del(&disk->kobj);
+ device_del(&disk->dev);
return;
}
- disk_sysfs_add_subdirs(disk);
+#endif
+ disk_sysfs_add_subdirs(disk);

/* No minors to use for partitions */
if (disk->minors == 1)
@@ -505,25 +410,23 @@ void register_disk(struct gendisk *disk)
if (!bdev)
goto exit;

- /* scan partition table, but suppress uevents */
bdev->bd_invalidated = 1;
- disk->part_uevent_suppress = 1;
err = blkdev_get(bdev, FMODE_READ, 0);
- disk->part_uevent_suppress = 0;
if (err < 0)
goto exit;
blkdev_put(bdev);

exit:
- /* announce disk after possible partitions are already created */
- kobject_uevent(&disk->kobj, KOBJ_ADD);
+ /* announce disk after possible partitions are created */
+ disk->dev.uevent_suppress = 0;
+ kobject_uevent(&disk->dev.kobj, KOBJ_ADD);

/* announce possible partitions */
for (i = 1; i < disk->minors; i++) {
p = disk->part[i-1];
if (!p || !p->nr_sects)
continue;
- kobject_uevent(&p->kobj, KOBJ_ADD);
+ kobject_uevent(&p->dev.kobj, KOBJ_ADD);
}
}

@@ -602,19 +505,11 @@ void del_gendisk(struct gendisk *disk)
disk_stat_set_all(disk, 0);
disk->stamp = 0;

- kobject_uevent(&disk->kobj, KOBJ_REMOVE);
kobject_unregister(disk->holder_dir);
kobject_unregister(disk->slave_dir);
- if (disk->driverfs_dev) {
- char *disk_name = make_block_name(disk);
- sysfs_remove_link(&disk->kobj, "device");
- if (disk_name) {
- sysfs_remove_link(&disk->driverfs_dev->kobj, disk_name);
- kfree(disk_name);
- }
- put_device(disk->driverfs_dev);
- disk->driverfs_dev = NULL;
- }
- sysfs_remove_link(&disk->kobj, "subsystem");
- kobject_del(&disk->kobj);
+ disk->driverfs_dev = NULL;
+#ifndef CONFIG_SYSFS_DEPRECATED
+ sysfs_remove_link(block_depr, disk->dev.bus_id);
+#endif
+ device_del(&disk->dev);
}
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index a47b802..1dbea0a 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -10,9 +10,19 @@
*/

#include <linux/types.h>
+#include <linux/kdev_t.h>

#ifdef CONFIG_BLOCK

+#define kobj_to_dev(k) container_of(k, struct device, kobj)
+#define dev_to_disk(device) container_of(device, struct gendisk, dev)
+#define dev_to_part(device) container_of(device, struct hd_struct, dev)
+
+extern struct device_type disk_type;
+extern struct device_type part_type;
+extern struct kobject *block_depr;
+extern struct class block_class;
+
enum {
/* These three have identical behaviour; use the second one if DOS FDISK gets
confused about extended/logical partitions starting past cylinder 1023. */
@@ -84,7 +94,7 @@ struct partition {
struct hd_struct {
sector_t start_sect;
sector_t nr_sects;
- struct kobject kobj;
+ struct device dev;
struct kobject *holder_dir;
unsigned ios[2], sectors[2]; /* READs and WRITEs */
int policy, partno;
@@ -117,15 +127,14 @@ struct gendisk {
* disks that can't be partitioned. */
char disk_name[32]; /* name of major driver */
struct hd_struct **part; /* [indexed by minor] */
- int part_uevent_suppress;
struct block_device_operations *fops;
struct request_queue *queue;
void *private_data;
sector_t capacity;

int flags;
- struct device *driverfs_dev;
- struct kobject kobj;
+ struct device *driverfs_dev; // FIXME: remove
+ struct device dev;
struct kobject *holder_dir;
struct kobject *slave_dir;

@@ -143,13 +152,6 @@ struct gendisk {
struct work_struct async_notify;
};

-/* Structure for sysfs attributes on block devices */
-struct disk_attribute {
- struct attribute attr;
- ssize_t (*show)(struct gendisk *, char *);
- ssize_t (*store)(struct gendisk *, const char *, size_t);
-};
-
/*
* Macros to operate on percpu disk statistics:
*
@@ -411,7 +413,8 @@ struct unixware_disklabel {
#define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2

-char *disk_name (struct gendisk *hd, int part, char *buf);
+extern dev_t blk_lookup_devt(const char *name);
+extern char *disk_name (struct gendisk *hd, int part, char *buf);

extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
@@ -423,12 +426,12 @@ extern struct gendisk *alloc_disk(int minors);
extern struct kobject *get_disk(struct gendisk *disk);
extern void put_disk(struct gendisk *disk);
extern void genhd_media_change_notify(struct gendisk *disk);
-extern void blk_register_region(dev_t dev, unsigned long range,
+extern void blk_register_region(dev_t devt, unsigned long range,
struct module *module,
struct kobject *(*probe)(dev_t, int *, void *),
int (*lock)(dev_t, void *),
void *data);
-extern void blk_unregister_region(dev_t dev, unsigned long range);
+extern void blk_unregister_region(dev_t devt, unsigned long range);

static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
{
@@ -441,6 +444,12 @@ static inline struct block_device *bdget_disk(struct gendisk *disk, int index)

static inline void printk_all_partitions(void) { }

+static inline dev_t blk_lookup_devt(const char *name)
+{
+ dev_t devt = MKDEV(0, 0);
+ return devt;
+}
+
#endif /* CONFIG_BLOCK */

#endif
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 4efa1e5..2ae5b84 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -55,69 +55,6 @@ static int __init readwrite(char *str)
__setup("ro", readonly);
__setup("rw", readwrite);

-static dev_t try_name(char *name, int part)
-{
- char path[64];
- char buf[32];
- int range;
- dev_t res;
- char *s;
- int len;
- int fd;
- unsigned int maj, min;
-
- /* read device number from .../dev */
-
- sprintf(path, "/sys/block/%s/dev", name);
- fd = sys_open(path, 0, 0);
- if (fd < 0)
- goto fail;
- len = sys_read(fd, buf, 32);
- sys_close(fd);
- if (len <= 0 || len == 32 || buf[len - 1] != '\n')
- goto fail;
- buf[len - 1] = '\0';
- if (sscanf(buf, "%u:%u", &maj, &min) == 2) {
- /*
- * Try the %u:%u format -- see print_dev_t()
- */
- res = MKDEV(maj, min);
- if (maj != MAJOR(res) || min != MINOR(res))
- goto fail;
- } else {
- /*
- * Nope. Try old-style "0321"
- */
- res = new_decode_dev(simple_strtoul(buf, &s, 16));
- if (*s)
- goto fail;
- }
-
- /* if it's there and we are not looking for a partition - that's it */
- if (!part)
- return res;
-
- /* otherwise read range from .../range */
- sprintf(path, "/sys/block/%s/range", name);
- fd = sys_open(path, 0, 0);
- if (fd < 0)
- goto fail;
- len = sys_read(fd, buf, 32);
- sys_close(fd);
- if (len <= 0 || len == 32 || buf[len - 1] != '\n')
- goto fail;
- buf[len - 1] = '\0';
- range = simple_strtoul(buf, &s, 10);
- if (*s)
- goto fail;
-
- /* if partition is within range - we got it */
- if (part < range)
- return res + part;
-fail:
- return 0;
-}
-
/*
* Convert a name into device number. We accept the following variants:
*
@@ -129,12 +66,10 @@ fail:
* 5) /dev/<disk_name>p<decimal> - same as the above, that form is
* used when disk name of partitioned disk ends on a digit.
*
- * If name doesn't have fall into the categories above, we return 0.
- * Sysfs is used to check if something is a disk name - it has
- * all known disks under bus/block/devices. If the disk name
- * contains slashes, name of sysfs node has them replaced with
- * bangs. try_name() does the actual checks, assuming that sysfs
- * is mounted on rootfs /sys.
+ * If name doesn't have fall into the categories above, we return (0,0).
+ * block_class is used to check if something is a disk name. If the disk
+ * name contains slashes, the device name has them replaced with
+ * bangs.
*/

dev_t name_to_dev_t(char *name)
@@ -142,13 +77,6 @@ dev_t name_to_dev_t(char *name)
char s[32];
char *p;
dev_t res = 0;
- int part;
-
-#ifdef CONFIG_SYSFS
- int mkdir_err = sys_mkdir("/sys", 0700);
- if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
- goto out;
-#endif

if (strncmp(name, "/dev/", 5) != 0) {
unsigned maj, min;
@@ -164,6 +92,7 @@ dev_t name_to_dev_t(char *name)
}
goto done;
}
+
name += 5;
res = Root_NFS;
if (strcmp(name, "nfs") == 0)
@@ -178,35 +107,14 @@ dev_t name_to_dev_t(char *name)
for (p = s; *p; p++)
if (*p == '/')
*p = '!';
- res = try_name(s, 0);
+ res = blk_lookup_devt(s);
if (res)
goto done;

- while (p > s && isdigit(p[-1]))
- p--;
- if (p == s || !*p || *p == '0')
- goto fail;
- part = simple_strtoul(p, NULL, 10);
- *p = '\0';
- res = try_name(s, part);
- if (res)
- goto done;
-
- if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
- goto fail;
- p[-1] = '\0';
- res = try_name(s, part);
+fail:
+ return 0;
done:
-#ifdef CONFIG_SYSFS
- sys_umount("/sys", 0);
-out:
- if (!mkdir_err)
- sys_rmdir("/sys");
-#endif
return res;
-fail:
- res = 0;
- goto done;
}

static int __init root_dev_setup(char *line)
--
1.5.3.8

2008-01-25 08:33:40

by Greg KH

[permalink] [raw]
Subject: [PATCH 178/196] kobject: update the kobject/kset documentation

This provides a much-needed kobject and kset documentation update.

Thanks to Kay Sievers, Alan Stern, Jonathan Corbet, Randy Dunlap, Jan
Engelhardt, and others for reviewing and providing help with this
document.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
Documentation/kobject.txt | 386 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 386 insertions(+), 0 deletions(-)
create mode 100644 Documentation/kobject.txt

diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
new file mode 100644
index 0000000..bf3256e
--- /dev/null
+++ b/Documentation/kobject.txt
@@ -0,0 +1,386 @@
+Everything you never wanted to know about kobjects, ksets, and ktypes
+
+Greg Kroah-Hartman <[email protected]>
+
+Based on an original article by Jon Corbet for lwn.net written October 1,
+2003 and located at http://lwn.net/Articles/51437/
+
+Last updated December 19, 2007
+
+
+Part of the difficulty in understanding the driver model - and the kobject
+abstraction upon which it is built - is that there is no obvious starting
+place. Dealing with kobjects requires understanding a few different types,
+all of which make reference to each other. In an attempt to make things
+easier, we'll take a multi-pass approach, starting with vague terms and
+adding detail as we go. To that end, here are some quick definitions of
+some terms we will be working with.
+
+ - A kobject is an object of type struct kobject. Kobjects have a name
+ and a reference count. A kobject also has a parent pointer (allowing
+ objects to be arranged into hierarchies), a specific type, and,
+ usually, a representation in the sysfs virtual filesystem.
+
+ Kobjects are generally not interesting on their own; instead, they are
+ usually embedded within some other structure which contains the stuff
+ the code is really interested in.
+
+ No structure should EVER have more than one kobject embedded within it.
+ If it does, the reference counting for the object is sure to be messed
+ up and incorrect, and your code will be buggy. So do not do this.
+
+ - A ktype is the type of object that embeds a kobject. Every structure
+ that embeds a kobject needs a corresponding ktype. The ktype controls
+ what happens to the kobject when it is created and destroyed.
+
+ - A kset is a group of kobjects. These kobjects can be of the same ktype
+ or belong to different ktypes. The kset is the basic container type for
+ collections of kobjects. Ksets contain their own kobjects, but you can
+ safely ignore that implementation detail as the kset core code handles
+ this kobject automatically.
+
+ When you see a sysfs directory full of other directories, generally each
+ of those directories corresponds to a kobject in the same kset.
+
+We'll look at how to create and manipulate all of these types. A bottom-up
+approach will be taken, so we'll go back to kobjects.
+
+
+Embedding kobjects
+
+It is rare for kernel code to create a standalone kobject, with one major
+exception explained below. Instead, kobjects are used to control access to
+a larger, domain-specific object. To this end, kobjects will be found
+embedded in other structures. If you are used to thinking of things in
+object-oriented terms, kobjects can be seen as a top-level, abstract class
+from which other classes are derived. A kobject implements a set of
+capabilities which are not particularly useful by themselves, but which are
+nice to have in other objects. The C language does not allow for the
+direct expression of inheritance, so other techniques - such as structure
+embedding - must be used.
+
+So, for example, the UIO code has a structure that defines the memory
+region associated with a uio device:
+
+struct uio_mem {
+ struct kobject kobj;
+ unsigned long addr;
+ unsigned long size;
+ int memtype;
+ void __iomem *internal_addr;
+};
+
+If you have a struct uio_mem structure, finding its embedded kobject is
+just a matter of using the kobj member. Code that works with kobjects will
+often have the opposite problem, however: given a struct kobject pointer,
+what is the pointer to the containing structure? You must avoid tricks
+(such as assuming that the kobject is at the beginning of the structure)
+and, instead, use the container_of() macro, found in <linux/kernel.h>:
+
+ container_of(pointer, type, member)
+
+where pointer is the pointer to the embedded kobject, type is the type of
+the containing structure, and member is the name of the structure field to
+which pointer points. The return value from container_of() is a pointer to
+the given type. So, for example, a pointer "kp" to a struct kobject
+embedded within a struct uio_mem could be converted to a pointer to the
+containing uio_mem structure with:
+
+ struct uio_mem *u_mem = container_of(kp, struct uio_mem, kobj);
+
+Programmers often define a simple macro for "back-casting" kobject pointers
+to the containing type.
+
+
+Initialization of kobjects
+
+Code which creates a kobject must, of course, initialize that object. Some
+of the internal fields are setup with a (mandatory) call to kobject_init():
+
+ void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
+
+The ktype is required for a kobject to be created properly, as every kobject
+must have an associated kobj_type. After calling kobject_init(), to
+register the kobject with sysfs, the function kobject_add() must be called:
+
+ int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...);
+
+This sets up the parent of the kobject and the name for the kobject
+properly. If the kobject is to be associated with a specific kset,
+kobj->kset must be assigned before calling kobject_add(). If a kset is
+associated with a kobject, then the parent for the kobject can be set to
+NULL in the call to kobject_add() and then the kobject's parent will be the
+kset itself.
+
+As the name of the kobject is set when it is added to the kernel, the name
+of the kobject should never be manipulated directly. If you must change
+the name of the kobject, call kobject_rename():
+
+ int kobject_rename(struct kobject *kobj, const char *new_name);
+
+There is a function called kobject_set_name() but that is legacy cruft and
+is being removed. If your code needs to call this function, it is
+incorrect and needs to be fixed.
+
+To properly access the name of the kobject, use the function
+kobject_name():
+
+ const char *kobject_name(const struct kobject * kobj);
+
+There is a helper function to both initialize and add the kobject to the
+kernel at the same time, called supprisingly enough kobject_init_and_add():
+
+ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
+ struct kobject *parent, const char *fmt, ...);
+
+The arguments are the same as the individual kobject_init() and
+kobject_add() functions described above.
+
+
+Uevents
+
+After a kobject has been registered with the kobject core, you need to
+announce to the world that it has been created. This can be done with a
+call to kobject_uevent():
+
+ int kobject_uevent(struct kobject *kobj, enum kobject_action action);
+
+Use the KOBJ_ADD action for when the kobject is first added to the kernel.
+This should be done only after any attributes or children of the kobject
+have been initialized properly, as userspace will instantly start to look
+for them when this call happens.
+
+When the kobject is removed from the kernel (details on how to do that is
+below), the uevent for KOBJ_REMOVE will be automatically created by the
+kobject core, so the caller does not have to worry about doing that by
+hand.
+
+
+Reference counts
+
+One of the key functions of a kobject is to serve as a reference counter
+for the object in which it is embedded. As long as references to the object
+exist, the object (and the code which supports it) must continue to exist.
+The low-level functions for manipulating a kobject's reference counts are:
+
+ struct kobject *kobject_get(struct kobject *kobj);
+ void kobject_put(struct kobject *kobj);
+
+A successful call to kobject_get() will increment the kobject's reference
+counter and return the pointer to the kobject.
+
+When a reference is released, the call to kobject_put() will decrement the
+reference count and, possibly, free the object. Note that kobject_init()
+sets the reference count to one, so the code which sets up the kobject will
+need to do a kobject_put() eventually to release that reference.
+
+Because kobjects are dynamic, they must not be declared statically or on
+the stack, but instead, always allocated dynamically. Future versions of
+the kernel will contain a run-time check for kobjects that are created
+statically and will warn the developer of this improper usage.
+
+If all that you want to use a kobject for is to provide a reference counter
+for your structure, please use the struct kref instead; a kobject would be
+overkill. For more information on how to use struct kref, please see the
+file Documentation/kref.txt in the Linux kernel source tree.
+
+
+Creating "simple" kobjects
+
+Sometimes all that a developer wants is a way to create a simple directory
+in the sysfs hierarchy, and not have to mess with the whole complication of
+ksets, show and store functions, and other details. This is the one
+exception where a single kobject should be created. To create such an
+entry, use the function:
+
+ struct kobject *kobject_create_and_add(char *name, struct kobject *parent);
+
+This function will create a kobject and place it in sysfs in the location
+underneath the specified parent kobject. To create simple attributes
+associated with this kobject, use:
+
+ int sysfs_create_file(struct kobject *kobj, struct attribute *attr);
+or
+ int sysfs_create_group(struct kobject *kobj, struct attribute_group *grp);
+
+Both types of attributes used here, with a kobject that has been created
+with the kobject_create_and_add(), can be of type kobj_attribute, so no
+special custom attribute is needed to be created.
+
+See the example module, samples/kobject/kobject-example.c for an
+implementation of a simple kobject and attributes.
+
+
+
+ktypes and release methods
+
+One important thing still missing from the discussion is what happens to a
+kobject when its reference count reaches zero. The code which created the
+kobject generally does not know when that will happen; if it did, there
+would be little point in using a kobject in the first place. Even
+predictable object lifecycles become more complicated when sysfs is brought
+in as other portions of the kernel can get a reference on any kobject that
+is registered in the system.
+
+The end result is that a structure protected by a kobject cannot be freed
+before its reference count goes to zero. The reference count is not under
+the direct control of the code which created the kobject. So that code must
+be notified asynchronously whenever the last reference to one of its
+kobjects goes away.
+
+Once you registered your kobject via kobject_add(), you must never use
+kfree() to free it directly. The only safe way is to use kobject_put(). It
+is good practice to always use kobject_put() after kobject_init() to avoid
+errors creeping in.
+
+This notification is done through a kobject's release() method. Usually
+such a method has a form like:
+
+ void my_object_release(struct kobject *kobj)
+ {
+ struct my_object *mine = container_of(kobj, struct my_object, kobj);
+
+ /* Perform any additional cleanup on this object, then... */
+ kfree(mine);
+ }
+
+One important point cannot be overstated: every kobject must have a
+release() method, and the kobject must persist (in a consistent state)
+until that method is called. If these constraints are not met, the code is
+flawed. Note that the kernel will warn you if you forget to provide a
+release() method. Do not try to get rid of this warning by providing an
+"empty" release function; you will be mocked mercilessly by the kobject
+maintainer if you attempt this.
+
+Note, the name of the kobject is available in the release function, but it
+must NOT be changed within this callback. Otherwise there will be a memory
+leak in the kobject core, which makes people unhappy.
+
+Interestingly, the release() method is not stored in the kobject itself;
+instead, it is associated with the ktype. So let us introduce struct
+kobj_type:
+
+ struct kobj_type {
+ void (*release)(struct kobject *);
+ struct sysfs_ops *sysfs_ops;
+ struct attribute **default_attrs;
+ };
+
+This structure is used to describe a particular type of kobject (or, more
+correctly, of containing object). Every kobject needs to have an associated
+kobj_type structure; a pointer to that structure must be specified when you
+call kobject_init() or kobject_init_and_add().
+
+The release field in struct kobj_type is, of course, a pointer to the
+release() method for this type of kobject. The other two fields (sysfs_ops
+and default_attrs) control how objects of this type are represented in
+sysfs; they are beyond the scope of this document.
+
+The default_attrs pointer is a list of default attributes that will be
+automatically created for any kobject that is registered with this ktype.
+
+
+ksets
+
+A kset is merely a collection of kobjects that want to be associated with
+each other. There is no restriction that they be of the same ktype, but be
+very careful if they are not.
+
+A kset serves these functions:
+
+ - It serves as a bag containing a group of objects. A kset can be used by
+ the kernel to track "all block devices" or "all PCI device drivers."
+
+ - A kset is also a subdirectory in sysfs, where the associated kobjects
+ with the kset can show up. Every kset contains a kobject which can be
+ set up to be the parent of other kobjects; the top-level directories of
+ the sysfs hierarchy are constructed in this way.
+
+ - Ksets can support the "hotplugging" of kobjects and influence how
+ uevent events are reported to user space.
+
+In object-oriented terms, "kset" is the top-level container class; ksets
+contain their own kobject, but that kobject is managed by the kset code and
+should not be manipulated by any other user.
+
+A kset keeps its children in a standard kernel linked list. Kobjects point
+back to their containing kset via their kset field. In almost all cases,
+the kobjects belonging to a ket have that kset (or, strictly, its embedded
+kobject) in their parent.
+
+As a kset contains a kobject within it, it should always be dynamically
+created and never declared statically or on the stack. To create a new
+kset use:
+ struct kset *kset_create_and_add(const char *name,
+ struct kset_uevent_ops *u,
+ struct kobject *parent);
+
+When you are finished with the kset, call:
+ void kset_unregister(struct kset *kset);
+to destroy it.
+
+An example of using a kset can be seen in the
+samples/kobject/kset-example.c file in the kernel tree.
+
+If a kset wishes to control the uevent operations of the kobjects
+associated with it, it can use the struct kset_uevent_ops to handle it:
+
+struct kset_uevent_ops {
+ int (*filter)(struct kset *kset, struct kobject *kobj);
+ const char *(*name)(struct kset *kset, struct kobject *kobj);
+ int (*uevent)(struct kset *kset, struct kobject *kobj,
+ struct kobj_uevent_env *env);
+};
+
+
+The filter function allows a kset to prevent a uevent from being emitted to
+userspace for a specific kobject. If the function returns 0, the uevent
+will not be emitted.
+
+The name function will be called to override the default name of the kset
+that the uevent sends to userspace. By default, the name will be the same
+as the kset itself, but this function, if present, can override that name.
+
+The uevent function will be called when the uevent is about to be sent to
+userspace to allow more environment variables to be added to the uevent.
+
+One might ask how, exactly, a kobject is added to a kset, given that no
+functions which perform that function have been presented. The answer is
+that this task is handled by kobject_add(). When a kobject is passed to
+kobject_add(), its kset member should point to the kset to which the
+kobject will belong. kobject_add() will handle the rest.
+
+If the kobject belonging to a kset has no parent kobject set, it will be
+added to the kset's directory. Not all members of a kset do necessarily
+live in the kset directory. If an explicit parent kobject is assigned
+before the kobject is added, the kobject is registered with the kset, but
+added below the parent kobject.
+
+
+Kobject removal
+
+After a kobject has been registered with the kobject core successfully, it
+must be cleaned up when the code is finished with it. To do that, call
+kobject_put(). By doing this, the kobject core will automatically clean up
+all of the memory allocated by this kobject. If a KOBJ_ADD uevent has been
+sent for the object, a corresponding KOBJ_REMOVE uevent will be sent, and
+any other sysfs housekeeping will be handled for the caller properly.
+
+If you need to do a two-stage delete of the kobject (say you are not
+allowed to sleep when you need to destroy the object), then call
+kobject_del() which will unregister the kobject from sysfs. This makes the
+kobject "invisible", but it is not cleaned up, and the reference count of
+the object is still the same. At a later time call kobject_put() to finish
+the cleanup of the memory associated with the kobject.
+
+kobject_del() can be used to drop the reference to the parent object, if
+circular references are constructed. It is valid in some cases, that a
+parent objects references a child. Circular references _must_ be broken
+with an explicit call to kobject_del(), so that a release functions will be
+called, and the objects in the former circle release each other.
+
+
+Example code to copy from
+
+For a more complete example of using ksets and kobjects properly, see the
+sample/kobject/kset-example.c code.
--
1.5.3.8

2008-01-25 08:34:11

by Greg KH

[permalink] [raw]
Subject: [PATCH 151/196] Driver core: move the static kobject out of struct driver

This patch removes the kobject, and a few other driver-core-only fields
out of struct driver and into the driver core only. Now drivers can be
safely create on the stack or statically (like they currently are.)

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/base.h | 8 +++++
drivers/base/bus.c | 71 +++++++++++++++++++++++++---------------------
drivers/base/dd.c | 24 ++++++++--------
drivers/base/driver.c | 40 +++++++++++++++++---------
drivers/base/module.c | 12 ++++----
drivers/base/platform.c | 2 +-
include/linux/device.h | 16 ++++------
7 files changed, 99 insertions(+), 74 deletions(-)

diff --git a/drivers/base/base.h b/drivers/base/base.h
index 0547236..3b0f395 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -27,6 +27,14 @@ struct bus_type_private {
struct bus_type *bus;
};

+struct driver_private {
+ struct kobject kobj;
+ struct klist klist_devices;
+ struct klist_node knode_bus;
+ struct module_kobject *mkobj;
+ struct device_driver *driver;
+};
+#define to_driver(obj) container_of(obj, struct driver_private, kobj)

/* initialisation functions */
extern int devices_init(void);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 04d3850..aa0c986 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -3,6 +3,8 @@
*
* Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
+ * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2007 Novell Inc.
*
* This file is released under the GPLv2
*
@@ -24,7 +26,6 @@
*/

#define to_drv_attr(_attr) container_of(_attr, struct driver_attribute, attr)
-#define to_driver(obj) container_of(obj, struct device_driver, kobj)


static int __must_check bus_rescan_devices_helper(struct device *dev,
@@ -49,11 +50,11 @@ static ssize_t
drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
{
struct driver_attribute * drv_attr = to_drv_attr(attr);
- struct device_driver * drv = to_driver(kobj);
+ struct driver_private *drv_priv = to_driver(kobj);
ssize_t ret = -EIO;

if (drv_attr->show)
- ret = drv_attr->show(drv, buf);
+ ret = drv_attr->show(drv_priv->driver, buf);
return ret;
}

@@ -62,11 +63,11 @@ drv_attr_store(struct kobject * kobj, struct attribute * attr,
const char * buf, size_t count)
{
struct driver_attribute * drv_attr = to_drv_attr(attr);
- struct device_driver * drv = to_driver(kobj);
+ struct driver_private *drv_priv = to_driver(kobj);
ssize_t ret = -EIO;

if (drv_attr->store)
- ret = drv_attr->store(drv, buf, count);
+ ret = drv_attr->store(drv_priv->driver, buf, count);
return ret;
}

@@ -75,22 +76,12 @@ static struct sysfs_ops driver_sysfs_ops = {
.store = drv_attr_store,
};

-
-static void driver_release(struct kobject * kobj)
+static void driver_release(struct kobject *kobj)
{
- /*
- * Yes this is an empty release function, it is this way because struct
- * device is always a static object, not a dynamic one. Yes, this is
- * not nice and bad, but remember, drivers are code, reference counted
- * by the module count, not a device, which is really data. And yes,
- * in the future I do want to have all drivers be created dynamically,
- * and am working toward that goal, but it will take a bit longer...
- *
- * But do not let this example give _anyone_ the idea that they can
- * create a release function without any code in it at all, to do that
- * is almost always wrong. If you have any questions about this,
- * please send an email to <[email protected]>
- */
+ struct driver_private *drv_priv = to_driver(kobj);
+
+ pr_debug("%s: freeing %s\n", __FUNCTION__, kobject_name(kobj));
+ kfree(drv_priv);
}

static struct kobj_type driver_ktype = {
@@ -350,7 +341,13 @@ struct device * bus_find_device(struct bus_type *bus,
static struct device_driver * next_driver(struct klist_iter * i)
{
struct klist_node * n = klist_next(i);
- return n ? container_of(n, struct device_driver, knode_bus) : NULL;
+ struct driver_private *drv_priv;
+
+ if (n) {
+ drv_priv = container_of(n, struct driver_private, knode_bus);
+ return drv_priv->driver;
+ }
+ return NULL;
}

/**
@@ -384,7 +381,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
return -EINVAL;

klist_iter_init_node(&bus->p->klist_drivers, &i,
- start ? &start->knode_bus : NULL);
+ start ? &start->p->knode_bus : NULL);
while ((drv = next_driver(&i)) && !error)
error = fn(drv, data);
klist_iter_exit(&i);
@@ -620,7 +617,7 @@ static ssize_t driver_uevent_store(struct device_driver *drv,
enum kobject_action action;

if (kobject_action_type(buf, count, &action) == 0)
- kobject_uevent(&drv->kobj, action);
+ kobject_uevent(&drv->p->kobj, action);
return count;
}
static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store);
@@ -632,19 +629,29 @@ static DRIVER_ATTR(uevent, S_IWUSR, NULL, driver_uevent_store);
*/
int bus_add_driver(struct device_driver *drv)
{
- struct bus_type * bus = bus_get(drv->bus);
+ struct bus_type *bus;
+ struct driver_private *priv;
int error = 0;

+ bus = bus_get(drv->bus);
if (!bus)
return -EINVAL;

pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
- error = kobject_set_name(&drv->kobj, "%s", drv->name);
+
+ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ error = kobject_set_name(&priv->kobj, "%s", drv->name);
if (error)
goto out_put_bus;
- drv->kobj.kset = bus->p->drivers_kset;
- drv->kobj.ktype = &driver_ktype;
- error = kobject_register(&drv->kobj);
+ priv->kobj.kset = bus->p->drivers_kset;
+ priv->kobj.ktype = &driver_ktype;
+ klist_init(&priv->klist_devices, NULL, NULL);
+ priv->driver = drv;
+ drv->p = priv;
+ error = kobject_register(&priv->kobj);
if (error)
goto out_put_bus;

@@ -653,7 +660,7 @@ int bus_add_driver(struct device_driver *drv)
if (error)
goto out_unregister;
}
- klist_add_tail(&drv->knode_bus, &bus->p->klist_drivers);
+ klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers);
module_add_driver(drv->owner, drv);

error = driver_create_file(drv, &driver_attr_uevent);
@@ -676,7 +683,7 @@ int bus_add_driver(struct device_driver *drv)

return error;
out_unregister:
- kobject_unregister(&drv->kobj);
+ kobject_unregister(&priv->kobj);
out_put_bus:
bus_put(bus);
return error;
@@ -699,11 +706,11 @@ void bus_remove_driver(struct device_driver * drv)
remove_bind_files(drv);
driver_remove_attrs(drv->bus, drv);
driver_remove_file(drv, &driver_attr_uevent);
- klist_remove(&drv->knode_bus);
+ klist_remove(&drv->p->knode_bus);
pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name);
driver_detach(drv);
module_remove_driver(drv);
- kobject_unregister(&drv->kobj);
+ kobject_unregister(&drv->p->kobj);
bus_put(drv->bus);
}

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 7bf0e67..87a348c 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -11,6 +11,8 @@
*
* Copyright (c) 2002-5 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
+ * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2007 Novell Inc.
*
* This file is released under the GPLv2
*/
@@ -23,8 +25,6 @@
#include "base.h"
#include "power/power.h"

-#define to_drv(node) container_of(node, struct device_driver, kobj.entry)
-

static void driver_bound(struct device *dev)
{
@@ -41,20 +41,20 @@ static void driver_bound(struct device *dev)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_BOUND_DRIVER, dev);

- klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices);
+ klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices);
}

static int driver_sysfs_add(struct device *dev)
{
int ret;

- ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj,
+ ret = sysfs_create_link(&dev->driver->p->kobj, &dev->kobj,
kobject_name(&dev->kobj));
if (ret == 0) {
- ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj,
+ ret = sysfs_create_link(&dev->kobj, &dev->driver->p->kobj,
"driver");
if (ret)
- sysfs_remove_link(&dev->driver->kobj,
+ sysfs_remove_link(&dev->driver->p->kobj,
kobject_name(&dev->kobj));
}
return ret;
@@ -65,7 +65,7 @@ static void driver_sysfs_remove(struct device *dev)
struct device_driver *drv = dev->driver;

if (drv) {
- sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
+ sysfs_remove_link(&drv->p->kobj, kobject_name(&dev->kobj));
sysfs_remove_link(&dev->kobj, "driver");
}
}
@@ -339,15 +339,15 @@ void driver_detach(struct device_driver * drv)
struct device * dev;

for (;;) {
- spin_lock(&drv->klist_devices.k_lock);
- if (list_empty(&drv->klist_devices.k_list)) {
- spin_unlock(&drv->klist_devices.k_lock);
+ spin_lock(&drv->p->klist_devices.k_lock);
+ if (list_empty(&drv->p->klist_devices.k_list)) {
+ spin_unlock(&drv->p->klist_devices.k_lock);
break;
}
- dev = list_entry(drv->klist_devices.k_list.prev,
+ dev = list_entry(drv->p->klist_devices.k_list.prev,
struct device, knode_driver.n_node);
get_device(dev);
- spin_unlock(&drv->klist_devices.k_lock);
+ spin_unlock(&drv->p->klist_devices.k_lock);

if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 633ae1d..5aacff2 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -3,6 +3,8 @@
*
* Copyright (c) 2002-3 Patrick Mochel
* Copyright (c) 2002-3 Open Source Development Labs
+ * Copyright (c) 2007 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2007 Novell Inc.
*
* This file is released under the GPLv2
*
@@ -15,7 +17,6 @@
#include "base.h"

#define to_dev(node) container_of(node, struct device, driver_list)
-#define to_drv(obj) container_of(obj, struct device_driver, kobj)


static struct device * next_device(struct klist_iter * i)
@@ -44,7 +45,7 @@ int driver_for_each_device(struct device_driver * drv, struct device * start,
if (!drv)
return -EINVAL;

- klist_iter_init_node(&drv->klist_devices, &i,
+ klist_iter_init_node(&drv->p->klist_devices, &i,
start ? &start->knode_driver : NULL);
while ((dev = next_device(&i)) && !error)
error = fn(dev, data);
@@ -80,7 +81,7 @@ struct device * driver_find_device(struct device_driver *drv,
if (!drv)
return NULL;

- klist_iter_init_node(&drv->klist_devices, &i,
+ klist_iter_init_node(&drv->p->klist_devices, &i,
(start ? &start->knode_driver : NULL));
while ((dev = next_device(&i)))
if (match(dev, data) && get_device(dev))
@@ -100,7 +101,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att
{
int error;
if (get_driver(drv)) {
- error = sysfs_create_file(&drv->kobj, &attr->attr);
+ error = sysfs_create_file(&drv->p->kobj, &attr->attr);
put_driver(drv);
} else
error = -EINVAL;
@@ -117,7 +118,7 @@ int driver_create_file(struct device_driver * drv, struct driver_attribute * att
void driver_remove_file(struct device_driver * drv, struct driver_attribute * attr)
{
if (get_driver(drv)) {
- sysfs_remove_file(&drv->kobj, &attr->attr);
+ sysfs_remove_file(&drv->p->kobj, &attr->attr);
put_driver(drv);
}
}
@@ -143,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
if (!name)
return -ENOMEM;

- return kobject_add_ng(kobj, &drv->kobj, "%s", name);
+ return kobject_add_ng(kobj, &drv->p->kobj, "%s", name);
}
EXPORT_SYMBOL_GPL(driver_add_kobj);

@@ -153,7 +154,15 @@ EXPORT_SYMBOL_GPL(driver_add_kobj);
*/
struct device_driver * get_driver(struct device_driver * drv)
{
- return drv ? to_drv(kobject_get(&drv->kobj)) : NULL;
+ if (drv) {
+ struct driver_private *priv;
+ struct kobject *kobj;
+
+ kobj = kobject_get(&drv->p->kobj);
+ priv = to_driver(kobj);
+ return priv->driver;
+ }
+ return NULL;
}


@@ -163,7 +172,7 @@ struct device_driver * get_driver(struct device_driver * drv)
*/
void put_driver(struct device_driver * drv)
{
- kobject_put(&drv->kobj);
+ kobject_put(&drv->p->kobj);
}

static int driver_add_groups(struct device_driver *drv,
@@ -174,10 +183,10 @@ static int driver_add_groups(struct device_driver *drv,

if (groups) {
for (i = 0; groups[i]; i++) {
- error = sysfs_create_group(&drv->kobj, groups[i]);
+ error = sysfs_create_group(&drv->p->kobj, groups[i]);
if (error) {
while (--i >= 0)
- sysfs_remove_group(&drv->kobj,
+ sysfs_remove_group(&drv->p->kobj,
groups[i]);
break;
}
@@ -193,7 +202,7 @@ static void driver_remove_groups(struct device_driver *drv,

if (groups)
for (i = 0; groups[i]; i++)
- sysfs_remove_group(&drv->kobj, groups[i]);
+ sysfs_remove_group(&drv->p->kobj, groups[i]);
}


@@ -214,7 +223,6 @@ int driver_register(struct device_driver * drv)
(drv->bus->shutdown && drv->shutdown)) {
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
}
- klist_init(&drv->klist_devices, NULL, NULL);
ret = bus_add_driver(drv);
if (ret)
return ret;
@@ -250,8 +258,12 @@ void driver_unregister(struct device_driver * drv)
struct device_driver *driver_find(const char *name, struct bus_type *bus)
{
struct kobject *k = kset_find_obj(bus->p->drivers_kset, name);
- if (k)
- return to_drv(k);
+ struct driver_private *priv;
+
+ if (k) {
+ priv = to_driver(k);
+ return priv->driver;
+ }
return NULL;
}

diff --git a/drivers/base/module.c b/drivers/base/module.c
index cad07be..103be9c 100644
--- a/drivers/base/module.c
+++ b/drivers/base/module.c
@@ -50,7 +50,7 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
if (mkobj) {
mk = container_of(mkobj, struct module_kobject, kobj);
/* remember our module structure */
- drv->mkobj = mk;
+ drv->p->mkobj = mk;
/* kset_find_obj took a reference */
kobject_put(mkobj);
}
@@ -60,11 +60,11 @@ void module_add_driver(struct module *mod, struct device_driver *drv)
return;

/* Don't check return codes; these calls are idempotent */
- no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module");
+ no_warn = sysfs_create_link(&drv->p->kobj, &mk->kobj, "module");
driver_name = make_driver_name(drv);
if (driver_name) {
module_create_drivers_dir(mk);
- no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj,
+ no_warn = sysfs_create_link(mk->drivers_dir, &drv->p->kobj,
driver_name);
kfree(driver_name);
}
@@ -78,12 +78,12 @@ void module_remove_driver(struct device_driver *drv)
if (!drv)
return;

- sysfs_remove_link(&drv->kobj, "module");
+ sysfs_remove_link(&drv->p->kobj, "module");

if (drv->owner)
mk = &drv->owner->mkobj;
- else if (drv->mkobj)
- mk = drv->mkobj;
+ else if (drv->p->mkobj)
+ mk = drv->p->mkobj;
if (mk && mk->drivers_dir) {
driver_name = make_driver_name(drv);
if (driver_name) {
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index d56a05f..bdd59e8 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -499,7 +499,7 @@ int __init_or_module platform_driver_probe(struct platform_driver *drv,
*/
spin_lock(&platform_bus_type.p->klist_drivers.k_lock);
drv->probe = NULL;
- if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))
+ if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
retval = -ENODEV;
drv->driver.probe = platform_drv_probe_fail;
spin_unlock(&platform_bus_type.p->klist_drivers.k_lock);
diff --git a/include/linux/device.h b/include/linux/device.h
index 721ee31..92ba3a8 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -32,6 +32,7 @@

struct device;
struct device_driver;
+struct driver_private;
struct class;
struct class_device;
struct bus_type;
@@ -113,16 +114,11 @@ extern struct kset *bus_get_kset(struct bus_type *bus);
extern struct klist *bus_get_device_klist(struct bus_type *bus);

struct device_driver {
- const char * name;
- struct bus_type * bus;
-
- struct kobject kobj;
- struct klist klist_devices;
- struct klist_node knode_bus;
+ const char *name;
+ struct bus_type *bus;

- struct module * owner;
- const char * mod_name; /* used for built-in modules */
- struct module_kobject * mkobj;
+ struct module *owner;
+ const char *mod_name; /* used for built-in modules */

int (*probe) (struct device * dev);
int (*remove) (struct device * dev);
@@ -130,6 +126,8 @@ struct device_driver {
int (*suspend) (struct device * dev, pm_message_t state);
int (*resume) (struct device * dev);
struct attribute_group **groups;
+
+ struct driver_private *p;
};


--
1.5.3.8

2008-01-25 08:34:45

by Greg KH

[permalink] [raw]
Subject: [PATCH 155/196] Driver core: fix class glue dir cleanup logic

From: Kay Sievers <[email protected]>

We should remove the glue directory between the class and the bus
device _after_ we sent out the 'remove' event for the device, otherwise
the parent relationship is no longer valid, and composing the path
with deleted sysfs entries will not work.

Cc: Alan Stern <[email protected]>
Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/core.c | 206 +++++++++++++++++++++++----------------------------
1 files changed, 94 insertions(+), 112 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 22fdf32..13cae18 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -18,7 +18,7 @@
#include <linux/string.h>
#include <linux/kdev_t.h>
#include <linux/notifier.h>
-
+#include <linux/genhd.h>
#include <asm/semaphore.h>

#include "base.h"
@@ -538,22 +538,20 @@ void device_initialize(struct device *dev)
}

#ifdef CONFIG_SYSFS_DEPRECATED
-static struct kobject * get_device_parent(struct device *dev,
- struct device *parent)
+static struct kobject *get_device_parent(struct device *dev,
+ struct device *parent)
{
- /*
- * Set the parent to the class, not the parent device
- * for topmost devices in class hierarchy.
- * This keeps sysfs from having a symlink to make old
- * udevs happy
- */
+ /* class devices without a parent live in /sys/class/<classname>/ */
if (dev->class && (!parent || parent->class != dev->class))
return &dev->class->subsys.kobj;
+ /* all other devices keep their parent */
else if (parent)
return &parent->kobj;

return NULL;
}
+
+static inline void cleanup_device_parent(struct device *dev) {}
#else
static struct kobject *virtual_device_parent(struct device *dev)
{
@@ -566,8 +564,8 @@ static struct kobject *virtual_device_parent(struct device *dev)
return virtual_dir;
}

-static struct kobject * get_device_parent(struct device *dev,
- struct device *parent)
+static struct kobject *get_device_parent(struct device *dev,
+ struct device *parent)
{
int retval;

@@ -618,6 +616,34 @@ static struct kobject * get_device_parent(struct device *dev,
return &parent->kobj;
return NULL;
}
+
+static void cleanup_device_parent(struct device *dev)
+{
+ struct device *d;
+ int other = 0;
+
+ if (!dev->class)
+ return;
+
+ /* see if we live in a parent class directory */
+ if (dev->kobj.parent->kset != &dev->class->class_dirs)
+ return;
+
+ /* if we are the last child of our class, delete the directory */
+ down(&dev->class->sem);
+ list_for_each_entry(d, &dev->class->devices, node) {
+ if (d == dev)
+ continue;
+ if (d->kobj.parent == dev->kobj.parent) {
+ other = 1;
+ break;
+ }
+ }
+ if (!other)
+ kobject_del(dev->kobj.parent);
+ kobject_put(dev->kobj.parent);
+ up(&dev->class->sem);
+}
#endif

static int setup_parent(struct device *dev, struct device *parent)
@@ -637,65 +663,74 @@ static int device_add_class_symlinks(struct device *dev)

if (!dev->class)
return 0;
+
error = sysfs_create_link(&dev->kobj, &dev->class->subsys.kobj,
"subsystem");
if (error)
goto out;
- /*
- * If this is not a "fake" compatible device, then create the
- * symlink from the class to the device.
- */
+
+#ifdef CONFIG_SYSFS_DEPRECATED
+ /* stacked class devices need a symlink in the class directory */
if (dev->kobj.parent != &dev->class->subsys.kobj) {
error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
dev->bus_id);
if (error)
goto out_subsys;
}
+
if (dev->parent) {
-#ifdef CONFIG_SYSFS_DEPRECATED
- {
- struct device *parent = dev->parent;
- char *class_name;
-
- /*
- * In old sysfs stacked class devices had 'device'
- * link pointing to real device instead of parent
- */
- while (parent->class && !parent->bus && parent->parent)
- parent = parent->parent;
-
- error = sysfs_create_link(&dev->kobj,
- &parent->kobj,
- "device");
- if (error)
- goto out_busid;
+ struct device *parent = dev->parent;
+ char *class_name;

- class_name = make_class_name(dev->class->name,
- &dev->kobj);
- if (class_name)
- error = sysfs_create_link(&dev->parent->kobj,
- &dev->kobj, class_name);
- kfree(class_name);
- if (error)
- goto out_device;
- }
-#else
- error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
+ /*
+ * stacked class devices have the 'device' link
+ * pointing to the bus device instead of the parent
+ */
+ while (parent->class && !parent->bus && parent->parent)
+ parent = parent->parent;
+
+ error = sysfs_create_link(&dev->kobj,
+ &parent->kobj,
"device");
if (error)
goto out_busid;
-#endif
+
+ class_name = make_class_name(dev->class->name,
+ &dev->kobj);
+ if (class_name)
+ error = sysfs_create_link(&dev->parent->kobj,
+ &dev->kobj, class_name);
+ kfree(class_name);
+ if (error)
+ goto out_device;
}
return 0;

-#ifdef CONFIG_SYSFS_DEPRECATED
out_device:
if (dev->parent)
sysfs_remove_link(&dev->kobj, "device");
-#endif
out_busid:
if (dev->kobj.parent != &dev->class->subsys.kobj)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
+#else
+ /* link in the class directory pointing to the device */
+ error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
+ dev->bus_id);
+ if (error)
+ goto out_subsys;
+
+ if (dev->parent) {
+ error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
+ "device");
+ if (error)
+ goto out_busid;
+ }
+ return 0;
+
+out_busid:
+ sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
+#endif
+
out_subsys:
sysfs_remove_link(&dev->kobj, "subsystem");
out:
@@ -706,8 +741,9 @@ static void device_remove_class_symlinks(struct device *dev)
{
if (!dev->class)
return;
- if (dev->parent) {
+
#ifdef CONFIG_SYSFS_DEPRECATED
+ if (dev->parent) {
char *class_name;

class_name = make_class_name(dev->class->name, &dev->kobj);
@@ -715,11 +751,18 @@ static void device_remove_class_symlinks(struct device *dev)
sysfs_remove_link(&dev->parent->kobj, class_name);
kfree(class_name);
}
-#endif
sysfs_remove_link(&dev->kobj, "device");
}
+
if (dev->kobj.parent != &dev->class->subsys.kobj)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
+#else
+ if (dev->parent)
+ sysfs_remove_link(&dev->kobj, "device");
+
+ sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
+#endif
+
sysfs_remove_link(&dev->kobj, "subsystem");
}

@@ -830,26 +873,6 @@ int device_add(struct device *dev)
SymlinkError:
if (MAJOR(dev->devt))
device_remove_file(dev, &devt_attr);
-
- if (dev->class) {
- sysfs_remove_link(&dev->kobj, "subsystem");
- /* If this is not a "fake" compatible device, remove the
- * symlink from the class to the device. */
- if (dev->kobj.parent != &dev->class->subsys.kobj)
- sysfs_remove_link(&dev->class->subsys.kobj,
- dev->bus_id);
- if (parent) {
-#ifdef CONFIG_SYSFS_DEPRECATED
- char *class_name = make_class_name(dev->class->name,
- &dev->kobj);
- if (class_name)
- sysfs_remove_link(&dev->parent->kobj,
- class_name);
- kfree(class_name);
-#endif
- sysfs_remove_link(&dev->kobj, "device");
- }
- }
ueventattrError:
device_remove_file(dev, &uevent_attr);
attrError:
@@ -932,23 +955,7 @@ void device_del(struct device * dev)
if (MAJOR(dev->devt))
device_remove_file(dev, &devt_attr);
if (dev->class) {
- sysfs_remove_link(&dev->kobj, "subsystem");
- /* If this is not a "fake" compatible device, remove the
- * symlink from the class to the device. */
- if (dev->kobj.parent != &dev->class->subsys.kobj)
- sysfs_remove_link(&dev->class->subsys.kobj,
- dev->bus_id);
- if (parent) {
-#ifdef CONFIG_SYSFS_DEPRECATED
- char *class_name = make_class_name(dev->class->name,
- &dev->kobj);
- if (class_name)
- sysfs_remove_link(&dev->parent->kobj,
- class_name);
- kfree(class_name);
-#endif
- sysfs_remove_link(&dev->kobj, "device");
- }
+ device_remove_class_symlinks(dev);

down(&dev->class->sem);
/* notify any interfaces that the device is now gone */
@@ -958,31 +965,6 @@ void device_del(struct device * dev)
/* remove the device from the class list */
list_del_init(&dev->node);
up(&dev->class->sem);
-
- /* If we live in a parent class-directory, unreference it */
- if (dev->kobj.parent->kset == &dev->class->class_dirs) {
- struct device *d;
- int other = 0;
-
- /*
- * if we are the last child of our class, delete
- * our class-directory at this parent
- */
- down(&dev->class->sem);
- list_for_each_entry(d, &dev->class->devices, node) {
- if (d == dev)
- continue;
- if (d->kobj.parent == dev->kobj.parent) {
- other = 1;
- break;
- }
- }
- if (!other)
- kobject_del(dev->kobj.parent);
-
- kobject_put(dev->kobj.parent);
- up(&dev->class->sem);
- }
}
device_remove_file(dev, &uevent_attr);
device_remove_attrs(dev);
@@ -1004,9 +986,9 @@ void device_del(struct device * dev)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
BUS_NOTIFY_DEL_DEVICE, dev);
kobject_uevent(&dev->kobj, KOBJ_REMOVE);
+ cleanup_device_parent(dev);
kobject_del(&dev->kobj);
- if (parent)
- put_device(parent);
+ put_device(parent);
}

/**
--
1.5.3.8

2008-01-25 08:35:09

by Greg KH

[permalink] [raw]
Subject: [PATCH 166/196] Kobject: rename kobject_init_ng() to kobject_init()

Now that the old kobject_init() function is gone, rename
kobject_init_ng() to kobject_init() to clean up the namespace.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/elevator.c | 2 +-
block/ll_rw_blk.c | 2 +-
drivers/base/class.c | 2 +-
drivers/base/core.c | 2 +-
drivers/md/md.c | 2 +-
drivers/net/iseries_veth.c | 4 ++--
drivers/uio/uio.c | 2 +-
fs/char_dev.c | 4 ++--
include/linux/kobject.h | 2 +-
lib/kobject.c | 14 +++++++-------
10 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index 645469a..f9736fb 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -185,7 +185,7 @@ static elevator_t *elevator_alloc(struct request_queue *q,

eq->ops = &e->ops;
eq->elevator_type = e;
- kobject_init_ng(&eq->kobj, &elv_ktype);
+ kobject_init(&eq->kobj, &elv_ktype);
mutex_init(&eq->sysfs_lock);

eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES,
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 234dd3d..5ccec8a 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1862,7 +1862,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)

init_timer(&q->unplug_timer);

- kobject_init_ng(&q->kobj, &queue_ktype);
+ kobject_init(&q->kobj, &queue_ktype);

mutex_init(&q->sysfs_lock);

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 8e3cba2..61fd26c 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -553,7 +553,7 @@ static struct class_device_attribute class_uevent_attr =
void class_device_initialize(struct class_device *class_dev)
{
class_dev->kobj.kset = &class_obj_subsys;
- kobject_init_ng(&class_dev->kobj, &class_device_ktype);
+ kobject_init(&class_dev->kobj, &class_device_ktype);
INIT_LIST_HEAD(&class_dev->node);
}

diff --git a/drivers/base/core.c b/drivers/base/core.c
index e881702..675a719 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -525,7 +525,7 @@ static void klist_children_put(struct klist_node *n)
void device_initialize(struct device *dev)
{
dev->kobj.kset = devices_kset;
- kobject_init_ng(&dev->kobj, &device_ktype);
+ kobject_init(&dev->kobj, &device_ktype);
klist_init(&dev->klist_children, klist_children_get,
klist_children_put);
INIT_LIST_HEAD(&dev->dma_pools);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 989d854..ae800ba 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -2033,7 +2033,7 @@ static mdk_rdev_t *md_import_device(dev_t newdev, int super_format, int super_mi
if (err)
goto abort_free;

- kobject_init_ng(&rdev->kobj, &rdev_ktype);
+ kobject_init(&rdev->kobj, &rdev_ktype);

rdev->desc_nr = -1;
rdev->saved_raid_disk = -1;
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index ee15667..419861c 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -844,7 +844,7 @@ static int veth_init_connection(u8 rlp)

/* This gets us 1 reference, which is held on behalf of the driver
* infrastructure. It's released at module unload. */
- kobject_init_ng(&cnx->kobject, &veth_lpar_connection_ktype);
+ kobject_init(&cnx->kobject, &veth_lpar_connection_ktype);

msgs = kcalloc(VETH_NUMBUFFERS, sizeof(struct veth_msg), GFP_KERNEL);
if (! msgs) {
@@ -1083,7 +1083,7 @@ static struct net_device * __init veth_probe_one(int vlan,
return NULL;
}

- kobject_init_ng(&port->kobject, &veth_port_ktype);
+ kobject_init(&port->kobject, &veth_port_ktype);
if (0 != kobject_add(&port->kobject, &dev->dev.kobj, "veth_port"))
veth_error("Failed adding port for %s to sysfs.\n", dev->name);

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 1ec2d31..f352731 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -169,7 +169,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
map = kzalloc(sizeof(*map), GFP_KERNEL);
if (!map)
goto err;
- kobject_init_ng(&map->kobj, &map_attr_type);
+ kobject_init(&map->kobj, &map_attr_type);
map->mem = mem;
mem->map = map;
ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
diff --git a/fs/char_dev.c b/fs/char_dev.c
index b2dd5a0..2c7a8b5 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -511,7 +511,7 @@ struct cdev *cdev_alloc(void)
struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
if (p) {
INIT_LIST_HEAD(&p->list);
- kobject_init_ng(&p->kobj, &ktype_cdev_dynamic);
+ kobject_init(&p->kobj, &ktype_cdev_dynamic);
}
return p;
}
@@ -528,7 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops)
{
memset(cdev, 0, sizeof *cdev);
INIT_LIST_HEAD(&cdev->list);
- kobject_init_ng(&cdev->kobj, &ktype_cdev_default);
+ kobject_init(&cdev->kobj, &ktype_cdev_default);
cdev->ops = fops;
}

diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 53458b6..d9d8c36 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -78,7 +78,7 @@ static inline const char * kobject_name(const struct kobject * kobj)
return kobj->k_name;
}

-extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
+extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
extern int __must_check kobject_add(struct kobject *kobj,
struct kobject *parent,
const char *fmt, ...);
diff --git a/lib/kobject.c b/lib/kobject.c
index 10d977b..4cc231c 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -287,7 +287,7 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...)
EXPORT_SYMBOL(kobject_set_name);

/**
- * kobject_init_ng - initialize a kobject structure
+ * kobject_init - initialize a kobject structure
* @kobj: pointer to the kobject to initialize
* @ktype: pointer to the ktype for this kobject.
*
@@ -298,7 +298,7 @@ EXPORT_SYMBOL(kobject_set_name);
* to kobject_put(), not by a call to kfree directly to ensure that all of
* the memory is cleaned up properly.
*/
-void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype)
+void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
{
char *err_str;

@@ -326,7 +326,7 @@ error:
printk(KERN_ERR "kobject: %s\n", err_str);
dump_stack();
}
-EXPORT_SYMBOL(kobject_init_ng);
+EXPORT_SYMBOL(kobject_init);

static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
const char *fmt, va_list vargs)
@@ -401,7 +401,7 @@ EXPORT_SYMBOL(kobject_add);
* @parent: pointer to the parent of this kobject.
* @fmt: the name of the kobject.
*
- * This function combines the call to kobject_init_ng() and
+ * This function combines the call to kobject_init() and
* kobject_add(). The same type of error handling after a call to
* kobject_add() and kobject lifetime rules are the same here.
*/
@@ -411,7 +411,7 @@ int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
va_list args;
int retval;

- kobject_init_ng(kobj, ktype);
+ kobject_init(kobj, ktype);

va_start(args, fmt);
retval = kobject_add_varg(kobj, parent, fmt, args);
@@ -636,7 +636,7 @@ static struct kobj_type dynamic_kobj_ktype = {
*
* If the kobject was not able to be created, NULL will be returned.
* The kobject structure returned from here must be cleaned up with a
- * call to kobject_put() and not kfree(), as kobject_init_ng() has
+ * call to kobject_put() and not kfree(), as kobject_init() has
* already been called on this structure.
*/
struct kobject *kobject_create(void)
@@ -647,7 +647,7 @@ struct kobject *kobject_create(void)
if (!kobj)
return NULL;

- kobject_init_ng(kobj, &dynamic_kobj_ktype);
+ kobject_init(kobj, &dynamic_kobj_ktype);
return kobj;
}

--
1.5.3.8

2008-01-25 08:35:46

by Greg KH

[permalink] [raw]
Subject: [PATCH 129/196] Kobject: convert drivers/base/class.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/class.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 3ffcda7..ba6745b 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -546,8 +546,7 @@ static struct class_device_attribute class_uevent_attr =
void class_device_initialize(struct class_device *class_dev)
{
class_dev->kobj.kset = &class_obj_subsys;
- class_dev->kobj.ktype = &class_device_ktype;
- kobject_init(&class_dev->kobj);
+ kobject_init_ng(&class_dev->kobj, &class_device_ktype);
INIT_LIST_HEAD(&class_dev->node);
}

@@ -575,16 +574,13 @@ int class_device_add(struct class_device *class_dev)
class_dev->class_id);

/* first, register with generic layer. */
- error = kobject_set_name(&class_dev->kobj, "%s", class_dev->class_id);
- if (error)
- goto out2;
-
if (parent_class_dev)
class_dev->kobj.parent = &parent_class_dev->kobj;
else
class_dev->kobj.parent = &parent_class->subsys.kobj;

- error = kobject_add(&class_dev->kobj);
+ error = kobject_add_ng(&class_dev->kobj, class_dev->kobj.parent,
+ "%s", class_dev->class_id);
if (error)
goto out2;

--
1.5.3.8

2008-01-25 08:36:15

by Greg KH

[permalink] [raw]
Subject: [PATCH 185/196] UIO: constify function pointer tables

From: Jan Engelhardt <[email protected]>

Signed-off-by: Jan Engelhardt <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/uio/uio.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 03b66fb..cc246fa 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -39,7 +39,7 @@ struct uio_device {

static int uio_major;
static DEFINE_IDR(uio_idr);
-static struct file_operations uio_fops;
+static const struct file_operations uio_fops;

/* UIO class infrastructure */
static struct uio_class {
@@ -508,7 +508,7 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
}
}

-static struct file_operations uio_fops = {
+static const struct file_operations uio_fops = {
.owner = THIS_MODULE,
.open = uio_open,
.release = uio_release,
--
1.5.3.8

2008-01-25 08:36:47

by Greg KH

[permalink] [raw]
Subject: [PATCH 174/196] Kobject: convert remaining kobject_unregister() to kobject_put()

There is no need for kobject_unregister() anymore, thanks to Kay's
kobject cleanup changes, so replace all instances of it with
kobject_put().


Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
kernel/ksysfs.c | 2 +-
kernel/module.c | 9 ++++-----
lib/kobject.c | 4 ++--
net/bridge/br_sysfs_br.c | 2 +-
security/inode.c | 2 +-
5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 1081aff..e53bc30 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -154,7 +154,7 @@ notes_exit:
group_exit:
sysfs_remove_group(kernel_kobj, &kernel_attr_group);
kset_exit:
- kobject_unregister(kernel_kobj);
+ kobject_put(kernel_kobj);
exit:
return error;
}
diff --git a/kernel/module.c b/kernel/module.c
index 89cd4c7..dcb8a2c 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1257,9 +1257,8 @@ int mod_sysfs_setup(struct module *mod,
out_unreg_param:
module_param_sysfs_remove(mod);
out_unreg_holders:
- kobject_unregister(mod->holders_dir);
+ kobject_put(mod->holders_dir);
out_unreg:
- kobject_del(&mod->mkobj.kobj);
kobject_put(&mod->mkobj.kobj);
return err;
}
@@ -1269,9 +1268,9 @@ static void mod_kobject_remove(struct module *mod)
{
module_remove_modinfo_attrs(mod);
module_param_sysfs_remove(mod);
- kobject_unregister(mod->mkobj.drivers_dir);
- kobject_unregister(mod->holders_dir);
- kobject_unregister(&mod->mkobj.kobj);
+ kobject_put(mod->mkobj.drivers_dir);
+ kobject_put(mod->holders_dir);
+ kobject_put(&mod->mkobj.kobj);
}

/*
diff --git a/lib/kobject.c b/lib/kobject.c
index 4fce5ca..462946e 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -664,7 +664,7 @@ struct kobject *kobject_create(void)
*
* This function creates a kset structure dynamically and registers it
* with sysfs. When you are finished with this structure, call
- * kobject_unregister() and the structure will be dynamically freed when
+ * kobject_put() and the structure will be dynamically freed when
* it is no longer being used.
*
* If the kobject was not able to be created, NULL will be returned.
@@ -761,7 +761,7 @@ void kset_unregister(struct kset * k)
{
if (!k)
return;
- kobject_unregister(&k->kobj);
+ kobject_put(&k->kobj);
}


diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
index 4e7f91f..9cf0538 100644
--- a/net/bridge/br_sysfs_br.c
+++ b/net/bridge/br_sysfs_br.c
@@ -447,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)
struct kobject *kobj = &dev->dev.kobj;
struct net_bridge *br = netdev_priv(dev);

- kobject_unregister(br->ifobj);
+ kobject_put(br->ifobj);
sysfs_remove_bin_file(kobj, &bridge_forward);
sysfs_remove_group(kobj, &bridge_group);
}
diff --git a/security/inode.c b/security/inode.c
index def0cc1..acc6cf0 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -327,7 +327,7 @@ static int __init securityfs_init(void)

retval = register_filesystem(&fs_type);
if (retval)
- kobject_unregister(security_kobj);
+ kobject_put(security_kobj);
return retval;
}

--
1.5.3.8

2008-01-25 08:37:15

by Greg KH

[permalink] [raw]
Subject: [PATCH 145/196] driver core: Introduce default attribute groups.

From: Cornelia Huck <[email protected]>

This is lot like default attributes for devices (and indeed,
a lot of the code is lifted from there).

Signed-off-by: Cornelia Huck <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/driver.c | 42 +++++++++++++++++++++++++++++++++++++++++-
include/linux/device.h | 1 +
2 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index f94be40..e3b5840 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -142,6 +142,37 @@ void put_driver(struct device_driver * drv)
kobject_put(&drv->kobj);
}

+static int driver_add_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int error = 0;
+ int i;
+
+ if (groups) {
+ for (i = 0; groups[i]; i++) {
+ error = sysfs_create_group(&drv->kobj, groups[i]);
+ if (error) {
+ while (--i >= 0)
+ sysfs_remove_group(&drv->kobj,
+ groups[i]);
+ break;
+ }
+ }
+ }
+ return error;
+}
+
+static void driver_remove_groups(struct device_driver *drv,
+ struct attribute_group **groups)
+{
+ int i;
+
+ if (groups)
+ for (i = 0; groups[i]; i++)
+ sysfs_remove_group(&drv->kobj, groups[i]);
+}
+
+
/**
* driver_register - register driver with bus
* @drv: driver to register
@@ -152,13 +183,21 @@ void put_driver(struct device_driver * drv)
*/
int driver_register(struct device_driver * drv)
{
+ int ret;
+
if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown)) {
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
}
klist_init(&drv->klist_devices, NULL, NULL);
- return bus_add_driver(drv);
+ ret = bus_add_driver(drv);
+ if (ret)
+ return ret;
+ ret = driver_add_groups(drv, drv->groups);
+ if (ret)
+ bus_remove_driver(drv);
+ return ret;
}

/**
@@ -170,6 +209,7 @@ int driver_register(struct device_driver * drv)

void driver_unregister(struct device_driver * drv)
{
+ driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}

diff --git a/include/linux/device.h b/include/linux/device.h
index 3f24bf4..d974dda 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -129,6 +129,7 @@ struct device_driver {
void (*shutdown) (struct device * dev);
int (*suspend) (struct device * dev, pm_message_t state);
int (*resume) (struct device * dev);
+ struct attribute_group **groups;
};


--
1.5.3.8

2008-01-25 08:37:48

by Greg KH

[permalink] [raw]
Subject: [PATCH 183/196] driver core: fix build with SYSFS=n

From: Randy Dunlap <[email protected]>

When SYSFS=n and MODULES=y, build ends with:

linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':
linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function)
make[3]: *** [drivers/base/module.o] Error 1

Below is one possible fix.
Build-tested with all 4 config combinations of SYSFS & MODULES.

Signed-off-by: Randy Dunlap <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/base/Makefile | 2 ++
drivers/base/base.h | 2 +-
2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index ff26968..63e09c0 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -11,7 +11,9 @@ obj-$(CONFIG_FW_LOADER) += firmware_class.o
obj-$(CONFIG_NUMA) += node.o
obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o
obj-$(CONFIG_SMP) += topology.o
+ifeq ($(CONFIG_SYSFS),y)
obj-$(CONFIG_MODULES) += module.o
+endif
obj-$(CONFIG_SYS_HYPERVISOR) += hypervisor.o

ifeq ($(CONFIG_DEBUG_DRIVER),y)
diff --git a/drivers/base/base.h b/drivers/base/base.h
index a74ceda..f7ad65a 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -81,7 +81,7 @@ extern int devres_release_all(struct device *dev);

extern struct kset *devices_kset;

-#ifdef CONFIG_MODULES
+#if defined(CONFIG_MODULES) && defined(CONFIG_SYSFS)
extern void module_add_driver(struct module *mod, struct device_driver *drv);
extern void module_remove_driver(struct device_driver *drv);
#else
--
1.5.3.8

2008-01-25 08:38:21

by Greg KH

[permalink] [raw]
Subject: [PATCH 160/196] Kobject: convert block/ll_rw_blk.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Jens Axboe <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/ll_rw_blk.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 3887b2a..8054b7d 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -1862,9 +1862,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)

init_timer(&q->unplug_timer);

- kobject_set_name(&q->kobj, "%s", "queue");
- q->kobj.ktype = &queue_ktype;
- kobject_init(&q->kobj);
+ kobject_init_ng(&q->kobj, &queue_ktype);

mutex_init(&q->sysfs_lock);

@@ -4182,9 +4180,8 @@ int blk_register_queue(struct gendisk *disk)
if (!q || !q->request_fn)
return -ENXIO;

- q->kobj.parent = kobject_get(&disk->dev.kobj);
-
- ret = kobject_add(&q->kobj);
+ ret = kobject_add_ng(&q->kobj, kobject_get(&disk->dev.kobj),
+ "%s", "queue");
if (ret < 0)
return ret;

--
1.5.3.8

2008-01-25 08:38:50

by Greg KH

[permalink] [raw]
Subject: [PATCH 159/196] Kobject: convert block/elevator.c to use kobject_init/add_ng()

This converts the code to use the new kobject functions, cleaning up the
logic in doing so.

Cc: Jens Axboe <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/elevator.c | 8 ++------
1 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index e452deb..5445c3c 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -185,9 +185,7 @@ static elevator_t *elevator_alloc(struct request_queue *q,

eq->ops = &e->ops;
eq->elevator_type = e;
- kobject_init(&eq->kobj);
- kobject_set_name(&eq->kobj, "%s", "iosched");
- eq->kobj.ktype = &elv_ktype;
+ kobject_init_ng(&eq->kobj, &elv_ktype);
mutex_init(&eq->sysfs_lock);

eq->hash = kmalloc_node(sizeof(struct hlist_head) * ELV_HASH_ENTRIES,
@@ -931,9 +929,7 @@ int elv_register_queue(struct request_queue *q)
elevator_t *e = q->elevator;
int error;

- e->kobj.parent = &q->kobj;
-
- error = kobject_add(&e->kobj);
+ error = kobject_add_ng(&e->kobj, &q->kobj, "%s", "iosched");
if (!error) {
struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
if (attr) {
--
1.5.3.8

2008-01-25 08:39:28

by Greg KH

[permalink] [raw]
Subject: [PATCH 121/196] Kobject: change arch/sh/kernel/cpu/sh4/sq.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/sh/kernel/cpu/sh4/sq.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index b22a78c..97fd9b9 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -341,17 +341,18 @@ static int __devinit sq_sysdev_add(struct sys_device *sysdev)
{
unsigned int cpu = sysdev->id;
struct kobject *kobj;
+ int error;

sq_kobject[cpu] = kzalloc(sizeof(struct kobject), GFP_KERNEL);
if (unlikely(!sq_kobject[cpu]))
return -ENOMEM;

kobj = sq_kobject[cpu];
- kobj->parent = &sysdev->kobj;
- kobject_set_name(kobj, "%s", "sq");
- kobj->ktype = &ktype_percpu_entry;
-
- return kobject_register(kobj);
+ error = kobject_init_and_add(kobj, &ktype_percpu_entry, &sysdev->kobj,
+ "%s", "sq");
+ if (!error)
+ kobject_uevent(kobj, KOBJ_ADD);
+ return error;
}

static int __devexit sq_sysdev_remove(struct sys_device *sysdev)
--
1.5.3.8

2008-01-25 08:39:57

by Greg KH

[permalink] [raw]
Subject: [PATCH 164/196] Kobject: rename kobject_add_ng() to kobject_add()

Now that the old kobject_add() function is gone, rename kobject_add_ng()
to kobject_add() to clean up the namespace.

Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
block/elevator.c | 2 +-
block/ll_rw_blk.c | 4 ++--
drivers/base/class.c | 4 ++--
drivers/base/core.c | 6 +++---
drivers/base/driver.c | 2 +-
drivers/md/md.c | 2 +-
drivers/net/iseries_veth.c | 2 +-
drivers/uio/uio.c | 2 +-
include/linux/kobject.h | 6 +++---
lib/kobject.c | 14 +++++++-------
10 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index 5445c3c..645469a 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -929,7 +929,7 @@ int elv_register_queue(struct request_queue *q)
elevator_t *e = q->elevator;
int error;

- error = kobject_add_ng(&e->kobj, &q->kobj, "%s", "iosched");
+ error = kobject_add(&e->kobj, &q->kobj, "%s", "iosched");
if (!error) {
struct elv_fs_entry *attr = e->elevator_type->elevator_attrs;
if (attr) {
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 8054b7d..234dd3d 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -4180,8 +4180,8 @@ int blk_register_queue(struct gendisk *disk)
if (!q || !q->request_fn)
return -ENXIO;

- ret = kobject_add_ng(&q->kobj, kobject_get(&disk->dev.kobj),
- "%s", "queue");
+ ret = kobject_add(&q->kobj, kobject_get(&disk->dev.kobj),
+ "%s", "queue");
if (ret < 0)
return ret;

diff --git a/drivers/base/class.c b/drivers/base/class.c
index 624b331..8e3cba2 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -586,8 +586,8 @@ int class_device_add(struct class_device *class_dev)
else
class_dev->kobj.parent = &parent_class->subsys.kobj;

- error = kobject_add_ng(&class_dev->kobj, class_dev->kobj.parent,
- "%s", class_dev->class_id);
+ error = kobject_add(&class_dev->kobj, class_dev->kobj.parent,
+ "%s", class_dev->class_id);
if (error)
goto out2;

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 06e8738..e881702 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -602,7 +602,7 @@ static struct kobject *get_device_parent(struct device *dev,
if (!k)
return NULL;
k->kset = &dev->class->class_dirs;
- retval = kobject_add_ng(k, parent_kobj, "%s", dev->class->name);
+ retval = kobject_add(k, parent_kobj, "%s", dev->class->name);
if (retval < 0) {
kobject_put(k);
return NULL;
@@ -776,7 +776,7 @@ static void device_remove_class_symlinks(struct device *dev)
* This is part 2 of device_register(), though may be called
* separately _iff_ device_initialize() has been called separately.
*
- * This adds it to the kobject hierarchy via kobject_add_ng(), adds it
+ * This adds it to the kobject hierarchy via kobject_add(), adds it
* to the global and sibling lists for the device, then
* adds it to the other relevant subsystems of the driver model.
*/
@@ -807,7 +807,7 @@ int device_add(struct device *dev)
goto Error;

/* first, register with generic layer. */
- error = kobject_add_ng(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
+ error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id);
if (error)
goto Error;

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 5aacff2..94b697a 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -144,7 +144,7 @@ int driver_add_kobj(struct device_driver *drv, struct kobject *kobj,
if (!name)
return -ENOMEM;

- return kobject_add_ng(kobj, &drv->p->kobj, "%s", name);
+ return kobject_add(kobj, &drv->p->kobj, "%s", name);
}
EXPORT_SYMBOL_GPL(driver_add_kobj);

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 7ae9740..989d854 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1389,7 +1389,7 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
rdev->mddev = mddev;
printk(KERN_INFO "md: bind<%s>\n", b);

- if ((err = kobject_add_ng(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
+ if ((err = kobject_add(&rdev->kobj, &mddev->kobj, "dev-%s", b)))
goto fail;

if (rdev->bdev->bd_part)
diff --git a/drivers/net/iseries_veth.c b/drivers/net/iseries_veth.c
index 1a8299a..ee15667 100644
--- a/drivers/net/iseries_veth.c
+++ b/drivers/net/iseries_veth.c
@@ -1084,7 +1084,7 @@ static struct net_device * __init veth_probe_one(int vlan,
}

kobject_init_ng(&port->kobject, &veth_port_ktype);
- if (0 != kobject_add_ng(&port->kobject, &dev->dev.kobj, "veth_port"))
+ if (0 != kobject_add(&port->kobject, &dev->dev.kobj, "veth_port"))
veth_error("Failed adding port for %s to sysfs.\n", dev->name);

veth_info("%s attached to iSeries vlan %d (LPAR map = 0x%.4X)\n",
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index acc387d..1ec2d31 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -172,7 +172,7 @@ static int uio_dev_add_attributes(struct uio_device *idev)
kobject_init_ng(&map->kobj, &map_attr_type);
map->mem = mem;
mem->map = map;
- ret = kobject_add_ng(&map->kobj, idev->map_dir, "map%d", mi);
+ ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
if (ret)
goto err;
ret = kobject_uevent(&map->kobj, KOBJ_ADD);
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 8b0aa71..84c5afd 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -80,9 +80,9 @@ static inline const char * kobject_name(const struct kobject * kobj)

extern void kobject_init(struct kobject *);
extern void kobject_init_ng(struct kobject *kobj, struct kobj_type *ktype);
-extern int __must_check kobject_add_ng(struct kobject *kobj,
- struct kobject *parent,
- const char *fmt, ...);
+extern int __must_check kobject_add(struct kobject *kobj,
+ struct kobject *parent,
+ const char *fmt, ...);
extern int __must_check kobject_init_and_add(struct kobject *kobj,
struct kobj_type *ktype,
struct kobject *parent,
diff --git a/lib/kobject.c b/lib/kobject.c
index d04789f..359e114 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -350,7 +350,7 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
}

/**
- * kobject_add_ng - the main kobject add function
+ * kobject_add - the main kobject add function
* @kobj: the kobject to add
* @parent: pointer to the parent of the kobject.
* @fmt: format to name the kobject with.
@@ -381,8 +381,8 @@ static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
* kobject_uevent() with the UEVENT_ADD parameter to ensure that
* userspace is properly notified of this kobject's creation.
*/
-int kobject_add_ng(struct kobject *kobj, struct kobject *parent,
- const char *fmt, ...)
+int kobject_add(struct kobject *kobj, struct kobject *parent,
+ const char *fmt, ...)
{
va_list args;
int retval;
@@ -396,7 +396,7 @@ int kobject_add_ng(struct kobject *kobj, struct kobject *parent,

return retval;
}
-EXPORT_SYMBOL(kobject_add_ng);
+EXPORT_SYMBOL(kobject_add);

/**
* kobject_init_and_add - initialize a kobject structure and add it to the kobject hierarchy
@@ -406,8 +406,8 @@ EXPORT_SYMBOL(kobject_add_ng);
* @fmt: the name of the kobject.
*
* This function combines the call to kobject_init_ng() and
- * kobject_add_ng(). The same type of error handling after a call to
- * kobject_add_ng() and kobject lifetime rules are the same here.
+ * kobject_add(). The same type of error handling after a call to
+ * kobject_add() and kobject lifetime rules are the same here.
*/
int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
struct kobject *parent, const char *fmt, ...)
@@ -677,7 +677,7 @@ struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
if (!kobj)
return NULL;

- retval = kobject_add_ng(kobj, parent, "%s", name);
+ retval = kobject_add(kobj, parent, "%s", name);
if (retval) {
printk(KERN_WARNING "%s: kobject_add error: %d\n",
__FUNCTION__, retval);
--
1.5.3.8

2008-01-25 08:40:37

by Greg KH

[permalink] [raw]
Subject: [PATCH 115/196] Kobject: change drivers/cpuidle/sysfs.c to use kobject_init_and_add

Stop using kobject_register, as this way we can control the sending of
the uevent properly, after everything is properly initialized.

Cc: Shaohua Li <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/cpuidle/sysfs.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 0f3515e..059db9c 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -300,14 +300,13 @@ int cpuidle_add_state_sysfs(struct cpuidle_device *device)
kobj->state = &device->states[i];
init_completion(&kobj->kobj_unregister);

- kobj->kobj.parent = &device->kobj;
- kobj->kobj.ktype = &ktype_state_cpuidle;
- kobject_set_name(&kobj->kobj, "state%d", i);
- ret = kobject_register(&kobj->kobj);
+ ret = kobject_init_and_add(&kobj->kobj, &ktype_state_cpuidle, &device->kobj,
+ "state%d", i);
if (ret) {
kfree(kobj);
goto error_state;
}
+ kobject_uevent(&kobj->kobj, KOBJ_ADD);
device->kobjs[i] = kobj;
}

@@ -339,12 +338,14 @@ int cpuidle_add_sysfs(struct sys_device *sysdev)
{
int cpu = sysdev->id;
struct cpuidle_device *dev;
+ int error;

dev = per_cpu(cpuidle_devices, cpu);
- dev->kobj.parent = &sysdev->kobj;
- dev->kobj.ktype = &ktype_cpuidle;
- kobject_set_name(&dev->kobj, "%s", "cpuidle");
- return kobject_register(&dev->kobj);
+ error = kobject_init_and_add(&dev->kobj, &ktype_cpuidle, &sysdev->kobj,
+ "cpuidle");
+ if (!error)
+ kobject_uevent(&dev->kobj, KOBJ_ADD);
+ return error;
}

/**
--
1.5.3.8

2008-01-25 08:41:07

by Greg KH

[permalink] [raw]
Subject: [PATCH 143/196] PCI: use proper call to driver_create_file

Don't try to call the "raw" sysfs_create_file when we already have a
helper function to do this kind of work for us.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
drivers/pci/pci-driver.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 6d1a216..73e3629 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -96,17 +96,21 @@ pci_create_newid_file(struct pci_driver *drv)
{
int error = 0;
if (drv->probe != NULL)
- error = sysfs_create_file(&drv->driver.kobj,
- &driver_attr_new_id.attr);
+ error = driver_create_file(&drv->driver, &driver_attr_new_id);
return error;
}

+static void pci_remove_newid_file(struct pci_driver *drv)
+{
+ driver_remove_file(&drv->driver, &driver_attr_new_id);
+}
#else /* !CONFIG_HOTPLUG */
static inline void pci_free_dynids(struct pci_driver *drv) {}
static inline int pci_create_newid_file(struct pci_driver *drv)
{
return 0;
}
+static inline void pci_remove_newid_file(struct pci_driver *drv) {}
#endif

/**
@@ -447,6 +451,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
void
pci_unregister_driver(struct pci_driver *drv)
{
+ pci_remove_newid_file(drv);
driver_unregister(&drv->driver);
pci_free_dynids(drv);
}
--
1.5.3.8

2008-01-25 08:42:23

by Mikael Starvik

[permalink] [raw]
Subject: RE: [PATCH 128/196] Kobject: the cris iop_fw_load.c code is broken

Yes, we are currently in the process of cleaning this up for all our device
drivers.
Thanks!

-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Friday, January 25, 2008 8:33 AM
To: [email protected]
Cc: Greg Kroah-Hartman; Mikael Starvik; Kay Sievers
Subject: [PATCH 128/196] Kobject: the cris iop_fw_load.c code is broken


This code is really really really broken. So much so that it's almost
impossible to fix with a simple patch, so just comment out the offending
registration with the kobject core, and mark the driver as broken.

The problem is that the code is trying to register a "raw" struct
device, which is not allowed. struct device is only for use within the
driver model. This is being done to try to use the firmware layer which
wants a struct device. To properly fix this, use something easy, like a
platform device, which is a struct device and can be used for this kind
of thing.

Cc: Mikael Starvik <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
---
arch/cris/arch-v32/drivers/iop_fw_load.c | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/cris/arch-v32/drivers/iop_fw_load.c
b/arch/cris/arch-v32/drivers/iop_fw_load.c
index 11f9895..f4bdc1d 100644
--- a/arch/cris/arch-v32/drivers/iop_fw_load.c
+++ b/arch/cris/arch-v32/drivers/iop_fw_load.c
@@ -20,6 +20,9 @@

#define IOP_TIMEOUT 100

+#error "This driver is broken with regard to its driver core usage."
+#error "Please contact <[email protected]> for details on how to fix it
properly."
+
static struct device iop_spu_device[2] = {
{ .bus_id = "iop-spu0", },
{ .bus_id = "iop-spu1", },
@@ -192,6 +195,13 @@ int iop_start_mpu(unsigned int start_addr)

static int __init iop_fw_load_init(void)
{
+#if 0
+ /*
+ * static struct devices can not be added directly to sysfs by
ignoring
+ * the driver model infrastructure. To fix this properly, please
use
+ * the platform_bus to register these devices to be able to properly
+ * use the firmware infrastructure.
+ */
device_initialize(&iop_spu_device[0]);
kobject_set_name(&iop_spu_device[0].kobj, "iop-spu0");
kobject_add(&iop_spu_device[0].kobj);
@@ -201,6 +211,7 @@ static int __init iop_fw_load_init(void)
device_initialize(&iop_mpu_device);
kobject_set_name(&iop_mpu_device.kobj, "iop-mpu");
kobject_add(&iop_mpu_device.kobj);
+#endif
return 0;
}

--
1.5.3.8

2008-01-25 08:46:18

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 076/196] ecryptfs: remove version_str file from sysfs

Greg Kroah-Hartman wrote:
> This file violates the one-value-per-file sysfs rule.
>
> If you all want it added back, please do something like a per-feature
> file to show what is present and what isn't.
>
> Cc: Kay Sievers <[email protected]>
> Cc: Mike Halcrow <[email protected]>
> Cc: Phillip Hellewell <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> fs/ecryptfs/main.c | 43 -------------------------------------------
> 1 files changed, 0 insertions(+), 43 deletions(-)

It's not really good policy to rip out ABIs found in release kernels
like this, even if the motivation is sound.

IMO "don't break ABIs" rule is far more important than a
one-value-per-file sysfs rule.

Jeff


2008-01-25 08:47:19

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [PATCH 012/196] nozomi driver


On Jan 24 2008 23:09, Greg Kroah-Hartman wrote:
>+/*
>+ * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
>+ *
>+ * Written by: Ulf Jakobsson,
>+ * Jan �erfeldt,
^

Neither in ISO-8859-1 nor UTF-8 this position contains something meaningful.
Mind to update to UTF-8?

>+/*
>+ * CHANGELOG

Changelogs go into git, not files, at least that is what was mentioned
time and again.

>+#ifdef __BIG_ENDIAN
>+/* Big endian */
>+
>+struct toggles {
>+ unsigned enabled:5; /*
>+ * Toggle fields are valid if enabled is 0,
>+ * else A-channels must always be used.
>+ */
>+ unsigned diag_dl:1;
>+ unsigned mdm_dl:1;
>+ unsigned mdm_ul:1;
>+} __attribute__ ((packed));

Probably just me, unsigned int is a good bit more explicit.
The driver may also use a combined struct with
BIG_ENDIAN_BITFIELD/LITTLE_ENDIAN_BIGFIELD (see e.g. linux/ip.h).

>+/* Global variables */
>+static struct pci_device_id nozomi_pci_tbl[] = {
>+ {PCI_DEVICE(VENDOR1, DEVICE1)},
>+ {},
>+};

The macros are only used once, could just as well substitute them
by their real values.

>+/*
>+ * TODO:
>+ * -Optimize
>+ * -Rewrite cleaner
>+ */

>+/*
>+ * Handle donlink data, ports that are handled are modem and diagnostics
^

downlink

>+static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);

While 0444 is probably never going to change its meaning, S_IRUGO comes
into mind.

>+/* just to discard single character writes */
>+static void ntty_put_char(struct tty_struct *tty, unsigned char c)
>+{
>+ /* FIXME !!! */
>+ DBG2("PUT CHAR Function: %c", c);
>+}

fix it?

2008-01-25 09:10:07

by Dave Young

[permalink] [raw]
Subject: Re: [PATCH 044/196] kset: add kset_create_and_add function

On Jan 25, 2008 3:09 PM, Greg Kroah-Hartman <[email protected]> wrote:
> Now ksets can be dynamically created on the fly, no static definitions
> are required. Thanks to Miklos for hints on how to make this work
> better for the callers.
>
> And thanks to Kay for finding some stupid bugs in my original version
> and pointing out that we need to handle the fact that kobject's can have
> a kset as a parent and to handle that properly in kobject_add().
>
> Cc: Kay Sievers <[email protected]>
> Cc: Miklos Szeredi <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> include/linux/kobject.h | 4 ++-
> lib/kobject.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 94 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/kobject.h b/include/linux/kobject.h
> index 0b97b3a..f91aeb7 100644
> --- a/include/linux/kobject.h
> +++ b/include/linux/kobject.h
> @@ -150,11 +150,13 @@ struct kset {
> struct kset_uevent_ops *uevent_ops;
> };
>
> -
> extern void kset_init(struct kset * k);
> extern int __must_check kset_add(struct kset * k);
> extern int __must_check kset_register(struct kset * k);
> extern void kset_unregister(struct kset * k);
> +extern struct kset * __must_check kset_create_and_add(const char *name,
> + struct kset_uevent_ops *u,
> + struct kobject *parent_kobj);
>
> static inline struct kset * to_kset(struct kobject * kobj)
> {
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 8f24940..4fb27ba 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -186,8 +186,15 @@ int kobject_add(struct kobject * kobj)
> if (kobj->kset) {
> spin_lock(&kobj->kset->list_lock);
>
> - if (!parent)
> + if (!parent) {
> parent = kobject_get(&kobj->kset->kobj);
> + /*
> + * If the kset is our parent, get a second
> + * reference, we drop both the kset and the
> + * parent ref on cleanup
> + */
> + kobject_get(parent);
> + }
>
> list_add_tail(&kobj->entry,&kobj->kset->list);
> spin_unlock(&kobj->kset->list_lock);
> @@ -787,6 +794,89 @@ int subsys_create_file(struct kset *s, struct subsys_attribute *a)
> return error;
> }
>
> +static void kset_release(struct kobject *kobj)
> +{
> + struct kset *kset = container_of(kobj, struct kset, kobj);
> + pr_debug("kset %s: now freed\n", kobject_name(kobj));
> + kfree(kset);
> +}
> +
> +static struct kobj_type kset_type = {
> + .release = kset_release,
> +};
> +
> +/**
> + * kset_create - create a struct kset dynamically
> + *
> + * @name: the name for the kset
> + * @uevent_ops: a struct kset_uevent_ops for the kset
> + * @parent_kobj: the parent kobject of this kset, if any.
> + *
> + * This function creates a kset structure dynamically. This structure can
> + * then be registered with the system and show up in sysfs with a call to
> + * kset_register(). When you are finished with this structure, if
> + * kset_register() has been called, call kset_unregister() and the
> + * structure will be dynamically freed when it is no longer being used.
> + *
> + * If the kset was not able to be created, NULL will be returned.
> + */
> +static struct kset *kset_create(const char *name,
> + struct kset_uevent_ops *uevent_ops,
> + struct kobject *parent_kobj)
> +{
> + struct kset *kset;
> +
> + kset = kzalloc(sizeof(*kset), GFP_KERNEL);
> + if (!kset)
> + return NULL;
> + kobject_set_name(&kset->kobj, name);
> + kset->uevent_ops = uevent_ops;
> + kset->kobj.parent = parent_kobj;
> +
> + /*
> + * The kobject of this kset will have a type of kset_type and belong to
> + * no kset itself. That way we can properly free it when it is
> + * finished being used.
> + */
> + kset->kobj.ktype = &kset_type;
> + kset->kobj.kset = NULL;
> +
> + return kset;
> +}
> +
> +/**
> + * kset_create_and_add - create a struct kset dynamically and add it to sysfs
> + *
> + * @name: the name for the kset
> + * @uevent_ops: a struct kset_uevent_ops for the kset
> + * @parent_kobj: the parent kobject of this kset, if any.
> + *
> + * This function creates a kset structure dynamically and registers it
> + * with sysfs. When you are finished with this structure, call
> + * kset_unregister() and the structure will be dynamically freed when it
> + * is no longer being used.
> + *
> + * If the kset was not able to be created, NULL will be returned.
> + */
> +struct kset *kset_create_and_add(const char *name,
> + struct kset_uevent_ops *uevent_ops,
> + struct kobject *parent_kobj)
> +{
> + struct kset *kset;
> + int error;
> +
> + kset = kset_create(name, uevent_ops, parent_kobj);
> + if (!kset)
> + return NULL;
> + error = kset_register(kset);
> + if (error) {
> + kfree(kset);

How about : kobject_put(&kset->kobj);

> + return NULL;
> + }
> + return kset;
> +}
> +EXPORT_SYMBOL_GPL(kset_create_and_add);
> +
> EXPORT_SYMBOL(kobject_init);
> EXPORT_SYMBOL(kobject_register);
> EXPORT_SYMBOL(kobject_unregister);
> --
> 1.5.3.8
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2008-01-25 10:02:19

by Hans J. Koch

[permalink] [raw]
Subject: Re: [PATCH 185/196] UIO: constify function pointer tables

Am Thu, 24 Jan 2008 23:33:34 -0800
schrieb Greg Kroah-Hartman <[email protected]>:

> From: Jan Engelhardt <[email protected]>
>
> Signed-off-by: Jan Engelhardt <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Signed-off-by: Hans J. Koch <[email protected]>

> ---
> drivers/uio/uio.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
> index 03b66fb..cc246fa 100644
> --- a/drivers/uio/uio.c
> +++ b/drivers/uio/uio.c
> @@ -39,7 +39,7 @@ struct uio_device {
>
> static int uio_major;
> static DEFINE_IDR(uio_idr);
> -static struct file_operations uio_fops;
> +static const struct file_operations uio_fops;
>
> /* UIO class infrastructure */
> static struct uio_class {
> @@ -508,7 +508,7 @@ static int uio_mmap(struct file *filep, struct
> vm_area_struct *vma) }
> }
>
> -static struct file_operations uio_fops = {
> +static const struct file_operations uio_fops = {
> .owner = THIS_MODULE,
> .open = uio_open,
> .release = uio_release,

2008-01-25 11:56:37

by Stefan Richter

[permalink] [raw]
Subject: Re: [PATCH 012/196] nozomi driver

On 1/25/2008 9:31 AM, Jan Engelhardt wrote:
> On Jan 24 2008 23:09, Greg Kroah-Hartman wrote:
>>+#ifdef __BIG_ENDIAN
>>+/* Big endian */
>>+
>>+struct toggles {
>>+ unsigned enabled:5; /*
>>+ * Toggle fields are valid if enabled is 0,
>>+ * else A-channels must always be used.
>>+ */
>>+ unsigned diag_dl:1;
>>+ unsigned mdm_dl:1;
>>+ unsigned mdm_ul:1;
>>+} __attribute__ ((packed));
>
> Probably just me, unsigned int is a good bit more explicit.
> The driver may also use a combined struct with
> BIG_ENDIAN_BITFIELD/LITTLE_ENDIAN_BIGFIELD (see e.g. linux/ip.h).

I've been told we don't do bitfields anymore in on-the-wire data,
on-disk data, userspace ABIs, etc. because their layout is compiler
dependent in the end.
--
Stefan Richter
-=====-==--- ---= ==--=
http://arcgraph.de/sr/

2008-01-25 12:21:16

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 085/196] kset: convert s390 ipl.c to use kset_create

On Thu, Jan 24, 2008 at 11:31:54PM -0800, Greg Kroah-Hartman wrote:
> Dynamically create the kset instead of declaring it statically.
> This makes the kobject attributes now work properly that I broke in the
> previous patch.

Could you please merge this and the previous patch before it goes
upstream? Having an intermediate state where things are broken
will cause pain and additional work in case of bisecting.
Thanks!

2008-01-25 12:44:45

by Frank Seidel

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

From: Frank Seidel <[email protected]>

This is a driver to control the cardbus wireless data card that works on
3g networks.

Greg Kroah-Hartman <[email protected]> did the initial driver cleanup.
Thanks to Arnaud Patard <[email protected]> for help with bugfixing.
Thanks to Alan Cox for a lot of tty fixes.
Thanks to Satyam Sharma <[email protected]> for fixing buildbreakage.
Thanks to Frank Seidel <[email protected]> for a lot of bugfixes and
rewriting to make it a sane Linux driver
Thanks to Jiri Slaby <[email protected]> for a lot bugfixes, cleanups
and rewrites that make it much more readable.

Signed-off-by: Greg Kroah-Hartman <[email protected]>
Signed-off-by: Frank Seidel <[email protected]>
Signed-off-by: Jiri Slaby <[email protected]>
---
drivers/char/Kconfig | 10
drivers/char/Makefile | 1
drivers/char/nozomi.c | 1943 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 1954 insertions(+)

--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -373,6 +373,16 @@ config ISTALLION
To compile this driver as a module, choose M here: the
module will be called istallion.

+config NOZOMI
+ tristate "HSDPA Broadband Wireless Data Card - Globe Trotter"
+ depends on PCI && EXPERIMENTAL
+ help
+ If you have a HSDPA driver Broadband Wireless Data Card -
+ Globe Trotter PCMCIA card, say Y here.
+
+ To compile this driver as a module, choose M here, the module
+ will be called nozomi.
+
config A2232
tristate "Commodore A2232 serial support (EXPERIMENTAL)"
depends on EXPERIMENTAL && ZORRO && BROKEN_ON_SMP
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_SERIAL167) += serial167.o
obj-$(CONFIG_CYCLADES) += cyclades.o
obj-$(CONFIG_STALLION) += stallion.o
obj-$(CONFIG_ISTALLION) += istallion.o
+obj-$(CONFIG_NOZOMI) += nozomi.o
obj-$(CONFIG_DIGIEPCA) += epca.o
obj-$(CONFIG_SPECIALIX) += specialix.o
obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
--- /dev/null
+++ b/drivers/char/nozomi.c
@@ -0,0 +1,1943 @@
+/*
+ * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
+ *
+ * Written by: Ulf Jakobsson,
+ * Jan Åkerfeldt,
+ * Stefan Thomasson,
+ *
+ * Maintained by: Paul Hardwick ([email protected])
+ *
+ * Patches:
+ * Locking code changes for Vodafone by Sphere Systems Ltd,
+ * Andrew Bird ([email protected] )
+ * & Phil Sanderson
+ *
+ * Source has been ported from an implementation made by Filip Aben @ Option
+ *
+ * --------------------------------------------------------------------------
+ *
+ * Copyright (c) 2005,2006 Option Wireless Sweden AB
+ * Copyright (c) 2006 Sphere Systems Ltd
+ * Copyright (c) 2006 Option Wireless n/v
+ * All rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * --------------------------------------------------------------------------
+ */
+
+/* Enable this to have a lot of debug printouts */
+#define DEBUG
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/ioport.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/serial.h>
+#include <linux/interrupt.h>
+#include <linux/kmod.h>
+#include <linux/init.h>
+#include <linux/kfifo.h>
+#include <linux/uaccess.h>
+#include <asm/byteorder.h>
+
+#include <linux/delay.h>
+
+
+#define VERSION_STRING DRIVER_DESC " 2.1d (build date: " \
+ __DATE__ " " __TIME__ ")"
+
+/* Macros definitions */
+
+/* Default debug printout level */
+#define NOZOMI_DEBUG_LEVEL 0x00
+
+#define P_BUF_SIZE 128
+#define NFO(_err_flag_, args...) \
+do { \
+ char tmp[P_BUF_SIZE]; \
+ snprintf(tmp, sizeof(tmp), ##args); \
+ printk(_err_flag_ "[%d] %s(): %s\n", __LINE__, \
+ __FUNCTION__, tmp); \
+} while (0)
+
+#define DBG1(args...) D_(0x01, ##args)
+#define DBG2(args...) D_(0x02, ##args)
+#define DBG3(args...) D_(0x04, ##args)
+#define DBG4(args...) D_(0x08, ##args)
+#define DBG5(args...) D_(0x10, ##args)
+#define DBG6(args...) D_(0x20, ##args)
+#define DBG7(args...) D_(0x40, ##args)
+#define DBG8(args...) D_(0x80, ##args)
+
+#ifdef DEBUG
+/* Do we need this settable at runtime? */
+static int debug = NOZOMI_DEBUG_LEVEL;
+
+#define D(lvl, args...) do \
+ {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
+ while (0)
+#define D_(lvl, args...) D(lvl, ##args)
+
+/* These printouts are always printed */
+
+#else
+static int debug;
+#define D_(lvl, args...)
+#endif
+
+/* TODO: rewrite to optimize macros... */
+
+#define TMP_BUF_MAX 256
+
+#define DUMP(buf__,len__) \
+ do { \
+ char tbuf[TMP_BUF_MAX] = {0};\
+ if (len__ > 1) {\
+ snprintf(tbuf, len__ > TMP_BUF_MAX ? TMP_BUF_MAX : len__, "%s", buf__);\
+ if (tbuf[len__-2] == '\r') {\
+ tbuf[len__-2] = 'r';\
+ } \
+ DBG1("SENDING: '%s' (%d+n)", tbuf, len__);\
+ } else {\
+ DBG1("SENDING: '%s' (%d)", tbuf, len__);\
+ } \
+} while (0)
+
+/* Defines */
+#define NOZOMI_NAME "nozomi"
+#define NOZOMI_NAME_TTY "nozomi_tty"
+#define DRIVER_DESC "Nozomi driver"
+
+#define NTTY_TTY_MAXMINORS 256
+#define NTTY_FIFO_BUFFER_SIZE 8192
+
+/* Must be power of 2 */
+#define FIFO_BUFFER_SIZE_UL 8192
+
+/* Size of tmp send buffer to card */
+#define SEND_BUF_MAX 1024
+#define RECEIVE_BUF_MAX 4
+
+
+/* Define all types of vendors and devices to support */
+#define VENDOR1 0x1931 /* Vendor Option */
+#define DEVICE1 0x000c /* HSDPA card */
+
+#define R_IIR 0x0000 /* Interrupt Identity Register */
+#define R_FCR 0x0000 /* Flow Control Register */
+#define R_IER 0x0004 /* Interrupt Enable Register */
+
+#define CONFIG_MAGIC 0xEFEFFEFE
+#define TOGGLE_VALID 0x0000
+
+/* Definition of interrupt tokens */
+#define MDM_DL1 0x0001
+#define MDM_UL1 0x0002
+#define MDM_DL2 0x0004
+#define MDM_UL2 0x0008
+#define DIAG_DL1 0x0010
+#define DIAG_DL2 0x0020
+#define DIAG_UL 0x0040
+#define APP1_DL 0x0080
+#define APP1_UL 0x0100
+#define APP2_DL 0x0200
+#define APP2_UL 0x0400
+#define CTRL_DL 0x0800
+#define CTRL_UL 0x1000
+#define RESET 0x8000
+
+#define MDM_DL (MDM_DL1 | MDM_DL2)
+#define MDM_UL (MDM_UL1 | MDM_UL2)
+#define DIAG_DL (DIAG_DL1 | DIAG_DL2)
+
+/* modem signal definition */
+#define CTRL_DSR 0x0001
+#define CTRL_DCD 0x0002
+#define CTRL_RI 0x0004
+#define CTRL_CTS 0x0008
+
+#define CTRL_DTR 0x0001
+#define CTRL_RTS 0x0002
+
+#define MAX_PORT 4
+#define NOZOMI_MAX_PORTS 5
+#define NOZOMI_MAX_CARDS (NTTY_TTY_MAXMINORS / MAX_PORT)
+
+/* Type definitions */
+
+/*
+ * There are two types of nozomi cards,
+ * one with 2048 memory and with 8192 memory
+ */
+enum card_type {
+ F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
+ F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
+};
+
+/* Two different toggle channels exist */
+enum channel_type {
+ CH_A = 0,
+ CH_B = 1,
+};
+
+/* Port definition for the card regarding flow control */
+enum ctrl_port_type {
+ CTRL_CMD = 0,
+ CTRL_MDM = 1,
+ CTRL_DIAG = 2,
+ CTRL_APP1 = 3,
+ CTRL_APP2 = 4,
+ CTRL_ERROR = -1,
+};
+
+/* Ports that the nozomi has */
+enum port_type {
+ PORT_MDM = 0,
+ PORT_DIAG = 1,
+ PORT_APP1 = 2,
+ PORT_APP2 = 3,
+ PORT_CTRL = 4,
+ PORT_ERROR = -1,
+};
+
+#ifdef __BIG_ENDIAN
+/* Big endian */
+
+struct toggles {
+ unsigned int enabled:5; /*
+ * Toggle fields are valid if enabled is 0,
+ * else A-channels must always be used.
+ */
+ unsigned int diag_dl:1;
+ unsigned int mdm_dl:1;
+ unsigned int mdm_ul:1;
+} __attribute__ ((packed));
+
+/* Configuration table to read at startup of card */
+/* Is for now only needed during initialization phase */
+struct config_table {
+ u32 signature;
+ u16 product_information;
+ u16 version;
+ u8 pad3[3];
+ struct toggles toggle;
+ u8 pad1[4];
+ u16 dl_mdm_len1; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_start;
+
+ u16 dl_diag_len1;
+ u16 dl_mdm_len2; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_app1_len;
+
+ u16 dl_diag_len2;
+ u16 dl_ctrl_len;
+ u16 dl_app2_len;
+ u8 pad2[16];
+ u16 ul_mdm_len1;
+ u16 ul_start;
+ u16 ul_diag_len;
+ u16 ul_mdm_len2;
+ u16 ul_app1_len;
+ u16 ul_app2_len;
+ u16 ul_ctrl_len;
+} __attribute__ ((packed));
+
+/* This stores all control downlink flags */
+struct ctrl_dl {
+ u8 port;
+ unsigned int reserved:4;
+ unsigned int CTS:1;
+ unsigned int RI:1;
+ unsigned int DCD:1;
+ unsigned int DSR:1;
+} __attribute__ ((packed));
+
+/* This stores all control uplink flags */
+struct ctrl_ul {
+ u8 port;
+ unsigned int reserved:6;
+ unsigned int RTS:1;
+ unsigned int DTR:1;
+} __attribute__ ((packed));
+
+#else
+/* Little endian */
+
+/* This represents the toggle information */
+struct toggles {
+ unsigned int mdm_ul:1;
+ unsigned int mdm_dl:1;
+ unsigned int diag_dl:1;
+ unsigned int enabled:5; /*
+ * Toggle fields are valid if enabled is 0,
+ * else A-channels must always be used.
+ */
+} __attribute__ ((packed));
+
+/* Configuration table to read at startup of card */
+struct config_table {
+ u32 signature;
+ u16 version;
+ u16 product_information;
+ struct toggles toggle;
+ u8 pad1[7];
+ u16 dl_start;
+ u16 dl_mdm_len1; /*
+ * If this is 64, it can hold
+ * 60 bytes + 4 that is length field
+ */
+ u16 dl_mdm_len2;
+ u16 dl_diag_len1;
+ u16 dl_diag_len2;
+ u16 dl_app1_len;
+ u16 dl_app2_len;
+ u16 dl_ctrl_len;
+ u8 pad2[16];
+ u16 ul_start;
+ u16 ul_mdm_len2;
+ u16 ul_mdm_len1;
+ u16 ul_diag_len;
+ u16 ul_app1_len;
+ u16 ul_app2_len;
+ u16 ul_ctrl_len;
+} __attribute__ ((packed));
+
+/* This stores all control downlink flags */
+struct ctrl_dl {
+ unsigned int DSR:1;
+ unsigned int DCD:1;
+ unsigned int RI:1;
+ unsigned int CTS:1;
+ unsigned int reserverd:4;
+ u8 port;
+} __attribute__ ((packed));
+
+/* This stores all control uplink flags */
+struct ctrl_ul {
+ unsigned int DTR:1;
+ unsigned int RTS:1;
+ unsigned int reserved:6;
+ u8 port;
+} __attribute__ ((packed));
+#endif
+
+/* This holds all information that is needed regarding a port */
+struct port {
+ u8 update_flow_control;
+ struct ctrl_ul ctrl_ul;
+ struct ctrl_dl ctrl_dl;
+ struct kfifo *fifo_ul;
+ void __iomem *dl_addr[2];
+ u32 dl_size[2];
+ u8 toggle_dl;
+ void __iomem *ul_addr[2];
+ u32 ul_size[2];
+ u8 toggle_ul;
+ u16 token_dl;
+
+ struct tty_struct *tty;
+ int tty_open_count;
+ /* mutex to ensure one access patch to this port */
+ struct mutex tty_sem;
+ wait_queue_head_t tty_wait;
+ struct async_icount tty_icount;
+};
+
+/* Private data one for each card in the system */
+struct nozomi {
+ void __iomem *base_addr;
+ unsigned long flip;
+
+ /* Pointers to registers */
+ void __iomem *reg_iir;
+ void __iomem *reg_fcr;
+ void __iomem *reg_ier;
+
+ u16 last_ier;
+ enum card_type card_type;
+ struct config_table config_table; /* Configuration table */
+ struct pci_dev *pdev;
+ struct port port[NOZOMI_MAX_PORTS];
+ u8 *send_buf;
+
+ spinlock_t spin_mutex; /* secures access to registers and tty */
+
+ unsigned int index_start;
+ u32 open_ttys;
+};
+
+/* This is a data packet that is read or written to/from card */
+struct buffer {
+ u32 size; /* size is the length of the data buffer */
+ u8 *data;
+} __attribute__ ((packed));
+
+/* Global variables */
+static struct pci_device_id nozomi_pci_tbl[] = {
+ {PCI_DEVICE(VENDOR1, DEVICE1)},
+ {},
+};
+
+MODULE_DEVICE_TABLE(pci, nozomi_pci_tbl);
+
+static struct nozomi *ndevs[NOZOMI_MAX_CARDS];
+static struct tty_driver *ntty_driver;
+
+/*
+ * find card by tty_index
+ */
+static inline struct nozomi *get_dc_by_tty(const struct tty_struct *tty)
+{
+ return tty ? ndevs[tty->index / MAX_PORT] : NULL;
+}
+
+static inline struct port *get_port_by_tty(const struct tty_struct *tty)
+{
+ struct nozomi *ndev = get_dc_by_tty(tty);
+ return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL;
+}
+
+/*
+ * TODO:
+ * -Optimize
+ * -Rewrite cleaner
+ */
+
+static void read_mem32(u32 *buf, const void __iomem *mem_addr_start,
+ u32 size_bytes)
+{
+ u32 i = 0;
+ const u32 *ptr = (__force u32 *) mem_addr_start;
+ u16 *buf16;
+
+ if (unlikely(!ptr || !buf))
+ goto out;
+
+ /* shortcut for extremely often used cases */
+ switch (size_bytes) {
+ case 2: /* 2 bytes */
+ buf16 = (u16 *) buf;
+ *buf16 = __le16_to_cpu(readw((void __iomem *)ptr));
+ goto out;
+ break;
+ case 4: /* 4 bytes */
+ *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
+ goto out;
+ break;
+ }
+
+ while (i < size_bytes) {
+ if (size_bytes - i == 2) {
+ /* Handle 2 bytes in the end */
+ buf16 = (u16 *) buf;
+ *(buf16) = __le16_to_cpu(readw((void __iomem *)ptr));
+ i += 2;
+ } else {
+ /* Read 4 bytes */
+ *(buf) = __le32_to_cpu(readl((void __iomem *)ptr));
+ i += 4;
+ }
+ buf++;
+ ptr++;
+ }
+out:
+ return;
+}
+
+/*
+ * TODO:
+ * -Optimize
+ * -Rewrite cleaner
+ */
+static u32 write_mem32(void __iomem *mem_addr_start, u32 *buf,
+ u32 size_bytes)
+{
+ u32 i = 0;
+ u32 *ptr = (__force u32 *) mem_addr_start;
+ u16 *buf16;
+
+ if (unlikely(!ptr || !buf))
+ return 0;
+
+ /* shortcut for extremely often used cases */
+ switch (size_bytes) {
+ case 2: /* 2 bytes */
+ buf16 = (u16 *) buf;
+ writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
+ return 2;
+ break;
+ case 1: /*
+ * also needs to write 4 bytes in this case
+ * so falling through..
+ */
+ case 4: /* 4 bytes */
+ writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
+ return 4;
+ break;
+ }
+
+ while (i < size_bytes) {
+ if (size_bytes - i == 2) {
+ /* 2 bytes */
+ buf16 = (u16 *) buf;
+ writew(__cpu_to_le16(*buf16), (void __iomem *)ptr);
+ i += 2;
+ } else {
+ /* 4 bytes */
+ writel(__cpu_to_le32(*buf), (void __iomem *)ptr);
+ i += 4;
+ }
+ buf++;
+ ptr++;
+ }
+ return i;
+}
+
+/* Setup pointers to different channels and also setup buffer sizes. */
+static void setup_memory(struct nozomi *dc)
+{
+ void __iomem *offset = dc->base_addr + dc->config_table.dl_start;
+ /* The length reported is including the length field of 4 bytes,
+ * hence subtract with 4.
+ */
+ const u16 buff_offset = 4;
+
+ /* Modem port dl configuration */
+ dc->port[PORT_MDM].dl_addr[CH_A] = offset;
+ dc->port[PORT_MDM].dl_addr[CH_B] =
+ (offset += dc->config_table.dl_mdm_len1);
+ dc->port[PORT_MDM].dl_size[CH_A] =
+ dc->config_table.dl_mdm_len1 - buff_offset;
+ dc->port[PORT_MDM].dl_size[CH_B] =
+ dc->config_table.dl_mdm_len2 - buff_offset;
+
+ /* Diag port dl configuration */
+ dc->port[PORT_DIAG].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_mdm_len2);
+ dc->port[PORT_DIAG].dl_size[CH_A] =
+ dc->config_table.dl_diag_len1 - buff_offset;
+ dc->port[PORT_DIAG].dl_addr[CH_B] =
+ (offset += dc->config_table.dl_diag_len1);
+ dc->port[PORT_DIAG].dl_size[CH_B] =
+ dc->config_table.dl_diag_len2 - buff_offset;
+
+ /* App1 port dl configuration */
+ dc->port[PORT_APP1].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_diag_len2);
+ dc->port[PORT_APP1].dl_size[CH_A] =
+ dc->config_table.dl_app1_len - buff_offset;
+
+ /* App2 port dl configuration */
+ dc->port[PORT_APP2].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_app1_len);
+ dc->port[PORT_APP2].dl_size[CH_A] =
+ dc->config_table.dl_app2_len - buff_offset;
+
+ /* Ctrl dl configuration */
+ dc->port[PORT_CTRL].dl_addr[CH_A] =
+ (offset += dc->config_table.dl_app2_len);
+ dc->port[PORT_CTRL].dl_size[CH_A] =
+ dc->config_table.dl_ctrl_len - buff_offset;
+
+ offset = dc->base_addr + dc->config_table.ul_start;
+
+ /* Modem Port ul configuration */
+ dc->port[PORT_MDM].ul_addr[CH_A] = offset;
+ dc->port[PORT_MDM].ul_size[CH_A] =
+ dc->config_table.ul_mdm_len1 - buff_offset;
+ dc->port[PORT_MDM].ul_addr[CH_B] =
+ (offset += dc->config_table.ul_mdm_len1);
+ dc->port[PORT_MDM].ul_size[CH_B] =
+ dc->config_table.ul_mdm_len2 - buff_offset;
+
+ /* Diag port ul configuration */
+ dc->port[PORT_DIAG].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_mdm_len2);
+ dc->port[PORT_DIAG].ul_size[CH_A] =
+ dc->config_table.ul_diag_len - buff_offset;
+
+ /* App1 port ul configuration */
+ dc->port[PORT_APP1].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_diag_len);
+ dc->port[PORT_APP1].ul_size[CH_A] =
+ dc->config_table.ul_app1_len - buff_offset;
+
+ /* App2 port ul configuration */
+ dc->port[PORT_APP2].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_app1_len);
+ dc->port[PORT_APP2].ul_size[CH_A] =
+ dc->config_table.ul_app2_len - buff_offset;
+
+ /* Ctrl ul configuration */
+ dc->port[PORT_CTRL].ul_addr[CH_A] =
+ (offset += dc->config_table.ul_app2_len);
+ dc->port[PORT_CTRL].ul_size[CH_A] =
+ dc->config_table.ul_ctrl_len - buff_offset;
+}
+
+/* Dump config table under initalization phase */
+#ifdef DEBUG
+static void dump_table(const struct nozomi *dc)
+{
+ DBG3("signature: 0x%08X", dc->config_table.signature);
+ DBG3("version: 0x%04X", dc->config_table.version);
+ DBG3("product_information: 0x%04X", \
+ dc->config_table.product_information);
+ DBG3("toggle enabled: %d", dc->config_table.toggle.enabled);
+ DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul);
+ DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl);
+ DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl);
+
+ DBG3("dl_start: 0x%04X", dc->config_table.dl_start);
+ DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1,
+ dc->config_table.dl_mdm_len1);
+ DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2,
+ dc->config_table.dl_mdm_len2);
+ DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1,
+ dc->config_table.dl_diag_len1);
+ DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2,
+ dc->config_table.dl_diag_len2);
+ DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len,
+ dc->config_table.dl_app1_len);
+ DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len,
+ dc->config_table.dl_app2_len);
+ DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len,
+ dc->config_table.dl_ctrl_len);
+ DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start,
+ dc->config_table.ul_start);
+ DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1,
+ dc->config_table.ul_mdm_len1);
+ DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2,
+ dc->config_table.ul_mdm_len2);
+ DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len,
+ dc->config_table.ul_diag_len);
+ DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len,
+ dc->config_table.ul_app1_len);
+ DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len,
+ dc->config_table.ul_app2_len);
+ DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len,
+ dc->config_table.ul_ctrl_len);
+}
+#else
+static inline void dump_table(const struct nozomi *dc) { }
+#endif
+
+/*
+ * Read configuration table from card under intalization phase
+ * Returns 1 if ok, else 0
+ */
+static int nozomi_read_config_table(struct nozomi *dc)
+{
+ read_mem32((u32 *) &dc->config_table, dc->base_addr + 0,
+ sizeof(struct config_table));
+
+ if (dc->config_table.signature != CONFIG_MAGIC) {
+ dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n",
+ dc->config_table.signature, CONFIG_MAGIC);
+ return 0;
+ }
+
+ if ((dc->config_table.version == 0)
+ || (dc->config_table.toggle.enabled == TOGGLE_VALID)) {
+ int i;
+ DBG1("Second phase, configuring card");
+
+ setup_memory(dc);
+
+ dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul;
+ dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl;
+ dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl;
+ DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d",
+ dc->port[PORT_MDM].toggle_ul,
+ dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl);
+
+ dump_table(dc);
+
+ for (i = PORT_MDM; i < MAX_PORT; i++) {
+ dc->port[i].fifo_ul =
+ kfifo_alloc(FIFO_BUFFER_SIZE_UL, GFP_ATOMIC, NULL);
+ memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl));
+ memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul));
+ }
+
+ /* Enable control channel */
+ dc->last_ier = dc->last_ier | CTRL_DL;
+ writew(dc->last_ier, dc->reg_ier);
+
+ dev_info(&dc->pdev->dev, "Initialization OK!\n");
+ return 1;
+ }
+
+ if ((dc->config_table.version > 0)
+ && (dc->config_table.toggle.enabled != TOGGLE_VALID)) {
+ u32 offset = 0;
+ DBG1("First phase: pushing upload buffers, clearing download");
+
+ dev_info(&dc->pdev->dev, "Version of card: %d\n",
+ dc->config_table.version);
+
+ /* Here we should disable all I/O over F32. */
+ setup_memory(dc);
+
+ /*
+ * We should send ALL channel pair tokens back along
+ * with reset token
+ */
+
+ /* push upload modem buffers */
+ write_mem32(dc->port[PORT_MDM].ul_addr[CH_A],
+ (u32 *) &offset, 4);
+ write_mem32(dc->port[PORT_MDM].ul_addr[CH_B],
+ (u32 *) &offset, 4);
+
+ writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr);
+
+ DBG1("First phase done");
+ }
+
+ return 1;
+}
+
+/* Enable uplink interrupts */
+static void enable_transmit_ul(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {MDM_UL, DIAG_UL, APP1_UL, APP2_UL, CTRL_UL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier |= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Disable uplink interrupts */
+static void disable_transmit_ul(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {~MDM_UL, ~DIAG_UL, ~APP1_UL, ~APP2_UL, ~CTRL_UL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier &= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Enable downlink interrupts */
+static void enable_transmit_dl(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {MDM_DL, DIAG_DL, APP1_DL, APP2_DL, CTRL_DL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier |= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/* Disable downlink interrupts */
+static void disable_transmit_dl(enum port_type port, struct nozomi *dc)
+{
+ u16 mask[NOZOMI_MAX_PORTS] = \
+ {~MDM_DL, ~DIAG_DL, ~APP1_DL, ~APP2_DL, ~CTRL_DL};
+
+ if (port < NOZOMI_MAX_PORTS) {
+ dc->last_ier &= mask[port];
+ writew(dc->last_ier, dc->reg_ier);
+ } else {
+ dev_err(&dc->pdev->dev, "Called with wrong port?\n");
+ }
+}
+
+/*
+ * Return 1 - send buffer to card and ack.
+ * Return 0 - don't ack, don't send buffer to card.
+ */
+static int send_data(enum port_type index, struct nozomi *dc)
+{
+ u32 size = 0;
+ struct port *port = &dc->port[index];
+ u8 toggle = port->toggle_ul;
+ void __iomem *addr = port->ul_addr[toggle];
+ u32 ul_size = port->ul_size[toggle];
+ struct tty_struct *tty = port->tty;
+
+ /* Get data from tty and place in buf for now */
+ size = __kfifo_get(port->fifo_ul, dc->send_buf,
+ ul_size < SEND_BUF_MAX ? ul_size : SEND_BUF_MAX);
+
+ if (size == 0) {
+ DBG4("No more data to send, disable link:");
+ return 0;
+ }
+
+ /* DUMP(buf, size); */
+
+ /* Write length + data */
+ write_mem32(addr, (u32 *) &size, 4);
+ write_mem32(addr + 4, (u32 *) dc->send_buf, size);
+
+ if (tty)
+ tty_wakeup(tty);
+
+ return 1;
+}
+
+/* If all data has been read, return 1, else 0 */
+static int receive_data(enum port_type index, struct nozomi *dc)
+{
+ u8 buf[RECEIVE_BUF_MAX] = { 0 };
+ int size;
+ u32 offset = 4;
+ struct port *port = &dc->port[index];
+ void __iomem *addr = port->dl_addr[port->toggle_dl];
+ struct tty_struct *tty = port->tty;
+ int i;
+
+ if (unlikely(!tty)) {
+ DBG1("tty not open for port: %d?", index);
+ return 1;
+ }
+
+ read_mem32((u32 *) &size, addr, 4);
+ /* DBG1( "%d bytes port: %d", size, index); */
+
+ if (test_bit(TTY_THROTTLED, &tty->flags)) {
+ DBG1("No room in tty, don't read data, don't ack interrupt, "
+ "disable interrupt");
+
+ /* disable interrupt in downlink... */
+ disable_transmit_dl(index, dc);
+ return 0;
+ }
+
+ if (unlikely(size == 0)) {
+ dev_err(&dc->pdev->dev, "size == 0?\n");
+ return 1;
+ }
+
+ tty_buffer_request_room(tty, size);
+
+ while (size > 0) {
+ read_mem32((u32 *) buf, addr + offset, RECEIVE_BUF_MAX);
+
+ if (size == 1) {
+ tty_insert_flip_char(tty, buf[0], TTY_NORMAL);
+ size = 0;
+ } else if (size < RECEIVE_BUF_MAX) {
+ size -= tty_insert_flip_string(tty, (char *) buf, size);
+ } else {
+ i = tty_insert_flip_string(tty, \
+ (char *) buf, RECEIVE_BUF_MAX);
+ size -= i;
+ offset += i;
+ }
+ }
+
+ set_bit(index, &dc->flip);
+
+ return 1;
+}
+
+/* Debug for interrupts */
+#ifdef DEBUG
+static char *interrupt2str(u16 interrupt)
+{
+ static char buf[TMP_BUF_MAX];
+ char *p = buf;
+
+ interrupt & MDM_DL1 ? p += snprintf(p, TMP_BUF_MAX, "MDM_DL1 ") : NULL;
+ interrupt & MDM_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_DL2 ") : NULL;
+
+ interrupt & MDM_UL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_UL1 ") : NULL;
+ interrupt & MDM_UL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "MDM_UL2 ") : NULL;
+
+ interrupt & DIAG_DL1 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_DL1 ") : NULL;
+ interrupt & DIAG_DL2 ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_DL2 ") : NULL;
+
+ interrupt & DIAG_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "DIAG_UL ") : NULL;
+
+ interrupt & APP1_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP1_DL ") : NULL;
+ interrupt & APP2_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP2_DL ") : NULL;
+
+ interrupt & APP1_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP1_UL ") : NULL;
+ interrupt & APP2_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "APP2_UL ") : NULL;
+
+ interrupt & CTRL_DL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "CTRL_DL ") : NULL;
+ interrupt & CTRL_UL ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "CTRL_UL ") : NULL;
+
+ interrupt & RESET ? p += snprintf(p, TMP_BUF_MAX - (p - buf),
+ "RESET ") : NULL;
+
+ return buf;
+}
+#endif
+
+/*
+ * Receive flow control
+ * Return 1 - If ok, else 0
+ */
+static int receive_flow_control(struct nozomi *dc)
+{
+ enum port_type port = PORT_MDM;
+ struct ctrl_dl ctrl_dl;
+ struct ctrl_dl old_ctrl;
+ u16 enable_ier = 0;
+
+ read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2);
+
+ switch (ctrl_dl.port) {
+ case CTRL_CMD:
+ DBG1("The Base Band sends this value as a response to a "
+ "request for IMSI detach sent over the control "
+ "channel uplink (see section 7.6.1).");
+ break;
+ case CTRL_MDM:
+ port = PORT_MDM;
+ enable_ier = MDM_DL;
+ break;
+ case CTRL_DIAG:
+ port = PORT_DIAG;
+ enable_ier = DIAG_DL;
+ break;
+ case CTRL_APP1:
+ port = PORT_APP1;
+ enable_ier = APP1_DL;
+ break;
+ case CTRL_APP2:
+ port = PORT_APP2;
+ enable_ier = APP2_DL;
+ break;
+ default:
+ dev_err(&dc->pdev->dev,
+ "ERROR: flow control received for non-existing port\n");
+ return 0;
+ };
+
+ DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl),
+ *((u16 *)&ctrl_dl));
+
+ old_ctrl = dc->port[port].ctrl_dl;
+ dc->port[port].ctrl_dl = ctrl_dl;
+
+ if (old_ctrl.CTS == 1 && ctrl_dl.CTS == 0) {
+ DBG1("Disable interrupt (0x%04X) on port: %d",
+ enable_ier, port);
+ disable_transmit_ul(port, dc);
+
+ } else if (old_ctrl.CTS == 0 && ctrl_dl.CTS == 1) {
+
+ if (__kfifo_len(dc->port[port].fifo_ul)) {
+ DBG1("Enable interrupt (0x%04X) on port: %d",
+ enable_ier, port);
+ DBG1("Data in buffer [%d], enable transmit! ",
+ __kfifo_len(dc->port[port].fifo_ul));
+ enable_transmit_ul(port, dc);
+ } else {
+ DBG1("No data in buffer...");
+ }
+ }
+
+ if (*(u16 *)&old_ctrl == *(u16 *)&ctrl_dl) {
+ DBG1(" No change in mctrl");
+ return 1;
+ }
+ /* Update statistics */
+ if (old_ctrl.CTS != ctrl_dl.CTS)
+ dc->port[port].tty_icount.cts++;
+ if (old_ctrl.DSR != ctrl_dl.DSR)
+ dc->port[port].tty_icount.dsr++;
+ if (old_ctrl.RI != ctrl_dl.RI)
+ dc->port[port].tty_icount.rng++;
+ if (old_ctrl.DCD != ctrl_dl.DCD)
+ dc->port[port].tty_icount.dcd++;
+
+ wake_up_interruptible(&dc->port[port].tty_wait);
+
+ DBG1("port: %d DCD(%d), CTS(%d), RI(%d), DSR(%d)",
+ port,
+ dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts,
+ dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr);
+
+ return 1;
+}
+
+static enum ctrl_port_type port2ctrl(enum port_type port,
+ const struct nozomi *dc)
+{
+ switch (port) {
+ case PORT_MDM:
+ return CTRL_MDM;
+ case PORT_DIAG:
+ return CTRL_DIAG;
+ case PORT_APP1:
+ return CTRL_APP1;
+ case PORT_APP2:
+ return CTRL_APP2;
+ default:
+ dev_err(&dc->pdev->dev,
+ "ERROR: send flow control " \
+ "received for non-existing port\n");
+ };
+ return CTRL_ERROR;
+}
+
+/*
+ * Send flow control, can only update one channel at a time
+ * Return 0 - If we have updated all flow control
+ * Return 1 - If we need to update more flow control, ack current enable more
+ */
+static int send_flow_control(struct nozomi *dc)
+{
+ u32 i, more_flow_control_to_be_updated = 0;
+ u16 *ctrl;
+
+ for (i = PORT_MDM; i < MAX_PORT; i++) {
+ if (dc->port[i].update_flow_control) {
+ if (more_flow_control_to_be_updated) {
+ /* We have more flow control to be updated */
+ return 1;
+ }
+ dc->port[i].ctrl_ul.port = port2ctrl(i, dc);
+ ctrl = (u16 *)&dc->port[i].ctrl_ul;
+ write_mem32(dc->port[PORT_CTRL].ul_addr[0], \
+ (u32 *) ctrl, 2);
+ dc->port[i].update_flow_control = 0;
+ more_flow_control_to_be_updated = 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * Handle downlink data, ports that are handled are modem and diagnostics
+ * Return 1 - ok
+ * Return 0 - toggle fields are out of sync
+ */
+static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle,
+ u16 read_iir, u16 mask1, u16 mask2)
+{
+ if (*toggle == 0 && read_iir & mask1) {
+ if (receive_data(port, dc)) {
+ writew(mask1, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+
+ if (read_iir & mask2) {
+ if (receive_data(port, dc)) {
+ writew(mask2, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+ }
+ } else if (*toggle == 1 && read_iir & mask2) {
+ if (receive_data(port, dc)) {
+ writew(mask2, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+
+ if (read_iir & mask1) {
+ if (receive_data(port, dc)) {
+ writew(mask1, dc->reg_fcr);
+ *toggle = !(*toggle);
+ }
+ }
+ } else {
+ dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n",
+ *toggle);
+ return 0;
+ }
+ return 1;
+}
+
+/*
+ * Handle uplink data, this is currently for the modem port
+ * Return 1 - ok
+ * Return 0 - toggle field are out of sync
+ */
+static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir)
+{
+ u8 *toggle = &(dc->port[port].toggle_ul);
+
+ if (*toggle == 0 && read_iir & MDM_UL1) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL1, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+
+ if (read_iir & MDM_UL2) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL2, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+ }
+
+ } else if (*toggle == 1 && read_iir & MDM_UL2) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL2, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+
+ if (read_iir & MDM_UL1) {
+ dc->last_ier &= ~MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(port, dc)) {
+ writew(MDM_UL1, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | MDM_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ *toggle = !*toggle;
+ }
+ }
+ } else {
+ writew(read_iir & MDM_UL, dc->reg_fcr);
+ dev_err(&dc->pdev->dev, "port out of sync!\n");
+ return 0;
+ }
+ return 1;
+}
+
+static irqreturn_t interrupt_handler(int irq, void *dev_id)
+{
+ struct nozomi *dc = dev_id;
+ unsigned int a;
+ u16 read_iir;
+
+ if (!dc)
+ return IRQ_NONE;
+
+ spin_lock(&dc->spin_mutex);
+ read_iir = readw(dc->reg_iir);
+
+ /* Card removed */
+ if (read_iir == (u16)-1)
+ goto none;
+ /*
+ * Just handle interrupt enabled in IER
+ * (by masking with dc->last_ier)
+ */
+ read_iir &= dc->last_ier;
+
+ if (read_iir == 0)
+ goto none;
+
+
+ DBG4("%s irq:0x%04X, prev:0x%04X", interrupt2str(read_iir), read_iir,
+ dc->last_ier);
+
+ if (read_iir & RESET) {
+ if (unlikely(!nozomi_read_config_table(dc))) {
+ dc->last_ier = 0x0;
+ writew(dc->last_ier, dc->reg_ier);
+ dev_err(&dc->pdev->dev, "Could not read status from "
+ "card, we should disable interface\n");
+ } else {
+ writew(RESET, dc->reg_fcr);
+ }
+ /* No more useful info if this was the reset interrupt. */
+ goto exit_handler;
+ }
+ if (read_iir & CTRL_UL) {
+ DBG1("CTRL_UL");
+ dc->last_ier &= ~CTRL_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_flow_control(dc)) {
+ writew(CTRL_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | CTRL_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & CTRL_DL) {
+ receive_flow_control(dc);
+ writew(CTRL_DL, dc->reg_fcr);
+ }
+ if (read_iir & MDM_DL) {
+ if (!handle_data_dl(dc, PORT_MDM,
+ &(dc->port[PORT_MDM].toggle_dl), read_iir,
+ MDM_DL1, MDM_DL2)) {
+ dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & MDM_UL) {
+ if (!handle_data_ul(dc, PORT_MDM, read_iir)) {
+ dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & DIAG_DL) {
+ if (!handle_data_dl(dc, PORT_DIAG,
+ &(dc->port[PORT_DIAG].toggle_dl), read_iir,
+ DIAG_DL1, DIAG_DL2)) {
+ dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n");
+ goto exit_handler;
+ }
+ }
+ if (read_iir & DIAG_UL) {
+ dc->last_ier &= ~DIAG_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_DIAG, dc)) {
+ writew(DIAG_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | DIAG_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & APP1_DL) {
+ if (receive_data(PORT_APP1, dc))
+ writew(APP1_DL, dc->reg_fcr);
+ }
+ if (read_iir & APP1_UL) {
+ dc->last_ier &= ~APP1_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_APP1, dc)) {
+ writew(APP1_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | APP1_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+ if (read_iir & APP2_DL) {
+ if (receive_data(PORT_APP2, dc))
+ writew(APP2_DL, dc->reg_fcr);
+ }
+ if (read_iir & APP2_UL) {
+ dc->last_ier &= ~APP2_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ if (send_data(PORT_APP2, dc)) {
+ writew(APP2_UL, dc->reg_fcr);
+ dc->last_ier = dc->last_ier | APP2_UL;
+ writew(dc->last_ier, dc->reg_ier);
+ }
+ }
+
+exit_handler:
+ spin_unlock(&dc->spin_mutex);
+ for (a = 0; a < NOZOMI_MAX_PORTS; a++)
+ if (test_and_clear_bit(a, &dc->flip))
+ tty_flip_buffer_push(dc->port[a].tty);
+ return IRQ_HANDLED;
+none:
+ spin_unlock(&dc->spin_mutex);
+ return IRQ_NONE;
+}
+
+static void nozomi_get_card_type(struct nozomi *dc)
+{
+ int i;
+ u32 size = 0;
+
+ for (i = 0; i < 6; i++)
+ size += pci_resource_len(dc->pdev, i);
+
+ /* Assume card type F32_8 if no match */
+ dc->card_type = size == 2048 ? F32_2 : F32_8;
+
+ dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type);
+}
+
+static void nozomi_setup_private_data(struct nozomi *dc)
+{
+ void __iomem *offset = dc->base_addr + dc->card_type / 2;
+ unsigned int i;
+
+ dc->reg_fcr = (void __iomem *)(offset + R_FCR);
+ dc->reg_iir = (void __iomem *)(offset + R_IIR);
+ dc->reg_ier = (void __iomem *)(offset + R_IER);
+ dc->last_ier = 0;
+ dc->flip = 0;
+
+ dc->port[PORT_MDM].token_dl = MDM_DL;
+ dc->port[PORT_DIAG].token_dl = DIAG_DL;
+ dc->port[PORT_APP1].token_dl = APP1_DL;
+ dc->port[PORT_APP2].token_dl = APP2_DL;
+
+ for (i = 0; i < MAX_PORT; i++)
+ init_waitqueue_head(&dc->port[i].tty_wait);
+}
+
+static ssize_t card_type_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+
+ return sprintf(buf, "%d\n", dc->card_type);
+}
+static DEVICE_ATTR(card_type, S_IRUGO, card_type_show, NULL);
+
+static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct nozomi *dc = pci_get_drvdata(to_pci_dev(dev));
+
+ return sprintf(buf, "%u\n", dc->open_ttys);
+}
+static DEVICE_ATTR(open_ttys, S_IRUGO, open_ttys_show, NULL);
+
+static void make_sysfs_files(struct nozomi *dc)
+{
+ if (device_create_file(&dc->pdev->dev, &dev_attr_card_type))
+ dev_err(&dc->pdev->dev,
+ "Could not create sysfs file for card_type\n");
+ if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys))
+ dev_err(&dc->pdev->dev,
+ "Could not create sysfs file for open_ttys\n");
+}
+
+static void remove_sysfs_files(struct nozomi *dc)
+{
+ device_remove_file(&dc->pdev->dev, &dev_attr_card_type);
+ device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys);
+}
+
+/* Allocate memory for one device */
+static int __devinit nozomi_card_init(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ resource_size_t start;
+ int ret;
+ struct nozomi *dc = NULL;
+ int ndev_idx;
+ int i;
+
+ dev_dbg(&pdev->dev, "Init, new card found\n");
+
+ for (ndev_idx = 0; ndev_idx < ARRAY_SIZE(ndevs); ndev_idx++)
+ if (!ndevs[ndev_idx])
+ break;
+
+ if (ndev_idx >= ARRAY_SIZE(ndevs)) {
+ dev_err(&pdev->dev, "no free tty range for this card left\n");
+ ret = -EIO;
+ goto err;
+ }
+
+ dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL);
+ if (unlikely(!dc)) {
+ dev_err(&pdev->dev, "Could not allocate memory\n");
+ ret = -ENOMEM;
+ goto err_free;
+ }
+
+ dc->pdev = pdev;
+
+ /* Find out what card type it is */
+ nozomi_get_card_type(dc);
+
+ ret = pci_enable_device(dc->pdev);
+ if (ret) {
+ dev_err(&pdev->dev, "Failed to enable PCI Device\n");
+ goto err_free;
+ }
+
+ start = pci_resource_start(dc->pdev, 0);
+ if (start == 0) {
+ dev_err(&pdev->dev, "No I/O address for card detected\n");
+ ret = -ENODEV;
+ goto err_disable_device;
+ }
+
+ ret = pci_request_regions(dc->pdev, NOZOMI_NAME);
+ if (ret) {
+ dev_err(&pdev->dev, "I/O address 0x%04x already in use\n",
+ (int) /* nozomi_private.io_addr */ 0);
+ goto err_disable_device;
+ }
+
+ dc->base_addr = ioremap(start, dc->card_type);
+ if (!dc->base_addr) {
+ dev_err(&pdev->dev, "Unable to map card MMIO\n");
+ ret = -ENODEV;
+ goto err_rel_regs;
+ }
+
+ dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL);
+ if (!dc->send_buf) {
+ dev_err(&pdev->dev, "Could not allocate send buffer?\n");
+ ret = -ENOMEM;
+ goto err_free_sbuf;
+ }
+
+ spin_lock_init(&dc->spin_mutex);
+
+ nozomi_setup_private_data(dc);
+
+ /* Disable all interrupts */
+ dc->last_ier = 0;
+ writew(dc->last_ier, dc->reg_ier);
+
+ ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED,
+ NOZOMI_NAME, dc);
+ if (unlikely(ret)) {
+ dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
+ goto err_free_sbuf;
+ }
+
+ DBG1("base_addr: %p", dc->base_addr);
+
+ make_sysfs_files(dc);
+
+ dc->index_start = ndev_idx * MAX_PORT;
+ ndevs[ndev_idx] = dc;
+
+ for (i = 0; i < MAX_PORT; i++) {
+ mutex_init(&dc->port[i].tty_sem);
+ dc->port[i].tty_open_count = 0;
+ dc->port[i].tty = NULL;
+ tty_register_device(ntty_driver, dc->index_start + i,
+ &pdev->dev);
+ }
+
+ /* Enable RESET interrupt. */
+ dc->last_ier = RESET;
+ writew(dc->last_ier, dc->reg_ier);
+
+ pci_set_drvdata(pdev, dc);
+
+ return 0;
+
+err_free_sbuf:
+ kfree(dc->send_buf);
+ iounmap(dc->base_addr);
+err_rel_regs:
+ pci_release_regions(pdev);
+err_disable_device:
+ pci_disable_device(pdev);
+err_free:
+ kfree(dc);
+err:
+ return ret;
+}
+
+static void __devexit tty_exit(struct nozomi *dc)
+{
+ unsigned int i;
+
+ DBG1(" ");
+
+ flush_scheduled_work();
+
+ for (i = 0; i < MAX_PORT; ++i)
+ if (dc->port[i].tty && \
+ list_empty(&dc->port[i].tty->hangup_work.entry))
+ tty_hangup(dc->port[i].tty);
+
+ while (dc->open_ttys)
+ msleep(1);
+
+ for (i = dc->index_start; i < dc->index_start + MAX_PORT; ++i)
+ tty_unregister_device(ntty_driver, i);
+}
+
+/* Deallocate memory for one device */
+static void __devexit nozomi_card_exit(struct pci_dev *pdev)
+{
+ int i;
+ struct ctrl_ul ctrl;
+ struct nozomi *dc = pci_get_drvdata(pdev);
+
+ /* Disable all interrupts */
+ dc->last_ier = 0;
+ writew(dc->last_ier, dc->reg_ier);
+
+ tty_exit(dc);
+
+ /* Send 0x0001, command card to resend the reset token. */
+ /* This is to get the reset when the module is reloaded. */
+ ctrl.port = 0x00;
+ ctrl.reserved = 0;
+ ctrl.RTS = 0;
+ ctrl.DTR = 1;
+ DBG1("sending flow control 0x%04X", *((u16 *)&ctrl));
+
+ /* Setup dc->reg addresses to we can use defines here */
+ write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2);
+ writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */
+
+ remove_sysfs_files(dc);
+
+ free_irq(pdev->irq, dc);
+
+ for (i = 0; i < MAX_PORT; i++)
+ if (dc->port[i].fifo_ul)
+ kfifo_free(dc->port[i].fifo_ul);
+
+ kfree(dc->send_buf);
+
+ iounmap(dc->base_addr);
+
+ pci_release_regions(pdev);
+
+ pci_disable_device(pdev);
+
+ ndevs[dc->index_start / MAX_PORT] = NULL;
+
+ kfree(dc);
+}
+
+static void set_rts(const struct tty_struct *tty, int rts)
+{
+ struct port *port = get_port_by_tty(tty);
+
+ port->ctrl_ul.RTS = rts;
+ port->update_flow_control = 1;
+ enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
+}
+
+static void set_dtr(const struct tty_struct *tty, int dtr)
+{
+ struct port *port = get_port_by_tty(tty);
+
+ DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr);
+
+ port->ctrl_ul.DTR = dtr;
+ port->update_flow_control = 1;
+ enable_transmit_ul(PORT_CTRL, get_dc_by_tty(tty));
+}
+
+/*
+ * ----------------------------------------------------------------------------
+ * TTY code
+ * ----------------------------------------------------------------------------
+ */
+
+/* Called when the userspace process opens the tty, /dev/noz*. */
+static int ntty_open(struct tty_struct *tty, struct file *file)
+{
+ struct port *port = get_port_by_tty(tty);
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ if (!port || !dc)
+ return -ENODEV;
+
+ if (mutex_lock_interruptible(&port->tty_sem))
+ return -ERESTARTSYS;
+
+ port->tty_open_count++;
+ dc->open_ttys++;
+
+ /* Enable interrupt downlink for channel */
+ if (port->tty_open_count == 1) {
+ tty->low_latency = 1;
+ tty->driver_data = port;
+ port->tty = tty;
+ DBG1("open: %d", port->token_dl);
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ dc->last_ier = dc->last_ier | port->token_dl;
+ writew(dc->last_ier, dc->reg_ier);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+ }
+
+ mutex_unlock(&port->tty_sem);
+
+ return 0;
+}
+
+/* Called when the userspace process close the tty, /dev/noz*. */
+static void ntty_close(struct tty_struct *tty, struct file *file)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ struct port *port = tty->driver_data;
+ unsigned long flags;
+
+ if (!dc || !port)
+ return;
+
+ if (mutex_lock_interruptible(&port->tty_sem))
+ return;
+
+ if (!port->tty_open_count)
+ goto exit;
+
+ dc->open_ttys--;
+ port->tty_open_count--;
+
+ if (port->tty_open_count == 0) {
+ DBG1("close: %d", port->token_dl);
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ dc->last_ier &= ~(port->token_dl);
+ writew(dc->last_ier, dc->reg_ier);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+ }
+
+exit:
+ mutex_unlock(&port->tty_sem);
+}
+
+/*
+ * called when the userspace process writes to the tty (/dev/noz*).
+ * Data is inserted into a fifo, which is then read and transfered to the modem.
+ */
+static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
+ int count)
+{
+ int rval = -EINVAL;
+ struct nozomi *dc = get_dc_by_tty(tty);
+ struct port *port = tty->driver_data;
+ unsigned long flags;
+
+ /* DBG1( "WRITEx: %d, index = %d", count, index); */
+
+ if (!dc || !port)
+ return -ENODEV;
+
+ if (unlikely(!mutex_trylock(&port->tty_sem))) {
+ /*
+ * must test lock as tty layer wraps calls
+ * to this function with BKL
+ */
+ dev_err(&dc->pdev->dev, "Would have deadlocked - "
+ "return EAGAIN\n");
+ return -EAGAIN;
+ }
+
+ if (unlikely(!port->tty_open_count)) {
+ DBG1(" ");
+ goto exit;
+ }
+
+ rval = __kfifo_put(port->fifo_ul, (unsigned char *)buffer, count);
+
+ /* notify card */
+ if (unlikely(dc == NULL)) {
+ DBG1("No device context?");
+ goto exit;
+ }
+
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ /* CTS is only valid on the modem channel */
+ if (port == &(dc->port[PORT_MDM])) {
+ if (port->ctrl_dl.CTS) {
+ DBG4("Enable interrupt");
+ enable_transmit_ul(tty->index % MAX_PORT, dc);
+ } else {
+ dev_err(&dc->pdev->dev,
+ "CTS not active on modem port?\n");
+ }
+ } else {
+ enable_transmit_ul(tty->index % MAX_PORT, dc);
+ }
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+
+exit:
+ mutex_unlock(&port->tty_sem);
+ return rval;
+}
+
+/*
+ * Calculate how much is left in device
+ * This method is called by the upper tty layer.
+ * #according to sources N_TTY.c it expects a value >= 0 and
+ * does not check for negative values.
+ */
+static int ntty_write_room(struct tty_struct *tty)
+{
+ struct port *port = tty->driver_data;
+ int room = 0;
+ struct nozomi *dc = get_dc_by_tty(tty);
+
+ if (!dc || !port)
+ return 0;
+ if (!mutex_trylock(&port->tty_sem))
+ return 0;
+
+ if (!port->tty_open_count)
+ goto exit;
+
+ room = port->fifo_ul->size - __kfifo_len(port->fifo_ul);
+
+exit:
+ mutex_unlock(&port->tty_sem);
+ return room;
+}
+
+/* Gets io control parameters */
+static int ntty_tiocmget(struct tty_struct *tty, struct file *file)
+{
+ struct port *port = tty->driver_data;
+ struct ctrl_dl *ctrl_dl = &port->ctrl_dl;
+ struct ctrl_ul *ctrl_ul = &port->ctrl_ul;
+
+ return (ctrl_ul->RTS ? TIOCM_RTS : 0) |
+ (ctrl_ul->DTR ? TIOCM_DTR : 0) |
+ (ctrl_dl->DCD ? TIOCM_CAR : 0) |
+ (ctrl_dl->RI ? TIOCM_RNG : 0) |
+ (ctrl_dl->DSR ? TIOCM_DSR : 0) |
+ (ctrl_dl->CTS ? TIOCM_CTS : 0);
+}
+
+/* Sets io controls parameters */
+static int ntty_tiocmset(struct tty_struct *tty, struct file *file,
+ unsigned int set, unsigned int clear)
+{
+ if (set & TIOCM_RTS)
+ set_rts(tty, 1);
+ else if (clear & TIOCM_RTS)
+ set_rts(tty, 0);
+
+ if (set & TIOCM_DTR)
+ set_dtr(tty, 1);
+ else if (clear & TIOCM_DTR)
+ set_dtr(tty, 0);
+
+ return 0;
+}
+
+static int ntty_cflags_changed(struct port *port, unsigned long flags,
+ struct async_icount *cprev)
+{
+ struct async_icount cnow = port->tty_icount;
+ int ret;
+
+ ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
+ ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
+ ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
+ ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts));
+
+ *cprev = cnow;
+
+ return ret;
+}
+
+static int ntty_ioctl_tiocgicount(struct port *port, void __user *argp)
+{
+ struct async_icount cnow = port->tty_icount;
+ struct serial_icounter_struct icount;
+
+ icount.cts = cnow.cts;
+ icount.dsr = cnow.dsr;
+ icount.rng = cnow.rng;
+ icount.dcd = cnow.dcd;
+ icount.rx = cnow.rx;
+ icount.tx = cnow.tx;
+ icount.frame = cnow.frame;
+ icount.overrun = cnow.overrun;
+ icount.parity = cnow.parity;
+ icount.brk = cnow.brk;
+ icount.buf_overrun = cnow.buf_overrun;
+
+ return copy_to_user(argp, &icount, sizeof(icount));
+}
+
+static int ntty_ioctl(struct tty_struct *tty, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct port *port = tty->driver_data;
+ void __user *argp = (void __user *)arg;
+ int rval = -ENOIOCTLCMD;
+
+ DBG1("******** IOCTL, cmd: %d", cmd);
+
+ switch (cmd) {
+ case TIOCMIWAIT: {
+ struct async_icount cprev = port->tty_icount;
+
+ rval = wait_event_interruptible(port->tty_wait,
+ ntty_cflags_changed(port, arg, &cprev));
+ break;
+ } case TIOCGICOUNT:
+ rval = ntty_ioctl_tiocgicount(port, argp);
+ break;
+ default:
+ DBG1("ERR: 0x%08X, %d", cmd, cmd);
+ break;
+ };
+
+ return rval;
+}
+
+/*
+ * Called by the upper tty layer when tty buffers are ready
+ * to receive data again after a call to throttle.
+ */
+static void ntty_unthrottle(struct tty_struct *tty)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ DBG1("UNTHROTTLE");
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ enable_transmit_dl(tty->index % MAX_PORT, dc);
+ set_rts(tty, 1);
+
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+}
+
+/*
+ * Called by the upper tty layer when the tty buffers are almost full.
+ * The driver should stop send more data.
+ */
+static void ntty_throttle(struct tty_struct *tty)
+{
+ struct nozomi *dc = get_dc_by_tty(tty);
+ unsigned long flags;
+
+ DBG1("THROTTLE");
+ spin_lock_irqsave(&dc->spin_mutex, flags);
+ set_rts(tty, 0);
+ spin_unlock_irqrestore(&dc->spin_mutex, flags);
+}
+
+/* just to discard single character writes */
+static void ntty_put_char(struct tty_struct *tty, unsigned char c)
+{
+ /*
+ * card does not react correct when we write single chars
+ * to the card, so we discard them
+ */
+ DBG2("PUT CHAR Function: %c", c);
+}
+
+/* Returns number of chars in buffer, called by tty layer */
+static s32 ntty_chars_in_buffer(struct tty_struct *tty)
+{
+ struct port *port = tty->driver_data;
+ struct nozomi *dc = get_dc_by_tty(tty);
+ s32 rval;
+
+ if (unlikely(!dc || !port)) {
+ rval = -ENODEV;
+ goto exit_in_buffer;
+ }
+
+ if (unlikely(!port->tty_open_count)) {
+ dev_err(&dc->pdev->dev, "No tty open?\n");
+ rval = -ENODEV;
+ goto exit_in_buffer;
+ }
+
+ rval = __kfifo_len(port->fifo_ul);
+
+exit_in_buffer:
+ return rval;
+}
+
+static struct tty_operations tty_ops = {
+ .ioctl = ntty_ioctl,
+ .open = ntty_open,
+ .close = ntty_close,
+ .write = ntty_write,
+ .write_room = ntty_write_room,
+ .unthrottle = ntty_unthrottle,
+ .throttle = ntty_throttle,
+ .chars_in_buffer = ntty_chars_in_buffer,
+ .put_char = ntty_put_char,
+ .tiocmget = ntty_tiocmget,
+ .tiocmset = ntty_tiocmset,
+};
+
+/* Module initialization */
+static struct pci_driver nozomi_driver = {
+ .name = NOZOMI_NAME,
+ .id_table = nozomi_pci_tbl,
+ .probe = nozomi_card_init,
+ .remove = __devexit_p(nozomi_card_exit),
+};
+
+static __init int nozomi_init(void)
+{
+ int ret;
+
+ printk(KERN_INFO "Initializing %s\n", VERSION_STRING);
+
+ ntty_driver = alloc_tty_driver(NTTY_TTY_MAXMINORS);
+ if (!ntty_driver)
+ return -ENOMEM;
+
+ ntty_driver->owner = THIS_MODULE;
+ ntty_driver->driver_name = NOZOMI_NAME_TTY;
+ ntty_driver->name = "noz";
+ ntty_driver->major = 0;
+ ntty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+ ntty_driver->subtype = SERIAL_TYPE_NORMAL;
+ ntty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+ ntty_driver->init_termios = tty_std_termios;
+ ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \
+ HUPCL | CLOCAL;
+ ntty_driver->init_termios.c_ispeed = 115200;
+ ntty_driver->init_termios.c_ospeed = 115200;
+ tty_set_operations(ntty_driver, &tty_ops);
+
+ ret = tty_register_driver(ntty_driver);
+ if (ret) {
+ printk(KERN_ERR "Nozomi: failed to register ntty driver\n");
+ goto free_tty;
+ }
+
+ ret = pci_register_driver(&nozomi_driver);
+ if (ret) {
+ printk(KERN_ERR "Nozomi: can't register pci driver\n");
+ goto unr_tty;
+ }
+
+ return 0;
+unr_tty:
+ tty_unregister_driver(ntty_driver);
+free_tty:
+ put_tty_driver(ntty_driver);
+ return ret;
+}
+
+static __exit void nozomi_exit(void)
+{
+ printk(KERN_INFO "Unloading %s\n", DRIVER_DESC);
+ pci_unregister_driver(&nozomi_driver);
+ tty_unregister_driver(ntty_driver);
+ put_tty_driver(ntty_driver);
+}
+
+module_init(nozomi_init);
+module_exit(nozomi_exit);
+
+module_param(debug, int, S_IRUGO | S_IWUSR);
+
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_DESCRIPTION(DRIVER_DESC);

2008-01-25 12:45:31

by Frank Seidel

[permalink] [raw]
Subject: Re: [PATCH 012/196] nozomi driver

Hi,

thanks for your feedback.

On Freitag 25 Januar 2008 09:31:25, you (Jan Engelhardt) wrote:
> On Jan 24 2008 23:09, Greg Kroah-Hartman wrote:
> >+/*
> >+ * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
> >+ *
> >+ * Written by: Ulf Jakobsson,
> >+ * Jan �erfeldt,
> ^
> Neither in ISO-8859-1 nor UTF-8 this position contains something meaningful.
> Mind to update to UTF-8?

fixed

> >+/*
> >+ * CHANGELOG
>
> Changelogs go into git, not files, at least that is what was mentioned
> time and again.

i removed them

> >+#ifdef __BIG_ENDIAN
> >+/* Big endian */
> >+
> >+struct toggles {
> >+ unsigned enabled:5; /*
> >+ * Toggle fields are valid if enabled is 0,
> >+ * else A-channels must always be used.
> >+ */
> >+ unsigned diag_dl:1;
> >+ unsigned mdm_dl:1;
> >+ unsigned mdm_ul:1;
> >+} __attribute__ ((packed));
>
> Probably just me, unsigned int is a good bit more explicit.
> The driver may also use a combined struct with
> BIG_ENDIAN_BITFIELD/LITTLE_ENDIAN_BIGFIELD (see e.g. linux/ip.h).

Here i agree with Stefan, especially as this also would only
make a difference for one (struct config_table) of those four structs
and there it would vastly decrease readability.

> >+/* Global variables */
> >+static struct pci_device_id nozomi_pci_tbl[] = {
> >+ {PCI_DEVICE(VENDOR1, DEVICE1)},
> >+ {},
> >+};
>
> The macros are only used once, could just as well substitute them
> by their real values.

Yes, but on the other hand now all those driver specific numbers
are grouped together in the beginning of nozomi.c and it also
could happen there once will appear other cards or models of it
that this nozomi driver could handle.

> >+/*
> >+ * Handle donlink data, ports that are handled are modem and diagnostics
> ^
> downlink

corrected

> >+static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
>
> While 0444 is probably never going to change its meaning, S_IRUGO comes
> into mind.

changed it to S_IRUGO

> >+/* just to discard single character writes */
> >+static void ntty_put_char(struct tty_struct *tty, unsigned char c)
> >+{
> >+ /* FIXME !!! */
> >+ DBG2("PUT CHAR Function: %c", c);
> >+}

Its just a misleading comment, but i changed it.

Besides that i also removed an error and a warning the current
checkpatch.pl now showed up ("trailing statments should be on next
line" and a "inline preferred over __inline-__").

Thanks,
Frank

2008-01-25 13:21:43

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [PATCH 012/196] nozomi driver


On Jan 25 2008 13:44, Frank Seidel wrote:
>> >+/*
>> >+ * CHANGELOG
>>
>> Changelogs go into git, not files, at least that is what was mentioned
>> time and again.
>
>i removed them
>
If you want to keep them, add it to the patch description; that way they will
be retained in "git log" without expanding the size of the .c file. :)

2008-01-25 14:56:16

by James Bottomley

[permalink] [raw]
Subject: Re: [PATCH 191/196] scsi: use class iteration api


On Thu, 2008-01-24 at 23:33 -0800, Greg Kroah-Hartman wrote:
> From: Dave Young <[email protected]>
>
> Convert to use the class iteration api.
>
> Signed-off-by: Dave Young <[email protected]>
> Cc: James Bottomley <[email protected]>

Acked-by James Bottomley <[email protected]>

> Signed-off-by: Greg Kroah-Hartman <[email protected]>

2008-01-25 16:19:53

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add

On Thu, 24 Jan 2008 23:32:17 -0800
Greg Kroah-Hartman <[email protected]> wrote:

> The kobject in the bridge code is only used for registering with sysfs,
> not for any lifespan rules. This patch changes it to be only a pointer
> and use the simpler api for this kind of thing.
>
> Cc: Stephen Hemminger <[email protected]>
> Cc: Kay Sievers <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> net/bridge/br_if.c | 2 +-
> net/bridge/br_private.h | 2 +-
> net/bridge/br_sysfs_br.c | 14 ++++----------
> net/bridge/br_sysfs_if.c | 2 +-
> 4 files changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index 935784f..dadec94 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)
> struct net_bridge *br = p->br;
> struct net_device *dev = p->dev;
>
> - sysfs_remove_link(&br->ifobj, dev->name);
> + sysfs_remove_link(br->ifobj, dev->name);
>
> dev_set_promiscuity(dev, -1);
>
> diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
> index f666f7b..c11b554 100644
> --- a/net/bridge/br_private.h
> +++ b/net/bridge/br_private.h
> @@ -124,7 +124,7 @@ struct net_bridge
> struct timer_list tcn_timer;
> struct timer_list topology_change_timer;
> struct timer_list gc_timer;
> - struct kobject ifobj;
> + struct kobject *ifobj;
> };
>
> extern struct notifier_block br_device_notifier;
> diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> index 3312e8f..4e7f91f 100644
> --- a/net/bridge/br_sysfs_br.c
> +++ b/net/bridge/br_sysfs_br.c
> @@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev)
> goto out2;
> }
>
> -
> - kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR);
> - br->ifobj.ktype = NULL;
> - br->ifobj.kset = NULL;
> - br->ifobj.parent = brobj;
> -
> - err = kobject_register(&br->ifobj);
> - if (err) {
> + br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
> + if (!br->ifobj) {
> pr_info("%s: can't add kobject (directory) %s/%s\n",
> - __FUNCTION__, dev->name, kobject_name(&br->ifobj));
> + __FUNCTION__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
> goto out3;
> }
> return 0;
> @@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)
> struct kobject *kobj = &dev->dev.kobj;
> struct net_bridge *br = netdev_priv(dev);
>
> - kobject_unregister(&br->ifobj);
> + kobject_unregister(br->ifobj);
> sysfs_remove_bin_file(kobj, &bridge_forward);
> sysfs_remove_group(kobj, &bridge_group);
> }
> diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
> index 79db51f..02b2d50 100644
> --- a/net/bridge/br_sysfs_if.c
> +++ b/net/bridge/br_sysfs_if.c
> @@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p)
> goto out2;
> }
>
> - err= sysfs_create_link(&br->ifobj, &p->kobj, p->dev->name);
> + err = sysfs_create_link(br->ifobj, &p->kobj, p->dev->name);
> out2:
> return err;
> }

Okay, but where is the new kobject freed?

--
Stephen Hemminger <[email protected]>

2008-01-25 16:20:47

by Stephen Hemminger

[permalink] [raw]
Subject: Re: [PATCH 136/196] Kobject: convert net/bridge/br_if.c to use kobject_init/add_ng()

On Thu, 24 Jan 2008 23:32:45 -0800
Greg Kroah-Hartman <[email protected]> wrote:

> This converts the code to use the new kobject functions, cleaning up the
> logic in doing so.
>
> Cc: Stephen Hemminger <[email protected]>
> Cc: Kay Sievers <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
> net/bridge/br_if.c | 10 +++-------
> 1 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index dadec94..298e0f4 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -258,12 +258,6 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
> p->state = BR_STATE_DISABLED;
> br_stp_port_timer_init(p);
>
> - kobject_init(&p->kobj);
> - kobject_set_name(&p->kobj, SYSFS_BRIDGE_PORT_ATTR);
> - p->kobj.ktype = &brport_ktype;
> - p->kobj.parent = &(dev->dev.kobj);
> - p->kobj.kset = NULL;
> -
> return p;
> }
>
> @@ -379,7 +373,8 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
> if (IS_ERR(p))
> return PTR_ERR(p);
>
> - err = kobject_add(&p->kobj);
> + err = kobject_init_and_add(&p->kobj, &brport_ktype, &(dev->dev.kobj),
> + SYSFS_BRIDGE_PORT_ATTR);
> if (err)
> goto err0;
>
> @@ -416,6 +411,7 @@ err2:
> br_fdb_delete_by_port(br, p, 1);
> err1:
> kobject_del(&p->kobj);
> + return err;
> err0:
> kobject_put(&p->kobj);
> return err;

This is fine, no issues.

--
Stephen Hemminger <[email protected]>

2008-01-25 17:02:43

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [PATCH 012/196] nozomi driver

On Fri, 25 Jan 2008 14:21:33 +0100, Jan Engelhardt said:
>
> On Jan 25 2008 13:44, Frank Seidel wrote:
> >> >+/*
> >> >+ * CHANGELOG
> >>
> >> Changelogs go into git, not files, at least that is what was mentioned
> >> time and again.
> >
> >i removed them
> >
> If you want to keep them, add it to the patch description; that way they will
> be retained in "git log" without expanding the size of the .c file. :)

By all means - if you have text that explains the who/what/why of the patch,
put it in the patch description, so that 6 months later idiots like me have
a fighting chance of figuring out whether the patch incorrectly implements
the right idea, or if it correctly implements the wrong idea. ;)


Attachments:
(No filename) (226.00 B)

2008-01-25 17:50:56

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add

On Fri, Jan 25, 2008 at 08:19:23AM -0800, Stephen Hemminger wrote:
> On Thu, 24 Jan 2008 23:32:17 -0800
> Greg Kroah-Hartman <[email protected]> wrote:
>
> > The kobject in the bridge code is only used for registering with sysfs,
> > not for any lifespan rules. This patch changes it to be only a pointer
> > and use the simpler api for this kind of thing.
> >
> > Cc: Stephen Hemminger <[email protected]>
> > Cc: Kay Sievers <[email protected]>
> > Signed-off-by: Greg Kroah-Hartman <[email protected]>
> > ---
> > net/bridge/br_if.c | 2 +-
> > net/bridge/br_private.h | 2 +-
> > net/bridge/br_sysfs_br.c | 14 ++++----------
> > net/bridge/br_sysfs_if.c | 2 +-
> > 4 files changed, 7 insertions(+), 13 deletions(-)
> >
> > diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> > index 935784f..dadec94 100644
> > --- a/net/bridge/br_if.c
> > +++ b/net/bridge/br_if.c
> > @@ -133,7 +133,7 @@ static void del_nbp(struct net_bridge_port *p)
> > struct net_bridge *br = p->br;
> > struct net_device *dev = p->dev;
> >
> > - sysfs_remove_link(&br->ifobj, dev->name);
> > + sysfs_remove_link(br->ifobj, dev->name);
> >
> > dev_set_promiscuity(dev, -1);
> >
> > diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
> > index f666f7b..c11b554 100644
> > --- a/net/bridge/br_private.h
> > +++ b/net/bridge/br_private.h
> > @@ -124,7 +124,7 @@ struct net_bridge
> > struct timer_list tcn_timer;
> > struct timer_list topology_change_timer;
> > struct timer_list gc_timer;
> > - struct kobject ifobj;
> > + struct kobject *ifobj;
> > };
> >
> > extern struct notifier_block br_device_notifier;
> > diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c
> > index 3312e8f..4e7f91f 100644
> > --- a/net/bridge/br_sysfs_br.c
> > +++ b/net/bridge/br_sysfs_br.c
> > @@ -426,16 +426,10 @@ int br_sysfs_addbr(struct net_device *dev)
> > goto out2;
> > }
> >
> > -
> > - kobject_set_name(&br->ifobj, SYSFS_BRIDGE_PORT_SUBDIR);
> > - br->ifobj.ktype = NULL;
> > - br->ifobj.kset = NULL;
> > - br->ifobj.parent = brobj;
> > -
> > - err = kobject_register(&br->ifobj);
> > - if (err) {
> > + br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
> > + if (!br->ifobj) {
> > pr_info("%s: can't add kobject (directory) %s/%s\n",
> > - __FUNCTION__, dev->name, kobject_name(&br->ifobj));
> > + __FUNCTION__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
> > goto out3;
> > }
> > return 0;
> > @@ -453,7 +447,7 @@ void br_sysfs_delbr(struct net_device *dev)
> > struct kobject *kobj = &dev->dev.kobj;
> > struct net_bridge *br = netdev_priv(dev);
> >
> > - kobject_unregister(&br->ifobj);
> > + kobject_unregister(br->ifobj);
> > sysfs_remove_bin_file(kobj, &bridge_forward);
> > sysfs_remove_group(kobj, &bridge_group);
> > }
> > diff --git a/net/bridge/br_sysfs_if.c b/net/bridge/br_sysfs_if.c
> > index 79db51f..02b2d50 100644
> > --- a/net/bridge/br_sysfs_if.c
> > +++ b/net/bridge/br_sysfs_if.c
> > @@ -229,7 +229,7 @@ int br_sysfs_addif(struct net_bridge_port *p)
> > goto out2;
> > }
> >
> > - err= sysfs_create_link(&br->ifobj, &p->kobj, p->dev->name);
> > + err = sysfs_create_link(br->ifobj, &p->kobj, p->dev->name);
> > out2:
> > return err;
> > }
>
> Okay, but where is the new kobject freed?

In the call to kobject_unregister(), which has then later in the series
been converted to a call to kobject_put().

thanks,

greg k-h

2008-01-25 17:51:22

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 085/196] kset: convert s390 ipl.c to use kset_create

On Fri, Jan 25, 2008 at 01:20:53PM +0100, Heiko Carstens wrote:
> On Thu, Jan 24, 2008 at 11:31:54PM -0800, Greg Kroah-Hartman wrote:
> > Dynamically create the kset instead of declaring it statically.
> > This makes the kobject attributes now work properly that I broke in the
> > previous patch.
>
> Could you please merge this and the previous patch before it goes
> upstream? Having an intermediate state where things are broken
> will cause pain and additional work in case of bisecting.

It will not cause a build error (see the previous patch for details.)
The sysfs files will not properly show the correct data, that is all.

The odds that you will hit this in a 'git bisect' is VERY low, and the
previous patch states that the files are now broken, so there should not
be any confusion regarding any user that might run across this.

thanks,

greg k-h

2008-01-25 17:52:41

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 044/196] kset: add kset_create_and_add function

On Fri, Jan 25, 2008 at 05:09:41PM +0800, Dave Young wrote:
> On Jan 25, 2008 3:09 PM, Greg Kroah-Hartman <[email protected]> wrote:
> > +/**
> > + * kset_create_and_add - create a struct kset dynamically and add it to sysfs
> > + *
> > + * @name: the name for the kset
> > + * @uevent_ops: a struct kset_uevent_ops for the kset
> > + * @parent_kobj: the parent kobject of this kset, if any.
> > + *
> > + * This function creates a kset structure dynamically and registers it
> > + * with sysfs. When you are finished with this structure, call
> > + * kset_unregister() and the structure will be dynamically freed when it
> > + * is no longer being used.
> > + *
> > + * If the kset was not able to be created, NULL will be returned.
> > + */
> > +struct kset *kset_create_and_add(const char *name,
> > + struct kset_uevent_ops *uevent_ops,
> > + struct kobject *parent_kobj)
> > +{
> > + struct kset *kset;
> > + int error;
> > +
> > + kset = kset_create(name, uevent_ops, parent_kobj);
> > + if (!kset)
> > + return NULL;
> > + error = kset_register(kset);
> > + if (error) {
> > + kfree(kset);
>
> How about : kobject_put(&kset->kobj);

At this point in the object's lifetime, it is the same exact thing.

So both are correct :)

thanks,

greg k-h

2008-01-25 17:55:57

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 076/196] ecryptfs: remove version_str file from sysfs

On Fri, Jan 25, 2008 at 03:25:22AM -0500, Jeff Garzik wrote:
> Greg Kroah-Hartman wrote:
>> This file violates the one-value-per-file sysfs rule.
>> If you all want it added back, please do something like a per-feature
>> file to show what is present and what isn't.
>> Cc: Kay Sievers <[email protected]>
>> Cc: Mike Halcrow <[email protected]>
>> Cc: Phillip Hellewell <[email protected]>
>> Signed-off-by: Greg Kroah-Hartman <[email protected]>
>> ---
>> fs/ecryptfs/main.c | 43 -------------------------------------------
>> 1 files changed, 0 insertions(+), 43 deletions(-)
>
> It's not really good policy to rip out ABIs found in release kernels like
> this, even if the motivation is sound.

Normally I would agree, but this file is just so bad, it's not even
funny. I could not find any userspace tools or documentation that used
it, and the ecryptfs developers never responded to any of my emails
concerning it.

The information is still present, just in a different file, so no
functionality is lost here.

> IMO "don't break ABIs" rule is far more important than a one-value-per-file
> sysfs rule.

Just another example of why people need to document this kind of thing
in Documentation/ABI/ which prevents such atrocities from ever being
created in the first place...

thanks,

greg k-h

2008-01-25 18:16:49

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH 067/196] kset: convert slub to use kset_create

On Thu, 24 Jan 2008, Greg Kroah-Hartman wrote:

> Dynamically create the kset instead of declaring it statically.

Cannot see anything wrong (but then sysfs is mainly a mystery to
me)

Acked-by: Christoph Lameter <[email protected]>

2008-01-25 18:17:24

by Christoph Lameter

[permalink] [raw]
Subject: Re: [PATCH 135/196] Kobject: convert mm/slub.c to use kobject_init/add_ng()

On Thu, 24 Jan 2008, Greg Kroah-Hartman wrote:

> This converts the code to use the new kobject functions, cleaning up the
> logic in doing so.

Acked-by: Christoph Lameter <[email protected]>

2008-01-25 18:45:22

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24



On Thu, 24 Jan 2008, Greg KH wrote:
>
> Here are a pretty large number of kobject, documentation, and driver
> core patches against your 2.6.24 git tree.

I've merged it all, but it causes lots of scary warnings:

- from the purely broken ones:

ehci_hcd: no version for "struct_module" found: kernel tainted.

- to the scary ones:

sysfs: duplicate filename 'ehci_hcd' can not be created
WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
Pid: 610, comm: insmod Tainted: GF 2.6.24-gb47711bf #28

Call Trace:
[<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
[<ffffffff802bdbc0>] create_dir+0x4f/0x87
[<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
[<ffffffff803154c8>] kobject_get+0x12/0x17
[<ffffffff80315607>] kobject_add_internal+0xd9/0x194
[<ffffffff8031579c>] kobject_add_varg+0x54/0x61
[<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
[<ffffffff80315321>] kobject_init+0x42/0x82
[<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
[<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
[<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
[<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
[<ffffffff8028ebd5>] dput+0x1c/0x10b
[<ffffffff8020b3be>] system_call+0x7e/0x83

and the problem seems to be that it does all these checks even for modules
that will never be loaded, because I use my own kernel, but with the
default Fedora initrd (which is trying to load modules for stuff that I
already have built in).

Very annoying.

Can we please do that *after* the module loading symbol checks have run,
so that when you try to load a module that will not load, it won't
complain about these silly things?

(You can probably trigger this by simply trying to load a module that was
compiled for another kernel version - it will fail fine, but in failing it
will then generate all these incorrect warnings!)

Now it incorrectly taints my kernel, for no good reason.

Linus

2008-01-25 18:53:49

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, Jan 25, 2008 at 10:44:59AM -0800, Linus Torvalds wrote:
>
>
> On Thu, 24 Jan 2008, Greg KH wrote:
> >
> > Here are a pretty large number of kobject, documentation, and driver
> > core patches against your 2.6.24 git tree.
>
> I've merged it all, but it causes lots of scary warnings:
>
> - from the purely broken ones:
>
> ehci_hcd: no version for "struct_module" found: kernel tainted.
>
> - to the scary ones:
>
> sysfs: duplicate filename 'ehci_hcd' can not be created
> WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
> Pid: 610, comm: insmod Tainted: GF 2.6.24-gb47711bf #28
>
> Call Trace:
> [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
> [<ffffffff802bdbc0>] create_dir+0x4f/0x87
> [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
> [<ffffffff803154c8>] kobject_get+0x12/0x17
> [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
> [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
> [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
> [<ffffffff80315321>] kobject_init+0x42/0x82
> [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
> [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
> [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
> [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
> [<ffffffff8028ebd5>] dput+0x1c/0x10b
> [<ffffffff8020b3be>] system_call+0x7e/0x83
>
> and the problem seems to be that it does all these checks even for modules
> that will never be loaded, because I use my own kernel, but with the
> default Fedora initrd (which is trying to load modules for stuff that I
> already have built in).
>
> Very annoying.

That's really wierd, I don't see that at all here just running with your
2.6.24 + my git tree and lots of USB drivers built into the kernel also
(like ehci_hcd).

I'll try to reproduce it on your merged git tree now...

> Can we please do that *after* the module loading symbol checks have run,
> so that when you try to load a module that will not load, it won't
> complain about these silly things?
>
> (You can probably trigger this by simply trying to load a module that was
> compiled for another kernel version - it will fail fine, but in failing it
> will then generate all these incorrect warnings!)
>
> Now it incorrectly taints my kernel, for no good reason.

$ cat /proc/sys/kernel/tainted
0

Odd...

$ uname -r
2.6.24-ge374a2bf-dirty

Strange, I thought that the uname id would show the git version that you
were running, but that doesn't show a valid id. But that's probably a
different issue in the build system somewhere...

thanks,

greg k-h

2008-01-25 18:57:25

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

On Fri, Jan 25, 2008 at 01:44:23PM +0100, Frank Seidel wrote:
> From: Frank Seidel <[email protected]>
>
> This is a driver to control the cardbus wireless data card that works on
> 3g networks.

<snip>

Frank, can you send me a patch against Linus's current git tree that had
the last version of this driver included in it?

That way I can actually apply the changes :)

thanks,

greg k-h

2008-01-25 19:12:07

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24



On Fri, 25 Jan 2008, Greg KH wrote:
>
> That's really wierd, I don't see that at all here just running with your
> 2.6.24 + my git tree and lots of USB drivers built into the kernel also
> (like ehci_hcd).

But do you use an initrd that tries to load the same driver too?

I'm too lazy to want to do my own initrd. I just use the prepackaged ones
and rely on the fact that my private kernel will refuse to load modules
that aren't meant for it anyway.

> $ cat /proc/sys/kernel/tainted
> 0

Mine says "2".

> $ uname -r
> 2.6.24-ge374a2bf-dirty
>
> Strange, I thought that the uname id would show the git version that you
> were running, but that doesn't show a valid id. But that's probably a
> different issue in the build system somewhere...

That *is* the git version you're running: e374a2bf.

The "-g" is for "git" and the "-dirty" is because you have some
non-checked-in changes in addition.

I works for me:

[torvalds@hp linux]$ git show --abbrev-commit -s --pretty=oneline e374a2bf
e374a2b... Kobject: fix coding style issues in kobject c files

so that looks like a valid version..

Linus

2008-01-25 19:18:20

by Michael Halcrow

[permalink] [raw]
Subject: Re: [PATCH 076/196] ecryptfs: remove version_str file from sysfs

On Fri, Jan 25, 2008 at 09:54:21AM -0800, Greg KH wrote:
> I could not find any userspace tools or documentation that used it

The version_str handle is only there as a potential convenience for
users who need to figure out what their module can and cannot do. I
mentioned it in an article in LJ last year. It does not need to be
there for any tools to work right, and I do not think that anyone
really cares about it at this point, so I have no problem with just
ripping it out.

Mike

2008-01-25 19:18:55

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, Jan 25, 2008 at 11:11:48AM -0800, Linus Torvalds wrote:
>
>
> On Fri, 25 Jan 2008, Greg KH wrote:
> >
> > That's really wierd, I don't see that at all here just running with your
> > 2.6.24 + my git tree and lots of USB drivers built into the kernel also
> > (like ehci_hcd).
>
> But do you use an initrd that tries to load the same driver too?
>
> I'm too lazy to want to do my own initrd. I just use the prepackaged ones
> and rely on the fact that my private kernel will refuse to load modules
> that aren't meant for it anyway.

No, I don't use any initrd at all.

You should just get a message saying that the version magic doesn't
match, so the initrd modules will not load. That's what happens to me
when I try to force old modules to load.

> > $ cat /proc/sys/kernel/tainted
> > 0
>
> Mine says "2".
>
> > $ uname -r
> > 2.6.24-ge374a2bf-dirty
> >
> > Strange, I thought that the uname id would show the git version that you
> > were running, but that doesn't show a valid id. But that's probably a
> > different issue in the build system somewhere...
>
> That *is* the git version you're running: e374a2bf.
>
> The "-g" is for "git" and the "-dirty" is because you have some
> non-checked-in changes in addition.
>
> I works for me:
>
> [torvalds@hp linux]$ git show --abbrev-commit -s --pretty=oneline e374a2bf
> e374a2b... Kobject: fix coding style issues in kobject c files
>
> so that looks like a valid version..

Ah taking the "g" off the search works, didn't realize that.

And I didn't have any unchecked in files, 'git status' shows no modified
files, but other stuff in the main directory, like patches that
shouldn't matter, but perhaps they do.
But oh well, I'm still building your tree now to try to reproduce
this...

thanks,

greg k-h

2008-01-25 19:23:50

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, Jan 25, 2008 at 11:11:48AM -0800, Linus Torvalds wrote:
>
>
> On Fri, 25 Jan 2008, Greg KH wrote:
> >
> > That's really wierd, I don't see that at all here just running with your
> > 2.6.24 + my git tree and lots of USB drivers built into the kernel also
> > (like ehci_hcd).
>
> But do you use an initrd that tries to load the same driver too?

Ah, now I get it, sorry, I'll go check that error path, not exactly a
normal one :)

thanks,

greg k-h

2008-01-25 19:34:04

by Frank Seidel

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

On Friday 25 January 2008 19:55, Greg KH wrote:
> Frank, can you send me a patch against Linus's current git tree that had
> the last version of this driver included in it?
>
> That way I can actually apply the changes :)

Sure :-) This one is rebased on the current state in git.

Thanks,
Frank
---
drivers/char/nozomi.c | 122 ++++++++++++++------------------------------------
1 file changed, 36 insertions(+), 86 deletions(-)

--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -2,7 +2,7 @@
* nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
*
* Written by: Ulf Jakobsson,
- * Jan �erfeldt,
+ * Jan Åkerfeldt,
* Stefan Thomasson,
*
* Maintained by: Paul Hardwick ([email protected])
@@ -38,60 +38,6 @@
* --------------------------------------------------------------------------
*/

-/*
- * CHANGELOG
- * Version 2.1d
- * 11-November-2007 Jiri Slaby, Frank Seidel
- * - Big rework of multicard support by Jiri
- * - Major cleanups (semaphore to mutex, endianess, no major reservation)
- * - Optimizations
- *
- * Version 2.1c
- * 30-October-2007 Frank Seidel
- * - Completed multicard support
- * - Minor cleanups
- *
- * Version 2.1b
- * 07-August-2007 Frank Seidel
- * - Minor cleanups
- * - theoretical multicard support
- *
- * Version 2.1
- * 03-July-2006 Paul Hardwick
- *
- * - Stability Improvements. Incorporated spinlock wraps patch.
- * - Updated for newer 2.6.14+ kernels (tty_buffer_request_room)
- * - using __devexit macro for tty
- *
- *
- * Version 2.0
- * 08-feb-2006 15:34:10:Ulf
- *
- * -Fixed issue when not waking up line disipine layer, could probably result
- * in better uplink performance for 2.4.
- *
- * -Fixed issue with big endian during initalization, now proper toggle flags
- * are handled between preloader and maincode.
- *
- * -Fixed flow control issue.
- *
- * -Added support for setting DTR.
- *
- * -For 2.4 kernels, removing temporary buffer that's not needed.
- *
- * -Reading CTS only for modem port (only port that supports it).
- *
- * -Return 0 in write_room instead of netative value, it's not handled in
- * upper layer.
- *
- * --------------------------------------------------------------------------
- * Version 1.0
- *
- * First version of driver, only tested with card of type F32_2.
- * Works fine with 2.4 and 2.6 kernels.
- * Driver also support big endian architecture.
- */
-
/* Enable this to have a lot of debug printouts */
#define DEBUG

@@ -143,8 +89,9 @@ do { \
/* Do we need this settable at runtime? */
static int debug = NOZOMI_DEBUG_LEVEL;

-#define D(lvl, args...) do {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
- while (0)
+#define D(lvl, args...) do \
+ {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
+ while (0)
#define D_(lvl, args...) D(lvl, ##args)

/* These printouts are always printed */
@@ -273,13 +220,13 @@ enum port_type {
/* Big endian */

struct toggles {
- unsigned enabled:5; /*
+ unsigned int enabled:5; /*
* Toggle fields are valid if enabled is 0,
* else A-channels must always be used.
*/
- unsigned diag_dl:1;
- unsigned mdm_dl:1;
- unsigned mdm_ul:1;
+ unsigned int diag_dl:1;
+ unsigned int mdm_dl:1;
+ unsigned int mdm_ul:1;
} __attribute__ ((packed));

/* Configuration table to read at startup of card */
@@ -320,19 +267,19 @@ struct config_table {
/* This stores all control downlink flags */
struct ctrl_dl {
u8 port;
- unsigned reserved:4;
- unsigned CTS:1;
- unsigned RI:1;
- unsigned DCD:1;
- unsigned DSR:1;
+ unsigned int reserved:4;
+ unsigned int CTS:1;
+ unsigned int RI:1;
+ unsigned int DCD:1;
+ unsigned int DSR:1;
} __attribute__ ((packed));

/* This stores all control uplink flags */
struct ctrl_ul {
u8 port;
- unsigned reserved:6;
- unsigned RTS:1;
- unsigned DTR:1;
+ unsigned int reserved:6;
+ unsigned int RTS:1;
+ unsigned int DTR:1;
} __attribute__ ((packed));

#else
@@ -340,10 +287,10 @@ struct ctrl_ul {

/* This represents the toggle information */
struct toggles {
- unsigned mdm_ul:1;
- unsigned mdm_dl:1;
- unsigned diag_dl:1;
- unsigned enabled:5; /*
+ unsigned int mdm_ul:1;
+ unsigned int mdm_dl:1;
+ unsigned int diag_dl:1;
+ unsigned int enabled:5; /*
* Toggle fields are valid if enabled is 0,
* else A-channels must always be used.
*/
@@ -379,19 +326,19 @@ struct config_table {

/* This stores all control downlink flags */
struct ctrl_dl {
- unsigned DSR:1;
- unsigned DCD:1;
- unsigned RI:1;
- unsigned CTS:1;
- unsigned reserverd:4;
+ unsigned int DSR:1;
+ unsigned int DCD:1;
+ unsigned int RI:1;
+ unsigned int CTS:1;
+ unsigned int reserverd:4;
u8 port;
} __attribute__ ((packed));

/* This stores all control uplink flags */
struct ctrl_ul {
- unsigned DTR:1;
- unsigned RTS:1;
- unsigned reserved:6;
+ unsigned int DTR:1;
+ unsigned int RTS:1;
+ unsigned int reserved:6;
u8 port;
} __attribute__ ((packed));
#endif
@@ -694,7 +641,7 @@ static void dump_table(const struct nozo
dc->config_table.ul_ctrl_len);
}
#else
-static __inline__ void dump_table(const struct nozomi *dc) { }
+static inline void dump_table(const struct nozomi *dc) { }
#endif

/*
@@ -1102,7 +1049,7 @@ static int send_flow_control(struct nozo
}

/*
- * Handle donlink data, ports that are handled are modem and diagnostics
+ * Handle downlink data, ports that are handled are modem and diagnostics
* Return 1 - ok
* Return 0 - toggle fields are out of sync
*/
@@ -1363,7 +1310,7 @@ static ssize_t card_type_show(struct dev

return sprintf(buf, "%d\n", dc->card_type);
}
-static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
+static DEVICE_ATTR(card_type, S_IRUGO, card_type_show, NULL);

static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -1372,7 +1319,7 @@ static ssize_t open_ttys_show(struct dev

return sprintf(buf, "%u\n", dc->open_ttys);
}
-static DEVICE_ATTR(open_ttys, 0444, open_ttys_show, NULL);
+static DEVICE_ATTR(open_ttys, S_IRUGO, open_ttys_show, NULL);

static void make_sysfs_files(struct nozomi *dc)
{
@@ -1882,7 +1829,10 @@ static void ntty_throttle(struct tty_str
/* just to discard single character writes */
static void ntty_put_char(struct tty_struct *tty, unsigned char c)
{
- /* FIXME !!! */
+ /*
+ * card does not react correct when we write single chars
+ * to the card, so we discard them
+ */
DBG2("PUT CHAR Function: %c", c);
}

2008-01-25 19:43:55

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, Jan 25, 2008 at 10:44:59AM -0800, Linus Torvalds wrote:
>
>
> On Thu, 24 Jan 2008, Greg KH wrote:
> >
> > Here are a pretty large number of kobject, documentation, and driver
> > core patches against your 2.6.24 git tree.
>
> I've merged it all, but it causes lots of scary warnings:
>
> - from the purely broken ones:
>
> ehci_hcd: no version for "struct_module" found: kernel tainted.

Ok, in looking at the code, this should also be showing up for you on a
"clean" 2.6.24 release, I didn't change anything in this code path.

That is what taints your kernel with the "F" flag.

> - to the scary ones:
>
> sysfs: duplicate filename 'ehci_hcd' can not be created
> WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
> Pid: 610, comm: insmod Tainted: GF 2.6.24-gb47711bf #28
>
> Call Trace:
> [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
> [<ffffffff802bdbc0>] create_dir+0x4f/0x87
> [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
> [<ffffffff803154c8>] kobject_get+0x12/0x17
> [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
> [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
> [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
> [<ffffffff80315321>] kobject_init+0x42/0x82
> [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
> [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
> [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
> [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
> [<ffffffff8028ebd5>] dput+0x1c/0x10b
> [<ffffffff8020b3be>] system_call+0x7e/0x83

This is the sysfs core telling you that someone did something stupid :)

Yes, that's new, but the "error" was always there, I just made the
warning more visible to get people to pay attention to it, and find the
real errors where this happens (and it has found them, which is a good
thing.)

But in this case, it doesn't look like the module loading code will
detect that we are trying to load a module that is already present until
the kobjects are set up here. It's been this way for a long time :(

Rusty, any ideas of us adding a different check for "duplicate" modules
like this earlier in the load_module() function, so we don't spend so
much effort in building everything up when we don't need to?

I think it's down in the apply_relocate() function where we would
finally figure out that something bad is going on here, which seems a
bit late to me.

I guess we could just check the list of module names loaded when we try
to set up the kobject, that would be simple and easy.

Linus, does the patch below (built tested only) fix the above call trace
noise for you? It shouldn't change the taint flag, that's a different
issue it seems.

thanks,

greg k-h

---------------------

From: Greg Kroah-Hartman <[email protected]>
Subject: module: bail out of loading duplicate modules early

This should fix the long calltrace when trying to load a module that has
been built into the kernel allready.

Signed-off-by: Greg Kroah-Hartman <[email protected]>

diff --git a/kernel/module.c b/kernel/module.c
index dcb8a2c..3a76a4d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1210,6 +1210,7 @@ void module_remove_modinfo_attrs(struct module *mod)
int mod_sysfs_init(struct module *mod)
{
int err;
+ struct kobject *kobj;

if (!module_sysfs_initialized) {
printk(KERN_ERR "%s: module sysfs not initialized\n",
@@ -1217,6 +1218,15 @@ int mod_sysfs_init(struct module *mod)
err = -EINVAL;
goto out;
}
+
+ kobj = kset_find_obj(module_kset, mod->name);
+ if (kobj) {
+ printk(KERN_ERR "%s: module is already loaded\n", mod->name);
+ kobject_put(kobj);
+ err = -EINVAL;
+ goto out;
+ }
+
mod->mkobj.mod = mod;

memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));

2008-01-25 19:44:49

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

On Fri, Jan 25, 2008 at 08:33:50PM +0100, Frank Seidel wrote:
> On Friday 25 January 2008 19:55, Greg KH wrote:
> > Frank, can you send me a patch against Linus's current git tree that had
> > the last version of this driver included in it?
> >
> > That way I can actually apply the changes :)
>
> Sure :-) This one is rebased on the current state in git.

One more time, with a "real" changelog entry that I can use, and a
signed-off-by: so that I can apply it to the tree would be good :)

thanks,

greg k-h

2008-01-25 19:56:20

by Jeremy Fitzhardinge

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

Linus Torvalds wrote:
> I'm too lazy to want to do my own initrd. I just use the prepackaged ones
> and rely on the fact that my private kernel will refuse to load modules
> that aren't meant for it anyway.
>

initrds generally aren't prepackaged, but generated on install (at least
with Fedora). You can regenerate them with "mkinitrd -f
/boot/initrd-2.6.24.img 2.6.24". Also, I find that "make
modules_install install" does it automatically from a kernel build.

J

2008-01-25 20:13:36

by Frank Seidel

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

From: Frank Seidel <[email protected]>

Minor cleanups and removal of in-file changelog:

- Correction of misspellings and wrong encoded Name
- changed 'unsigned' to 'unsigned int' for better readability
- use of generic devicefile access macro
- fixed/added explanatory comment to ntty_put_char

Signed-off-by: Frank Seidel <[email protected]>
---
drivers/char/nozomi.c | 122 ++++++++++++++------------------------------------
1 file changed, 36 insertions(+), 86 deletions(-)

--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -2,7 +2,7 @@
* nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
*
* Written by: Ulf Jakobsson,
- * Jan �erfeldt,
+ * Jan Åkerfeldt,
* Stefan Thomasson,
*
* Maintained by: Paul Hardwick ([email protected])
@@ -38,60 +38,6 @@
* --------------------------------------------------------------------------
*/

-/*
- * CHANGELOG
- * Version 2.1d
- * 11-November-2007 Jiri Slaby, Frank Seidel
- * - Big rework of multicard support by Jiri
- * - Major cleanups (semaphore to mutex, endianess, no major reservation)
- * - Optimizations
- *
- * Version 2.1c
- * 30-October-2007 Frank Seidel
- * - Completed multicard support
- * - Minor cleanups
- *
- * Version 2.1b
- * 07-August-2007 Frank Seidel
- * - Minor cleanups
- * - theoretical multicard support
- *
- * Version 2.1
- * 03-July-2006 Paul Hardwick
- *
- * - Stability Improvements. Incorporated spinlock wraps patch.
- * - Updated for newer 2.6.14+ kernels (tty_buffer_request_room)
- * - using __devexit macro for tty
- *
- *
- * Version 2.0
- * 08-feb-2006 15:34:10:Ulf
- *
- * -Fixed issue when not waking up line disipine layer, could probably result
- * in better uplink performance for 2.4.
- *
- * -Fixed issue with big endian during initalization, now proper toggle flags
- * are handled between preloader and maincode.
- *
- * -Fixed flow control issue.
- *
- * -Added support for setting DTR.
- *
- * -For 2.4 kernels, removing temporary buffer that's not needed.
- *
- * -Reading CTS only for modem port (only port that supports it).
- *
- * -Return 0 in write_room instead of netative value, it's not handled in
- * upper layer.
- *
- * --------------------------------------------------------------------------
- * Version 1.0
- *
- * First version of driver, only tested with card of type F32_2.
- * Works fine with 2.4 and 2.6 kernels.
- * Driver also support big endian architecture.
- */
-
/* Enable this to have a lot of debug printouts */
#define DEBUG

@@ -143,8 +89,9 @@ do { \
/* Do we need this settable at runtime? */
static int debug = NOZOMI_DEBUG_LEVEL;

-#define D(lvl, args...) do {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
- while (0)
+#define D(lvl, args...) do \
+ {if (lvl & debug) NFO(KERN_DEBUG, ##args); } \
+ while (0)
#define D_(lvl, args...) D(lvl, ##args)

/* These printouts are always printed */
@@ -273,13 +220,13 @@ enum port_type {
/* Big endian */

struct toggles {
- unsigned enabled:5; /*
+ unsigned int enabled:5; /*
* Toggle fields are valid if enabled is 0,
* else A-channels must always be used.
*/
- unsigned diag_dl:1;
- unsigned mdm_dl:1;
- unsigned mdm_ul:1;
+ unsigned int diag_dl:1;
+ unsigned int mdm_dl:1;
+ unsigned int mdm_ul:1;
} __attribute__ ((packed));

/* Configuration table to read at startup of card */
@@ -320,19 +267,19 @@ struct config_table {
/* This stores all control downlink flags */
struct ctrl_dl {
u8 port;
- unsigned reserved:4;
- unsigned CTS:1;
- unsigned RI:1;
- unsigned DCD:1;
- unsigned DSR:1;
+ unsigned int reserved:4;
+ unsigned int CTS:1;
+ unsigned int RI:1;
+ unsigned int DCD:1;
+ unsigned int DSR:1;
} __attribute__ ((packed));

/* This stores all control uplink flags */
struct ctrl_ul {
u8 port;
- unsigned reserved:6;
- unsigned RTS:1;
- unsigned DTR:1;
+ unsigned int reserved:6;
+ unsigned int RTS:1;
+ unsigned int DTR:1;
} __attribute__ ((packed));

#else
@@ -340,10 +287,10 @@ struct ctrl_ul {

/* This represents the toggle information */
struct toggles {
- unsigned mdm_ul:1;
- unsigned mdm_dl:1;
- unsigned diag_dl:1;
- unsigned enabled:5; /*
+ unsigned int mdm_ul:1;
+ unsigned int mdm_dl:1;
+ unsigned int diag_dl:1;
+ unsigned int enabled:5; /*
* Toggle fields are valid if enabled is 0,
* else A-channels must always be used.
*/
@@ -379,19 +326,19 @@ struct config_table {

/* This stores all control downlink flags */
struct ctrl_dl {
- unsigned DSR:1;
- unsigned DCD:1;
- unsigned RI:1;
- unsigned CTS:1;
- unsigned reserverd:4;
+ unsigned int DSR:1;
+ unsigned int DCD:1;
+ unsigned int RI:1;
+ unsigned int CTS:1;
+ unsigned int reserverd:4;
u8 port;
} __attribute__ ((packed));

/* This stores all control uplink flags */
struct ctrl_ul {
- unsigned DTR:1;
- unsigned RTS:1;
- unsigned reserved:6;
+ unsigned int DTR:1;
+ unsigned int RTS:1;
+ unsigned int reserved:6;
u8 port;
} __attribute__ ((packed));
#endif
@@ -694,7 +641,7 @@ static void dump_table(const struct nozo
dc->config_table.ul_ctrl_len);
}
#else
-static __inline__ void dump_table(const struct nozomi *dc) { }
+static inline void dump_table(const struct nozomi *dc) { }
#endif

/*
@@ -1102,7 +1049,7 @@ static int send_flow_control(struct nozo
}

/*
- * Handle donlink data, ports that are handled are modem and diagnostics
+ * Handle downlink data, ports that are handled are modem and diagnostics
* Return 1 - ok
* Return 0 - toggle fields are out of sync
*/
@@ -1363,7 +1310,7 @@ static ssize_t card_type_show(struct dev

return sprintf(buf, "%d\n", dc->card_type);
}
-static DEVICE_ATTR(card_type, 0444, card_type_show, NULL);
+static DEVICE_ATTR(card_type, S_IRUGO, card_type_show, NULL);

static ssize_t open_ttys_show(struct device *dev, struct device_attribute *attr,
char *buf)
@@ -1372,7 +1319,7 @@ static ssize_t open_ttys_show(struct dev

return sprintf(buf, "%u\n", dc->open_ttys);
}
-static DEVICE_ATTR(open_ttys, 0444, open_ttys_show, NULL);
+static DEVICE_ATTR(open_ttys, S_IRUGO, open_ttys_show, NULL);

static void make_sysfs_files(struct nozomi *dc)
{
@@ -1882,7 +1829,10 @@ static void ntty_throttle(struct tty_str
/* just to discard single character writes */
static void ntty_put_char(struct tty_struct *tty, unsigned char c)
{
- /* FIXME !!! */
+ /*
+ * card does not react correct when we write single chars
+ * to the card, so we discard them
+ */
DBG2("PUT CHAR Function: %c", c);
}

2008-01-25 20:14:38

by Frank Seidel

[permalink] [raw]
Subject: Re: [PATCH 012/196 ver2] nozomi driver

On Friday 25 January 2008 20:43, Greg KH wrote:
> One more time, with a "real" changelog entry that I can use, and a
> signed-off-by: so that I can apply it to the tree would be good :)

Oops, sorry. Must have been much too long ago since i sent my last
patch :)

Thanks,
Frank

2008-01-25 20:23:41

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24



On Fri, 25 Jan 2008, Greg KH wrote:

> On Fri, Jan 25, 2008 at 10:44:59AM -0800, Linus Torvalds wrote:
> >
> > - from the purely broken ones:
> >
> > ehci_hcd: no version for "struct_module" found: kernel tainted.
>
> Ok, in looking at the code, this should also be showing up for you on a
> "clean" 2.6.24 release, I didn't change anything in this code path.

Ok, I just never noticed, because without any warnings or oopses, it
didn't much matter...

> Linus, does the patch below (built tested only) fix the above call trace
> noise for you? It shouldn't change the taint flag, that's a different
> issue it seems.

Sadly, I'm now in the process of shutting down all my machines to prepare
for "the flight from hell(tm)", so I won't have time to check this right
now.

Linus

2008-01-25 20:29:53

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, Jan 25, 2008 at 12:23:25PM -0800, Linus Torvalds wrote:
> On Fri, 25 Jan 2008, Greg KH wrote:
> > Linus, does the patch below (built tested only) fix the above call trace
> > noise for you? It shouldn't change the taint flag, that's a different
> > issue it seems.
>
> Sadly, I'm now in the process of shutting down all my machines to prepare
> for "the flight from hell(tm)", so I won't have time to check this right
> now.

Ok, I'll queue it up myself in my trees and send it to you in a few
days.

Have a nice trip,

greg k-h

2008-01-25 20:39:19

by Mark Fasheh

[permalink] [raw]
Subject: Re: [PATCH 093/196] kset: convert ocfs2 to use kset_create

On Thu, Jan 24, 2008 at 11:32:02PM -0800, Greg Kroah-Hartman wrote:
> Dynamically create the kset instead of declaring it statically.
>
> Also use the new kobj_attribute which cleans up this file a _lot_.
>
> Cc: Kay Sievers <[email protected]>
> Cc: Mark Fasheh <[email protected]>
> Cc: Kurt Hackel <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>

Acked-by: Mark Fasheh <[email protected]>

--
Mark Fasheh
Principal Software Developer, Oracle
[email protected]

2008-01-25 21:12:13

by Jon Masters

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, 2008-01-25 at 10:44 -0800, Linus Torvalds wrote:

> and the problem seems to be that it does all these checks even for modules
> that will never be loaded, because I use my own kernel, but with the
> default Fedora initrd (which is trying to load modules for stuff that I
> already have built in).

Thanks Linus. I'll pass this on to the mkinitrd maintainer. We'll try to
get this sorted out for you :)

Jon.

2008-01-25 21:21:18

by Jon Masters

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24


On Fri, 2008-01-25 at 11:56 -0800, Jeremy Fitzhardinge wrote:
> Linus Torvalds wrote:
> > I'm too lazy to want to do my own initrd. I just use the prepackaged ones
> > and rely on the fact that my private kernel will refuse to load modules
> > that aren't meant for it anyway.

> initrds generally aren't prepackaged, but generated on install (at least
> with Fedora). You can regenerate them with "mkinitrd -f
> /boot/initrd-2.6.24.img 2.6.24". Also, I find that "make
> modules_install install" does it automatically from a kernel build.

Right. I assumed that Linus was calling mkinitrd but was being bitten by
one of the occasional assumptions (I believe we make in that script)
that certain things are always modular. I just mailed the maintainer,
suggesting we screen against the one of the Modules.* files (perhaps
Modules.order might become a good candidate in due course...).

Jon.

2008-01-25 21:50:32

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24



On Fri, 25 Jan 2008, Jon Masters wrote:
>
> Right. I assumed that Linus was calling mkinitrd but was being bitten by
> one of the occasional assumptions (I believe we make in that script)

No. I really am not. My /etc/grub.conf looks like this:

title Linux
root (hd0,0)
kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.23.14-107.fc8.img

ie I literally run the fedora initrd.

I switch kernels, not initrd's. I don't even want to know if the initrd
contains some distro-specific setup...

Linus

2008-01-25 21:51:47

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.

Hey Greg,

with Linus's latest kernel v2.6.24-412-gb47711b (which includes the
patch in the email I'm replying to), I see the following when I do
"modprobe -r ib_ipath" (on a system that actually has ipath hardware):

kernel BUG at fs/sysfs/group.c:74!
invalid opcode: 0000 [1] SMP
CPU 1
Modules linked in: fan ac battery ipv6 nfs lockd nfs_acl sunrpc dm_snapshot dm_mirror dm_mod loop ide_cd cdrom e1000 amd74xx generic psmouse shpchp pci_hotplug thermal ib_ipath serio_raw ehci_hcd ohci_hcd evdev button i2c_nforce2 ide_core processor ib_core k8temp i2c_core
Pid: 3975, comm: modprobe Not tainted 2.6.24 #24
RIP: 0010:[<ffffffff802bdbdb>] [<ffffffff802bdbdb>] sysfs_remove_group+0x25/0x94
RSP: 0000:ffff8101fbc33db8 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff81007d8bc070
RDX: ffff81007d634272 RSI: ffff81007d634d00 RDI: ffffffff80503090
RBP: ffffffff880a7220 R08: 0000000000000000 R09: ffff81007d8bc070
R10: 0000000000000000 R11: 00000000fd812590 R12: ffff81007d8bc070
R13: 00007fffc6f88c80 R14: 0000000000000000 R15: 0000000000000000
FS: 00002acbe409b6e0(0000) GS:ffff81007e001a00(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00002acbe3e59de0 CR3: 000000007d482000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process modprobe (pid: 3975, threadinfo ffff8101fbc32000, task ffff8101fbead590)
Stack: 000000000e9000ff ffff81007d8bc160 ffff81007d8bc070 ffffffff88087574
ffffc20001734000 ffffc20001734000 ffffffff880a7050 ffffffff88074b26
ffffffff804bd39a ffff81007d8bc000 ffffffff880a7050 ffffffff804bd39a
Call Trace:
[<ffffffff88087574>] :ib_ipath:ipath_device_remove_group+0x20/0x42
[<ffffffff88074b26>] :ib_ipath:ipath_remove_one+0x9f/0x431
[<ffffffff803235e5>] pci_device_remove+0x24/0x47
[<ffffffff8036ec01>] __device_release_driver+0x74/0x97
[<ffffffff8036f075>] driver_detach+0x96/0xd5
[<ffffffff8036e568>] bus_remove_driver+0x7b/0x9e
[<ffffffff803238da>] pci_unregister_driver+0x29/0x7d
[<ffffffff8809093f>] :ib_ipath:infinipath_cleanup+0x33/0x40
[<ffffffff8025032a>] sys_delete_module+0x199/0x1cf
[<ffffffff80318400>] __up_read+0x2/0x8a
[<ffffffff8020befe>] system_call+0x7e/0x83

Code: 0f 0b eb fe 48 85 db 74 2e 83 3b 00 75 26 48 c7 c1 d8 ae 43
RIP [<ffffffff802bdbdb>] sysfs_remove_group+0x25/0x94
RSP <ffff8101fbc33db8>

The BUG() in question is the one here:

void sysfs_remove_group(struct kobject * kobj,
const struct attribute_group * grp)
{
struct sysfs_dirent *dir_sd = kobj->sd;
struct sysfs_dirent *sd;

if (grp->name) {
sd = sysfs_get_dirent(dir_sd, grp->name);
BUG_ON(!sd);

Any ideas here? I'll continue to try to relearn all the sysfs stuff
but a hint my make things go faster.

Thanks,
Roland

2008-01-25 21:58:25

by Jeremy Fitzhardinge

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

Linus Torvalds wrote:
> On Fri, 25 Jan 2008, Jon Masters wrote:
>
>> Right. I assumed that Linus was calling mkinitrd but was being bitten by
>> one of the occasional assumptions (I believe we make in that script)
>>
>
> No. I really am not. My /etc/grub.conf looks like this:
>
> title Linux
> root (hd0,0)
> kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
> initrd /initrd-2.6.23.14-107.fc8.img
>
> ie I literally run the fedora initrd.
>
> I switch kernels, not initrd's. I don't even want to know if the initrd
> contains some distro-specific setup...

The distro mkinird can reconstruct it containing your freshly built
modules (if any) and any other distro goo which needs to go in there.
/initrd-2.6.23.14-107.fc8.img doesn't come out of an rpm; its built by
an installer script when you install the kernel, and you can run the
same script on your kernels.

Does you use "make modules_install install" when you build the kernel?
It just does the right thing for me under F8, including rebuilding
initrd and updating grub.conf.

J

2008-01-25 22:04:56

by Jeff Garzik

[permalink] [raw]
Subject: Re: [PATCH 076/196] ecryptfs: remove version_str file from sysfs

Michael Halcrow wrote:
> On Fri, Jan 25, 2008 at 09:54:21AM -0800, Greg KH wrote:
>> I could not find any userspace tools or documentation that used it
>
> The version_str handle is only there as a potential convenience for
> users who need to figure out what their module can and cannot do. I
> mentioned it in an article in LJ last year. It does not need to be
> there for any tools to work right, and I do not think that anyone
> really cares about it at this point, so I have no problem with just
> ripping it out.

Cool, well ignore my objection then...

Jeff



2008-01-25 22:12:29

by Roland Dreier

[permalink] [raw]
Subject: Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.

So I think it is coming from the following code in ipath_sysfs.c:

int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
{
int ret;

ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
if (ret)
goto bail;

ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
if (ret)
goto bail_attrs;

sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
bail_attrs:
sysfs_remove_group(&dev->kobj, &dev_attr_group);
bail:
return ret;
}

note that the success path falls through into the error path and
removes the groups it just created, which means that on initialization
the groups are already removed, so we hit the BUG on the second try to
remove the groups on module exit.

And I think this chunk of your patch:

- snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
- ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
- if (ret == 0)
- goto bail;
-

was what broke it. (Note the "if (ret == 0) then skip error
unwinding" code that got deleted by mistake -- not surprising given
how hard to read that construction is)

My bad for not testing -mm better. I'll queue this up to fix it:

diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
index aa27ca9..e2a6534 100644
--- a/drivers/infiniband/hw/ipath/ipath_sysfs.c
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -770,7 +770,8 @@ int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
if (ret)
goto bail_attrs;

- sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
+ return 0;
+
bail_attrs:
sysfs_remove_group(&dev->kobj, &dev_attr_group);
bail:

2008-01-25 22:25:24

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 148/196] Infiniband: make ipath driver use default driver groups.

On Fri, Jan 25, 2008 at 02:11:14PM -0800, Roland Dreier wrote:
> So I think it is coming from the following code in ipath_sysfs.c:
>
> int ipath_device_create_group(struct device *dev, struct ipath_devdata *dd)
> {
> int ret;
>
> ret = sysfs_create_group(&dev->kobj, &dev_attr_group);
> if (ret)
> goto bail;
>
> ret = sysfs_create_group(&dev->kobj, &dev_counter_attr_group);
> if (ret)
> goto bail_attrs;
>
> sysfs_remove_group(&dev->kobj, &dev_counter_attr_group);
> bail_attrs:
> sysfs_remove_group(&dev->kobj, &dev_attr_group);
> bail:
> return ret;
> }
>
> note that the success path falls through into the error path and
> removes the groups it just created, which means that on initialization
> the groups are already removed, so we hit the BUG on the second try to
> remove the groups on module exit.
>
> And I think this chunk of your patch:
>
> - snprintf(unit, sizeof(unit), "%02d", dd->ipath_unit);
> - ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, unit);
> - if (ret == 0)
> - goto bail;
> -
>
> was what broke it. (Note the "if (ret == 0) then skip error
> unwinding" code that got deleted by mistake -- not surprising given
> how hard to read that construction is)
>
> My bad for not testing -mm better. I'll queue this up to fix it:

Thanks for the fix, and sorry for causing that, it was a complex error
path :)

Although a BUG() for when we try to remove a file that is no longer
there seems pretty harsh, I think I'll change that to a WARN_ON() so
that people just know to fix up their code, not kill the kernel
entirely.

thanks,

greg k-h

2008-01-25 22:26:09

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n


* Greg Kroah-Hartman <[email protected]> wrote:

> From: Randy Dunlap <[email protected]>
>
> When SYSFS=n and MODULES=y, build ends with:
>
> linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':
> linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function)
> make[3]: *** [drivers/base/module.o] Error 1

_PLEASE_ fold such fixes into the patch that introduces the build bugs,
prior sending your git trees upstream! (just like Andrew does it with
all patches that come via -mm)

Changes like this (and it now leaked into Linus' tree as well) kill
bisectability.

Thanks.

Ingo

2008-01-25 22:27:57

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24


On Fri, 2008-01-25 at 13:58 -0800, Jeremy Fitzhardinge wrote:
> Linus Torvalds wrote:
> > On Fri, 25 Jan 2008, Jon Masters wrote:
> >
> >> Right. I assumed that Linus was calling mkinitrd but was being bitten by
> >> one of the occasional assumptions (I believe we make in that script)
> >>
> >
> > No. I really am not. My /etc/grub.conf looks like this:
> >
> > title Linux
> > root (hd0,0)
> > kernel /vmlinuz ro root=/dev/VolGroup00/LogVol00 rhgb quiet
> > initrd /initrd-2.6.23.14-107.fc8.img
> >
> > ie I literally run the fedora initrd.
> >
> > I switch kernels, not initrd's. I don't even want to know if the initrd
> > contains some distro-specific setup...
>
> The distro mkinird can reconstruct it containing your freshly built
> modules (if any) and any other distro goo which needs to go in there.
> /initrd-2.6.23.14-107.fc8.img doesn't come out of an rpm; its built by
> an installer script when you install the kernel, and you can run the
> same script on your kernels.
>
> Does you use "make modules_install install" when you build the kernel?
> It just does the right thing for me under F8, including rebuilding
> initrd and updating grub.conf.

My wish is that distros would just boot without requiring an initrd. I
know how to make them for redhat and debian based distros, but the fact
that you can't (easily) cross-build them makes it a very tedious
construct.

I can butcher the distros into booting and ignore the errors on bootup
that whine that modules are missing, but really.

2008-01-25 22:34:12

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n

> On Fri, 25 Jan 2008 23:25:30 +0100 Ingo Molnar <[email protected]> wrote:
>
> * Greg Kroah-Hartman <[email protected]> wrote:
>
> > From: Randy Dunlap <[email protected]>
> >
> > When SYSFS=n and MODULES=y, build ends with:
> >
> > linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':
> > linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function)
> > make[3]: *** [drivers/base/module.o] Error 1
>
> _PLEASE_ fold such fixes into the patch that introduces the build bugs,
> prior sending your git trees upstream! (just like Andrew does it with
> all patches that come via -mm)
>
> Changes like this (and it now leaked into Linus' tree as well) kill
> bisectability.
>

Absolutely - this is important. After several hours mucking about I just
gave up trying to bisect a 2.6.24-rc1 regression due to hitting 100% build
errors and runtime oopses during the bisection. Mainly from networking in
that case.

2008-01-25 22:40:34

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n

On Fri, Jan 25, 2008 at 11:25:30PM +0100, Ingo Molnar wrote:
>
> * Greg Kroah-Hartman <[email protected]> wrote:
>
> > From: Randy Dunlap <[email protected]>
> >
> > When SYSFS=n and MODULES=y, build ends with:
> >
> > linux-2.6.24-rc6-mm1/drivers/base/module.c: In function 'module_add_driver':
> > linux-2.6.24-rc6-mm1/drivers/base/module.c:49: error: 'module_kset' undeclared (first use in this function)
> > make[3]: *** [drivers/base/module.o] Error 1
>
> _PLEASE_ fold such fixes into the patch that introduces the build bugs,
> prior sending your git trees upstream! (just like Andrew does it with
> all patches that come via -mm)

For most of these issues I do merge them together.

However, for some odd kernel configurations, like this one, I didn't, my
appologies. I'll try to be more careful in the future.

> Changes like this (and it now leaked into Linus' tree as well) kill
> bisectability.

The odds that a "normal" person has sysfs turned off and modules
enabled, trying to bisect things, is pretty slim :)

thanks,

greg k-h

2008-01-25 22:57:49

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n


* Greg KH <[email protected]> wrote:

> > Changes like this (and it now leaked into Linus' tree as well) kill
> > bisectability.
>
> The odds that a "normal" person has sysfs turned off and modules
> enabled, trying to bisect things, is pretty slim :)

that "slim" combination is what i use for about 25% of all my bisections
- i build, boot and stress-test randconfig configs.

If i find a problem with a given .config, i do _not_ go around and
change the .config to make a bisection point work. (and the automated
bisection scripts definitely wont do it either.)

so what is a 'weird config' to you is a real testing barrier for others.
And crap like that quickly mounts up. Having a buildable and bootable
kernel at every bisection point is a _must_.

Please! :-)

Ingo

2008-01-25 23:11:59

by Heiko Carstens

[permalink] [raw]
Subject: Re: [PATCH 085/196] kset: convert s390 ipl.c to use kset_create

On Fri, Jan 25, 2008 at 09:48:58AM -0800, Greg KH wrote:
> On Fri, Jan 25, 2008 at 01:20:53PM +0100, Heiko Carstens wrote:
> > On Thu, Jan 24, 2008 at 11:31:54PM -0800, Greg Kroah-Hartman wrote:
> > > Dynamically create the kset instead of declaring it statically.
> > > This makes the kobject attributes now work properly that I broke in the
> > > previous patch.
> >
> > Could you please merge this and the previous patch before it goes
> > upstream? Having an intermediate state where things are broken
> > will cause pain and additional work in case of bisecting.
>
> It will not cause a build error (see the previous patch for details.)
> The sysfs files will not properly show the correct data, that is all.
>
> The odds that you will hit this in a 'git bisect' is VERY low, and the
> previous patch states that the files are now broken, so there should not
> be any confusion regarding any user that might run across this.

The odds are very low, as long as not more patch sets come up which
introduce intermediate broken kernels.
What exactly is the advantage of breaking the kernel with patch 1 and
then fix it again with patch 2 instead of doing the straight forward
conversions all with one patch?

2008-01-25 23:16:45

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n

On Fri, Jan 25, 2008 at 11:57:23PM +0100, Ingo Molnar wrote:
>
> * Greg KH <[email protected]> wrote:
>
> > > Changes like this (and it now leaked into Linus' tree as well) kill
> > > bisectability.
> >
> > The odds that a "normal" person has sysfs turned off and modules
> > enabled, trying to bisect things, is pretty slim :)
>
> that "slim" combination is what i use for about 25% of all my bisections
> - i build, boot and stress-test randconfig configs.
>
> If i find a problem with a given .config, i do _not_ go around and
> change the .config to make a bisection point work. (and the automated
> bisection scripts definitely wont do it either.)
>
> so what is a 'weird config' to you is a real testing barrier for others.
> And crap like that quickly mounts up. Having a buildable and bootable
> kernel at every bisection point is a _must_.
>
> Please! :-)

Yes, I do agree that this is important, I'll work to not let this happen
again. Especially now that I have your build scripts, I'm working on
setting up something like that myself here.

thanks,

greg k-h

2008-01-25 23:20:00

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n


* Greg KH <[email protected]> wrote:

> > Please! :-)
>
> Yes, I do agree that this is important, I'll work to not let this
> happen again. Especially now that I have your build scripts, I'm
> working on setting up something like that myself here.

btw., Harvey Harrison has cleaned them up some more, and has told me
about KCONFIG_ALLCONFIG, which is very useful when you want to tailor
randconfig builds to different testsystems (which might have different
minimum driver requirements and different distro requirements for kernel
features). Harvey, could you send the latest version of those
auto-Kconfig cleanups?

Ingo

2008-01-25 23:27:21

by Harvey Harrison

[permalink] [raw]
Subject: Re: [PATCH 183/196] driver core: fix build with SYSFS=n

On Sat, 2008-01-26 at 00:18 +0100, Ingo Molnar wrote:
> * Greg KH <[email protected]> wrote:
>
> > > Please! :-)
> >
> > Yes, I do agree that this is important, I'll work to not let this
> > happen again. Especially now that I have your build scripts, I'm
> > working on setting up something like that myself here.
>
> btw., Harvey Harrison has cleaned them up some more, and has told me
> about KCONFIG_ALLCONFIG, which is very useful when you want to tailor
> randconfig builds to different testsystems (which might have different
> minimum driver requirements and different distro requirements for kernel
> features). Harvey, could you send the latest version of those
> auto-Kconfig cleanups?

Sorry, I've been a bit laid up with illness to pull out any upstreamable
pieces. Attached is the original version I sent to you that still has
the Ingo-specific need_config file. Hopefully I'll be back in action
and can finish this soon.

This is functionally equivalent to Ingo's patch at:

http://people.redhat.com/mingo/auto-qa-patches/Kconfig-qa.patch

Instead, create a need_config file and invoke randconfig as:

make randconfig KCONFIG_ALLCONFIG=need_config

Signed-off-by: Harvey Harrison <[email protected]>
---
Ingo, your QA patch ends up being much smaller and works exactly the
same as long as you invoke randconfig with the above. I've included
a need_config file that has all of the options I removed from your patch
suitable for the above KCONFIG_ALLCONFIG use.

Cheers,

Harvey

arch/x86/Kconfig | 74 +++++++++++++++++++++++++++++++++++
arch/x86/Kconfig.needed | 99
+++++++++++++++++++++++++++++++++++++++++++++++
drivers/atm/Kconfig | 1 +
drivers/base/core.c | 3 +
init/Kconfig | 13 ++++++
init/main.c | 56 ++++++++++++++++++++++++++
kernel/time/Kconfig | 13 ++++++
lib/Kconfig | 3 +
need_config | 85 ++++++++++++++++++++++++++++++++++++++++
9 files changed, 347 insertions(+), 0 deletions(-)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 665e4b1..9061f77 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -164,6 +164,12 @@ config X86_TRAMPOLINE

config KTIME_SCALAR
def_bool X86_32
+
+config BOOTPARAM_SUPPORT
+ bool "bootparam support"
+ help
+ support for boot command-line parameters via .config
+
source "init/Kconfig"

menu "Processor type and features"
@@ -1204,6 +1210,66 @@ config COMPAT_VDSO

If unsure, say Y.

+config BOOTPARAM_NMI_WATCHDOG_BIT_0
+ bool "bootparam: nmi_watchdog=X default value - bit 0"
+ depends on BOOTPARAM_SUPPORT
+ help
+ NMI watchdog default, bit 0. Useful for automated testing.
+
+config BOOTPARAM_NMI_WATCHDOG_BIT_1
+ bool "bootparam: nmi_watchdog=X default value - bit 1"
+ depends on BOOTPARAM_SUPPORT
+ help
+ NMI watchdog default, bit 1. Useful for automated testing.
+
+config BOOTPARAM_NOAPIC
+ bool "bootparam: noapic"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "noapic" on the boot line
+
+config BOOTPARAM_NOLAPIC
+ bool "bootparam: nolapic"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "nolapic" on the boot line
+
+config BOOTPARAM_LAPIC
+ bool "bootparam: lapic"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "lapic" on the boot line
+
+config BOOTPARAM_HPET_DISABLE
+ bool "bootparam: hpet=disable"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "hpet=disable" on the boot
line
+
+config BOOTPARAM_IDLE_MWAIT
+ bool "bootparam: idle=mwait"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "idle=mwait" on the boot line
+
+config BOOTPARAM_IDLE_POLL
+ bool "bootparam: idle=poll"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "idle=poll" on the boot line
+
+config BOOTPARAM_HIGHMEM_512M
+ bool "bootparam: highmem=512m"
+ depends on BOOTPARAM_SUPPORT
+ help
+ highmem=512m boot parameter. Useful for automated testing.
+
+config BOOTPARAM_NOPAT
+ bool "bootparam: nopat"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "nopat" on the boot line
+
endmenu

config ARCH_ENABLE_MEMORY_HOTPLUG
@@ -1612,3 +1678,11 @@ source "security/Kconfig"
source "crypto/Kconfig"

source "lib/Kconfig"
+
+config X86_32_ALWAYS_ON
+ bool
+ default y
+ depends on X86_32
+ select X86_PC
+ select PCI_GOANY
+
diff --git a/arch/x86/Kconfig.needed b/arch/x86/Kconfig.needed
new file mode 100644
index 0000000..b1f7ff0
--- /dev/null
+++ b/arch/x86/Kconfig.needed
@@ -0,0 +1,99 @@
+config FORCE_MINIMAL_CONFIG
+ bool
+ default y
+
+ select EXPERIMENTAL
+
+ select EXT3_FS
+ select EXT3_FS_XATTR
+ select EXT3_FS_POSIX_ACL
+ select EXT3_FS_SECURITY
+ select BLOCK
+ select HOTPLUG
+#select INOTIFY
+#select INOTIFY_USER
+
+ # so that capset() works (sudo, etc.):
+ select SECURITY
+ select SECURITY_CAPABILITIES
+ select BINFMT_ELF
+
+ select MSDOS_PARTITION
+ select PARTITION_ADVANCED
+ select BSD_DISKLABEL
+
+ select SYSFS
+ select SYSFS_DEPRECATED
+ select PROC_FS
+ select FUTEX
+
+select PACKET
+
+select NETPOLL
+select NETCONSOLE
+select NET_POLL_CONTROLLER
+select INET
+select NET
+select UNIX
+select NETDEVICES
+
+select SERIAL_8250
+select SERIAL_8250_CONSOLE
+select MAGIC_SYSRQ
+
+select INPUT
+select INPUT_MOUSEDEV
+select INPUT_POLLDEV
+select INPUT_KEYBOARD
+select KEYBOARD_ATKBD
+select SERIO
+select SERIO_I8042
+
+select VT
+select VT_CONSOLE
+select HW_CONSOLE
+select VGA_CONSOLE
+select EARLY_PRINTK
+select PRINTK
+select UNIX98_PTYS
+select STANDALONE
+select PREVENT_FIRMWARE_BUILD
+
+config FORCE_MINIMAL_CONFIG_64
+ bool
+ default y
+ depends on X86_64
+ select IA32_EMULATION
+
+config FORCE_MINIMAL_CONFIG_PHYS
+ bool
+ default y
+ depends on X86_64 || X86_32
+
+ select ATA
+ select SATA_AHCI
+ select ATA_PIIX
+ select PATA_AMD
+ select PATA_OLDPIIX
+ select BLK_DEV_SD
+
+ select E100
+ select E1000
+ select NET_ETHERNET
+ select NET_PCI
+ select MII
+ select CRC32
+
+ select 8139TOO
+ select FORCEDETH
+
+ select USB
+ select USB_MOUSE
+ select USB_EHCI_HCD
+ select USB_OHCI_HCD
+ select USB_UHCI_HCD
+ select USB_SUPPORT
+
+ select PCI
+
+
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index b554eda..caf4d20 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -344,6 +344,7 @@ config ATM_FORE200E_MAYBE
config ATM_FORE200E_PCA
bool "PCA-200E support"
depends on ATM_FORE200E_MAYBE && PCI
+ select ATM_FORE200E_PCA_DEFAULT_FW if PREVENT_FIRMWARE_BUILD
help
Say Y here if you want your PCA-200E cards to be probed.

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2683eac..84e61f5 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -104,7 +104,10 @@ static void device_release(struct kobject * kobj)
printk(KERN_ERR "Device '%s' does not have a release()
function, "
"it is broken and must be fixed.\n",
dev->bus_id);
+#if 0
+ // not a real bug:
WARN_ON(1);
+#endif
}
}

diff --git a/init/Kconfig b/init/Kconfig
index b9d11a8..add6333 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -324,6 +324,19 @@ config CPUSETS

Say N if unsure.

+config BOOTPARAM_MAXCPUS_1
+ bool "bootparam: maxcpus=1"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "maxcpus=1" on the boot line
+
+config BOOTPARAM_NOSMP
+ bool "bootparam: nosmp"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "nosmp" on the boot line
+
+
config FAIR_GROUP_SCHED
bool "Fair group CPU scheduler"
default y
diff --git a/init/main.c b/init/main.c
index 7f57f7a..495dd7e 100644
--- a/init/main.c
+++ b/init/main.c
@@ -126,6 +126,58 @@ static char *static_command_line;
static char *execute_command;
static char *ramdisk_execute_command;

+const char bootparam_command_line [] =
+""
+#ifdef CONFIG_BOOTPARAM_MAXCPUS_1
+" maxcpus=1"
+#endif
+#ifdef CONFIG_BOOTPARAM_NOSMP
+" nosmp"
+#endif
+#ifdef CONFIG_BOOTPARAM_NO_HZ_OFF
+" no_hz=off"
+#endif
+#ifdef CONFIG_BOOTPARAM_HIGHRES_OFF
+" highres=0"
+#endif
+#if defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_0) && \
+ !defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_1)
+" nmi_watchdog=0"
+#endif
+#if !defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_0) && \
+ defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_1)
+" nmi_watchdog=1"
+#endif
+#if defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_0) && \
+ defined(CONFIG_BOOTPARAM_NMI_WATCHDOG_BIT_1)
+" nmi_watchdog=2"
+#endif
+#ifdef CONFIG_BOOTPARAM_NOAPIC
+" noapic"
+#endif
+#ifdef CONFIG_BOOTPARAM_NOLAPIC
+" nolapic"
+#endif
+#ifdef CONFIG_BOOTPARAM_LAPIC
+" lapic"
+#endif
+#ifdef CONFIG_BOOTPARAM_HPET_DISABLE
+" hpet=disable"
+#endif
+#ifdef CONFIG_BOOTPARAM_IDLE_MWAIT
+" idle=mwait"
+#endif
+#ifdef CONFIG_BOOTPARAM_IDLE_POLL
+" idle=poll"
+#endif
+#ifdef CONFIG_BOOTPARAM_HIGHMEM_512M
+" highmem=512m"
+#endif
+#ifdef CONFIG_BOOTPARAM_NOPAT
+" nopat"
+#endif
+;
+
#ifdef CONFIG_SMP
/* Setup configured maximum number of CPUs to activate */
unsigned int __initdata setup_max_cpus = NR_CPUS;
@@ -484,6 +536,7 @@ void __init parse_early_param(void)
/* All fall through to do_early_param. */
strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
parse_args("early options", tmp_cmdline, NULL, 0,
do_early_param);
+
done = 1;
}

@@ -511,6 +564,9 @@ asmlinkage void __init start_kernel(void)

smp_setup_processor_id();

+ /* Build-time simulated boot parameters: */
+ strncat(boot_command_line, bootparam_command_line,
COMMAND_LINE_SIZE);
+
/*
* Need to run as early as possible, to initialize the
* lockdep hash:
diff --git a/kernel/time/Kconfig b/kernel/time/Kconfig
index 8d53106..a6b3b23 100644
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -14,6 +14,12 @@ config NO_HZ
only trigger on an as-needed basis both when the system is
busy and when the system is idle.

+config BOOTPARAM_NO_HZ_OFF
+ bool "bootparam: no_hz"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "no_hz=off" on the boot line
+
config HIGH_RES_TIMERS
bool "High Resolution Timer Support"
depends on GENERIC_TIME && GENERIC_CLOCKEVENTS
@@ -28,3 +34,10 @@ config GENERIC_CLOCKEVENTS_BUILD
default y
depends on GENERIC_CLOCKEVENTS || GENERIC_CLOCKEVENTS_MIGR

+config BOOTPARAM_HIGHRES_OFF
+ bool "bootparam: highres=0"
+ depends on BOOTPARAM_SUPPORT
+ help
+ if enabled, it has the effect as "highres=0" on the boot line
+
+
diff --git a/lib/Kconfig b/lib/Kconfig
index ba3d104..a4537df 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -142,3 +142,6 @@ config CHECK_SIGNATURE
bool

endmenu
+
+source "arch/x86/Kconfig.needed"
+
diff --git a/need_config b/need_config
new file mode 100644
index 0000000..fb57fec
--- /dev/null
+++ b/need_config
@@ -0,0 +1,85 @@
+# dangerous to boot on non-Elan CPUs
+CONFIG_X86_ELAN=n
+
+# hangs on bootup on non-Voyager platforms
+CONFIG_X86_VOYAGER=n
+
+# hangs on bootup on non-Numaq platforms
+CONFIG_X86_NUMAQ=n
+
+# hangs on bootup on non-VisWS platforms
+CONFIG_X86_VISWS=n
+
+# hangs on bootup on non-VisWS platforms (ES7000)
+CONFIG_X86_ES7000=n
+
+# hangs on bootup on non-PCIE systems
+CONFIG_PCI_GOMMCONFIG=n
+
+# the probe can hang during bootup on non-PARIDE boxes
+CONFIG_PARIDE=n
+
+# my test box expects /dev/sda, not /dev/hda
+CONFIG_IDE=n
+
+# unsafe and hangs on newer boxes
+CONFIG_BLK_DEV_HD_IDE=n
+
+# dangerous to enable - sometimes hangs on probe
+CONFIG_MTD=n
+
+# Can hang
+CONFIG_COPS=n
+
+# this creates a fake /dev/sda which confuses the bzImage bootup
+CONFIG_SCSI_DEBUG=n
+
+# can hang on a box without this hardware
+CONFIG_FB_CIRRUS=n
+CONFIG_FB_ASILIANT=n
+CONFIG_FB_VGA16=n
+CONFIG_FB_VESA=n
+CONFIG_FB_RADEON=n
+CONFIG_FB_CYBLA=n
+CONFIG_FB_VIRTUAL=n
+
+# can hang on a box without this hardware
+CONFIG_MDA_CONSOLE=n
+
+CONFIG_FRAMEBUFFER_CONSOLE=n
+
+# this ISA driver puts itself on IRQ10 - if IRQ10 happens to
+# trigger then that will cause a watchdog-initiated reboot
+CONFIG_EUROTECH_WDT=n
+
+# this ISA driver sits on IRQ11 by default - blocking forcedeth
+CONFIG_WDT=n
+
+# hangs a non-root-NFS box during bootup
+CONFIG_ROOT_NFS=n
+
+# auto-qa needs to see all messages
+CONFIG_LOG_BUF_SHIFT=20
+
+# Slows down bootup unnecessarily and does not catch bugs
+# by itself - so disable this.
+CONFIG_DEBUG_KOBJECT=n
+
+# too slow build in QA
+CONFIG_DEBUG_INFO=n
+
+# slow to build
+CONFIG_WANT_EXTRA_DEBUG_INFORMATION=n
+
+# fails with hard-to-debug "could not find init" boot failure
+CONFIG_SECURITY_ROOTPLUG=n
+
+# old system booted up with this cannot ssh out
+CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT=n
+
+# may hang on non-hardware
+CONFIG_SND_MTPAV=n
+
+# obsolete drivers
+CONFIG_SOUND_OSS=n
+
--
1.5.4.rc3.1118.gf6754c





2008-01-26 00:05:55

by Ingo Molnar

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24


* Peter Zijlstra <[email protected]> wrote:

> My wish is that distros would just boot without requiring an initrd. I
> know how to make them for redhat and debian based distros, but the
> fact that you can't (easily) cross-build them makes it a very tedious
> construct.

all it takes for me on Fedora is to boot a modular distro kernel once,
then copy the /dev to the real (persistent) /dev:

mkdir /tmp2
mount /dev/sda1 /tmp2
cp -a /dev/* /tmp2/dev/

and from that point on a bzImage/vmlinuz can boot up on Fedora without
any problems (as long as it has the right drivers built in), and the
initrd line can be removed from grub.conf.

Ingo

2008-01-26 00:28:36

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24


On Sat, 2008-01-26 at 01:05 +0100, Ingo Molnar wrote:
> * Peter Zijlstra <[email protected]> wrote:
>
> > My wish is that distros would just boot without requiring an initrd. I
> > know how to make them for redhat and debian based distros, but the
> > fact that you can't (easily) cross-build them makes it a very tedious
> > construct.
>
> all it takes for me on Fedora is to boot a modular distro kernel once,
> then copy the /dev to the real (persistent) /dev:
>
> mkdir /tmp2
> mount /dev/sda1 /tmp2
> cp -a /dev/* /tmp2/dev/
>
> and from that point on a bzImage/vmlinuz can boot up on Fedora without
> any problems (as long as it has the right drivers built in), and the
> initrd line can be removed from grub.conf.

Yeah, I usually do the same but with a bind mount, still it would be
grand if such things would not be needed.

2008-01-26 00:41:57

by Jon Masters

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24


On Sat, 2008-01-26 at 01:27 +0100, Peter Zijlstra wrote:
> On Sat, 2008-01-26 at 01:05 +0100, Ingo Molnar wrote:
> > * Peter Zijlstra <[email protected]> wrote:
> >
> > > My wish is that distros would just boot without requiring an initrd. I
> > > know how to make them for redhat and debian based distros, but the
> > > fact that you can't (easily) cross-build them makes it a very tedious
> > > construct.
> >
> > all it takes for me on Fedora is to boot a modular distro kernel once,
> > then copy the /dev to the real (persistent) /dev:
> >
> > mkdir /tmp2
> > mount /dev/sda1 /tmp2
> > cp -a /dev/* /tmp2/dev/
> >
> > and from that point on a bzImage/vmlinuz can boot up on Fedora without
> > any problems (as long as it has the right drivers built in), and the
> > initrd line can be removed from grub.conf.
>
> Yeah, I usually do the same but with a bind mount, still it would be
> grand if such things would not be needed.

Agreed. But it's not likely to be a priority - all the vendors want
completely modular kernels. But now we see what Linus wants to do,
perhaps we can try to be a bit more friendly toward that. It's not
actually rocket science, after all. I was concerned that he wanted to
use the modules in the initrd, but now I see Linus, and everyone else,
just want to do what I also secretly do, and just not use an initrd.

Isn't it funny. We all secretly hate using initrds ourselves :)

Jon.

2008-01-26 03:27:08

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Sat, 26 Jan 2008 01:05:26 +0100, Ingo Molnar said:

> all it takes for me on Fedora is to boot a modular distro kernel once,
> then copy the /dev to the real (persistent) /dev:
>
> mkdir /tmp2
> mount /dev/sda1 /tmp2
> cp -a /dev/* /tmp2/dev/
>
> and from that point on a bzImage/vmlinuz can boot up on Fedora without
> any problems (as long as it has the right drivers built in), and the
> initrd line can be removed from grub.conf.

Tried something like that once - it didn't play nice with the fact that I
have root-on-LVM, so you need an initrd to do the 'lvm vgchange -a' and get
it online.


Attachments:
(No filename) (226.00 B)

2008-01-26 03:29:31

by Olof Johansson

[permalink] [raw]
Subject: Re: [PATCH 063/196] kset: convert /sys/devices to use kset_create

On Thu, Jan 24, 2008 at 11:10:01PM -0800, Greg Kroah-Hartman wrote:
> Dynamically create the kset instead of declaring it statically. We also
> rename devices_subsys to devices_kset to catch all users of the
> variable.

Guess what, you broke powerpc again!

olof@quad:~/work/linux/k.org $ git grep devices_subsys
arch/powerpc/kernel/vio.c:extern struct kset devices_subsys; /* needed for vio_find_name() */
arch/powerpc/kernel/vio.c: found = kset_find_obj(&devices_subsys, kobj_name);

Obviously causes build failues, even of ppc64_defconfig.

(I can unfortunately not boot test, since I lack hardware that uses vio)


Signed-off-by: Olof Johansson <[email protected]>

diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
index 19a5656..ee752ab 100644
--- a/arch/powerpc/kernel/vio.c
+++ b/arch/powerpc/kernel/vio.c
@@ -37,7 +37,7 @@
#include <asm/iseries/hv_call_xm.h>
#include <asm/iseries/iommu.h>

-extern struct kset devices_subsys; /* needed for vio_find_name() */
+extern struct kset *devices_kset; /* needed for vio_find_name() */

static struct bus_type vio_bus_type;

@@ -369,7 +369,7 @@ static struct vio_dev *vio_find_name(const char *kobj_name)
{
struct kobject *found;

- found = kset_find_obj(&devices_subsys, kobj_name);
+ found = kset_find_obj(devices_kset, kobj_name);
if (!found)
return NULL;

2008-01-26 04:52:16

by Rusty Russell

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Saturday 26 January 2008 06:42:19 Greg KH wrote:
> On Fri, Jan 25, 2008 at 10:44:59AM -0800, Linus Torvalds wrote:
> > On Thu, 24 Jan 2008, Greg KH wrote:
> > > Here are a pretty large number of kobject, documentation, and driver
> > > core patches against your 2.6.24 git tree.
> >
> > I've merged it all, but it causes lots of scary warnings:
> >
> > - from the purely broken ones:
> >
> > ehci_hcd: no version for "struct_module" found: kernel tainted.
>
> Ok, in looking at the code, this should also be showing up for you on a
> "clean" 2.6.24 release, I didn't change anything in this code path.
>
> That is what taints your kernel with the "F" flag.
>
> > - to the scary ones:
> >
> > sysfs: duplicate filename 'ehci_hcd' can not be created
> > WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
> > Pid: 610, comm: insmod Tainted: GF 2.6.24-gb47711bf #28
> >
> > Call Trace:
> > [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
> > [<ffffffff802bdbc0>] create_dir+0x4f/0x87
> > [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
> > [<ffffffff803154c8>] kobject_get+0x12/0x17
> > [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
> > [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
> > [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
> > [<ffffffff80315321>] kobject_init+0x42/0x82
> > [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
> > [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
> > [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
> > [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
> > [<ffffffff8028ebd5>] dput+0x1c/0x10b
> > [<ffffffff8020b3be>] system_call+0x7e/0x83
>
> This is the sysfs core telling you that someone did something stupid :)
>
> Yes, that's new, but the "error" was always there, I just made the
> warning more visible to get people to pay attention to it, and find the
> real errors where this happens (and it has found them, which is a good
> thing.)
>
> But in this case, it doesn't look like the module loading code will
> detect that we are trying to load a module that is already present until
> the kobjects are set up here. It's been this way for a long time :(
>
> Rusty, any ideas of us adding a different check for "duplicate" modules
> like this earlier in the load_module() function, so we don't spend so
> much effort in building everything up when we don't need to?

module.c:1832 (in load_module)

if (find_module(mod->name)) {
err = -EEXIST;
goto free_mod;
}

That's pretty early, and before this backtrace.

Even for simultaneous loads, there's a mutex which protects from here to the
list insertion.

Puzzled,
Rusty.

2008-01-26 05:26:49

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 063/196] kset: convert /sys/devices to use kset_create

On Fri, Jan 25, 2008 at 09:40:55PM -0600, Olof Johansson wrote:
> On Thu, Jan 24, 2008 at 11:10:01PM -0800, Greg Kroah-Hartman wrote:
> > Dynamically create the kset instead of declaring it statically. We also
> > rename devices_subsys to devices_kset to catch all users of the
> > variable.
>
> Guess what, you broke powerpc again!

I did this ON PURPOSE!!!

The linux-kernel archives hold the details, and I was told by the PPC64
IBM people that they would fix this properly for 2.6.25, and not to hold
back on my changes. This has been known for many months now.

> olof@quad:~/work/linux/k.org $ git grep devices_subsys
> arch/powerpc/kernel/vio.c:extern struct kset devices_subsys; /* needed for vio_find_name() */
> arch/powerpc/kernel/vio.c: found = kset_find_obj(&devices_subsys, kobj_name);
>
> Obviously causes build failues, even of ppc64_defconfig.
>
> (I can unfortunately not boot test, since I lack hardware that uses vio)
>
>
> Signed-off-by: Olof Johansson <[email protected]>
>
> diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c
> index 19a5656..ee752ab 100644
> --- a/arch/powerpc/kernel/vio.c
> +++ b/arch/powerpc/kernel/vio.c
> @@ -37,7 +37,7 @@
> #include <asm/iseries/hv_call_xm.h>
> #include <asm/iseries/iommu.h>
>
> -extern struct kset devices_subsys; /* needed for vio_find_name() */
> +extern struct kset *devices_kset; /* needed for vio_find_name() */

No, this just papers over the real problem here. For some reason, the
vio code thinks it is acceptable to walk the whole device tree and match
by a name and just assume that they got the correct device. You call
this "enterprise grade"? :)

You need to just put your device on a real bus, and then just walk the
bus. That's the ONLY way you can guarantee the proper name will return
what you want, and you get the pointer that you really think you are
getting.

There is a reason that devices_kset is not exported, don't make me go
and have to name it something like:
devices_kset_dont_touch_this_or_gregkh_will_make_fun_of_you

Or I'll just mush 3 files in the driver core together and keep the
symbol from being accessible at all.

So no, I'm going to leave the build broken for this code, because that
is what it really is.

Please fix it correctly.

thanks,

greg k-h

2008-01-26 05:36:48

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 085/196] kset: convert s390 ipl.c to use kset_create

On Sat, Jan 26, 2008 at 12:11:33AM +0100, Heiko Carstens wrote:
> On Fri, Jan 25, 2008 at 09:48:58AM -0800, Greg KH wrote:
> > On Fri, Jan 25, 2008 at 01:20:53PM +0100, Heiko Carstens wrote:
> > > On Thu, Jan 24, 2008 at 11:31:54PM -0800, Greg Kroah-Hartman wrote:
> > > > Dynamically create the kset instead of declaring it statically.
> > > > This makes the kobject attributes now work properly that I broke in the
> > > > previous patch.
> > >
> > > Could you please merge this and the previous patch before it goes
> > > upstream? Having an intermediate state where things are broken
> > > will cause pain and additional work in case of bisecting.
> >
> > It will not cause a build error (see the previous patch for details.)
> > The sysfs files will not properly show the correct data, that is all.
> >
> > The odds that you will hit this in a 'git bisect' is VERY low, and the
> > previous patch states that the files are now broken, so there should not
> > be any confusion regarding any user that might run across this.
>
> The odds are very low, as long as not more patch sets come up which
> introduce intermediate broken kernels.
> What exactly is the advantage of breaking the kernel with patch 1 and
> then fix it again with patch 2 instead of doing the straight forward
> conversions all with one patch?

I was trying to do one logical thing at a time with this driver as I did
not have the hardware to test, and I could not even build the code at
the time.

In looking more closer, I think the 084 patch might still work properly,
but I can't guarantee it as the the default kobject parent might not be
pointing to the correct attribute at the time. I know 085 fixes this to
be sure that it will work properly.

It helped in reviewing this code by the other s390 developers to have
this in at least 2 pieces, to try to untangle the mess of sysfs files,
ksets, and other attrocities that you all have grown into over the
years.

So again, I'm sorry if this happens to break your run-time tests when
doing a 'git bisect', but as I explicitly stated it did in the patch, I
think everyone is properly forwarned :)

This core rework was tough to do, there was a reason no one had done it
before. Now it is cleaner, smaller, able to be understood by at least
one active kernel developer, if not more, and it's documented, with
working examples. If the downside of this effort is only this one thing
(note that others are finally finding real bugs...) I'll be very happy.

thanks,

greg k-h

2008-01-26 05:37:10

by Greg KH

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Sat, Jan 26, 2008 at 03:50:57PM +1100, Rusty Russell wrote:
> On Saturday 26 January 2008 06:42:19 Greg KH wrote:
> > On Fri, Jan 25, 2008 at 10:44:59AM -0800, Linus Torvalds wrote:
> > > On Thu, 24 Jan 2008, Greg KH wrote:
> > > > Here are a pretty large number of kobject, documentation, and driver
> > > > core patches against your 2.6.24 git tree.
> > >
> > > I've merged it all, but it causes lots of scary warnings:
> > >
> > > - from the purely broken ones:
> > >
> > > ehci_hcd: no version for "struct_module" found: kernel tainted.
> >
> > Ok, in looking at the code, this should also be showing up for you on a
> > "clean" 2.6.24 release, I didn't change anything in this code path.
> >
> > That is what taints your kernel with the "F" flag.
> >
> > > - to the scary ones:
> > >
> > > sysfs: duplicate filename 'ehci_hcd' can not be created
> > > WARNING: at fs/sysfs/dir.c:424 sysfs_add_one()
> > > Pid: 610, comm: insmod Tainted: GF 2.6.24-gb47711bf #28
> > >
> > > Call Trace:
> > > [<ffffffff802bd63c>] sysfs_add_one+0x54/0xbd
> > > [<ffffffff802bdbc0>] create_dir+0x4f/0x87
> > > [<ffffffff802bdc2d>] sysfs_create_dir+0x35/0x4a
> > > [<ffffffff803154c8>] kobject_get+0x12/0x17
> > > [<ffffffff80315607>] kobject_add_internal+0xd9/0x194
> > > [<ffffffff8031579c>] kobject_add_varg+0x54/0x61
> > > [<ffffffff80261efe>] __alloc_pages+0x66/0x2ee
> > > [<ffffffff80315321>] kobject_init+0x42/0x82
> > > [<ffffffff80315843>] kobject_init_and_add+0x9a/0xa7
> > > [<ffffffff802722c0>] __vmalloc_area_node+0x111/0x135
> > > [<ffffffff8025546b>] mod_sysfs_init+0x6e/0x83
> > > [<ffffffff802561e8>] sys_init_module+0xa3d/0x1833
> > > [<ffffffff8028ebd5>] dput+0x1c/0x10b
> > > [<ffffffff8020b3be>] system_call+0x7e/0x83
> >
> > This is the sysfs core telling you that someone did something stupid :)
> >
> > Yes, that's new, but the "error" was always there, I just made the
> > warning more visible to get people to pay attention to it, and find the
> > real errors where this happens (and it has found them, which is a good
> > thing.)
> >
> > But in this case, it doesn't look like the module loading code will
> > detect that we are trying to load a module that is already present until
> > the kobjects are set up here. It's been this way for a long time :(
> >
> > Rusty, any ideas of us adding a different check for "duplicate" modules
> > like this earlier in the load_module() function, so we don't spend so
> > much effort in building everything up when we don't need to?
>
> module.c:1832 (in load_module)
>
> if (find_module(mod->name)) {
> err = -EEXIST;
> goto free_mod;
> }
>
> That's pretty early, and before this backtrace.

But that doesn't catch the case here, of trying to load a module when
the code itself is already built into the kernel. For that we are
relying on the sysfs core to tell us we have a duplicate name problem,
which happens much later.

Is there any test you can do sooner, or is relying on the sysfs test
acceptable?

thanks,

greg k-h

2008-01-26 06:31:51

by Arjan van de Ven

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Fri, 25 Jan 2008 11:11:48 -0800 (PST)
Linus Torvalds <[email protected]> wrote:

>
>
> On Fri, 25 Jan 2008, Greg KH wrote:
> >
> > That's really wierd, I don't see that at all here just running with
> > your 2.6.24 + my git tree and lots of USB drivers built into the
> > kernel also (like ehci_hcd).
>
> But do you use an initrd that tries to load the same driver too?
>
> I'm too lazy to want to do my own initrd. I just use the prepackaged
> ones and rely on the fact that my private kernel will refuse to load
> modules that aren't meant for it anyway.
>

you know about "make install" right? That copies the needed files to /boot,
adds them to grub AND makes an initrd for you.. all for free ;)


--
If you want to reach me at my work email, use [email protected]
For development, discussion and tips for power savings,
visit http://www.lesswatts.org

2008-01-26 09:20:11

by Rusty Russell

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Saturday 26 January 2008 16:35:09 Greg KH wrote:
> On Sat, Jan 26, 2008 at 03:50:57PM +1100, Rusty Russell wrote:
> > That's pretty early, and before this backtrace.
>
> But that doesn't catch the case here, of trying to load a module when
> the code itself is already built into the kernel.

Ah, I missed that, sorry.

> For that we are
> relying on the sysfs core to tell us we have a duplicate name problem,
> which happens much later.
>
> Is there any test you can do sooner, or is relying on the sysfs test
> acceptable?

As you pointed out, that's always been a "configure your kernel correctly,
stupid" kind of bug. Nicer would be to have a list of in-kernel "modules"
generated by the build system, but sysfs is there and it's easy to hang our
hats off...

So, no objections to this with that as a FIXME, and a change so the message
says "module is already built into the kernel".

Thanks,
Rusty.

2008-01-26 17:24:24

by Olof Johansson

[permalink] [raw]
Subject: Re: [PATCH 063/196] kset: convert /sys/devices to use kset_create

On Fri, Jan 25, 2008 at 09:24:54PM -0800, Greg KH wrote:
> On Fri, Jan 25, 2008 at 09:40:55PM -0600, Olof Johansson wrote:
> > On Thu, Jan 24, 2008 at 11:10:01PM -0800, Greg Kroah-Hartman wrote:
> > > Dynamically create the kset instead of declaring it statically. We also
> > > rename devices_subsys to devices_kset to catch all users of the
> > > variable.
> >
> > Guess what, you broke powerpc again!
>
> I did this ON PURPOSE!!!
>
> The linux-kernel archives hold the details, and I was told by the PPC64
> IBM people that they would fix this properly for 2.6.25, and not to hold
> back on my changes. This has been known for many months now.

Yeah, my bad. :( I thought this was new, but it was just not exposed by
my scripts because of the EHEA build errors (they were actual compile
errors, while this was a link error, so it never go this far). That's
why I didn't see it in -rc8-mm1 and thought it was new.

> > -extern struct kset devices_subsys; /* needed for vio_find_name() */
> > +extern struct kset *devices_kset; /* needed for vio_find_name() */
>
> No, this just papers over the real problem here. For some reason, the
> vio code thinks it is acceptable to walk the whole device tree and match
> by a name and just assume that they got the correct device. You call
> this "enterprise grade"? :)
>
> You need to just put your device on a real bus, and then just walk the
> bus. That's the ONLY way you can guarantee the proper name will return
> what you want, and you get the pointer that you really think you are
> getting.

Hmm, they are already on a bus. Odd, must be done like this for legacy
reasons.

[...]

> So no, I'm going to leave the build broken for this code, because that
> is what it really is.
>
> Please fix it correctly.

Alright, I'll leave that to people who care about vio and can test the
proper fix. After a quick glance it looks like it should be easy to use
bus_find_device() for it instead.


-Olof

2008-01-27 06:43:19

by Linus Torvalds

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24



On Sat, 26 Jan 2008, Rusty Russell wrote:
>
> module.c:1832 (in load_module)
>
> if (find_module(mod->name)) {
> err = -EEXIST;
> goto free_mod;
> }
>
> That's pretty early, and before this backtrace.
>
> Even for simultaneous loads, there's a mutex which protects from here to the
> list insertion.

My problem isn't trying to load the same module twice.

My problem is that the *driver* already exists (because it's compiled in),
and has already initialized itself, and has already registered.

Then, initrd tries to load an old module for that driver.

So no simultaneous loading, no two modules, simple two *drivers* with the
same module names - but one was compiled in, and the other will fail
because it doesn't have the required linkages (ie it will failt the
modversions checks).

But even before it fails the modversion checks, it apparently does various
ugly things that clash with the built-in driver.

At least that seems to be the case.

Linus

2008-01-28 08:27:46

by Helge Hafting

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

Peter Zijlstra wrote:
> My wish is that distros would just boot without requiring an initrd. I
> know how to make them for redhat and debian based distros, but the fact
> that you can't (easily) cross-build them makes it a very tedious
> construct.
>
Debian is easy enough - make sure the drivers for the root
device and root fs is built-in, and you can drop the initrd.
Takes a second or two off the boot, and some more off the build.

Helge Hafting

2008-01-28 22:10:40

by Jan Engelhardt

[permalink] [raw]
Subject: Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add


On Jan 25 2008 09:45, Greg KH wrote:
>>
>> Okay, but where is the new kobject freed?
>
>In the call to kobject_unregister(), which has then later in the series
>been converted to a call to kobject_put().
>
Hm, working on LDD 3.1? :-)

2008-01-28 23:23:08

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH 108/196] Kobject: change net/bridge to use kobject_create_and_add

On Mon, Jan 28, 2008 at 11:09:24PM +0100, Jan Engelhardt wrote:
>
> On Jan 25 2008 09:45, Greg KH wrote:
> >>
> >> Okay, but where is the new kobject freed?
> >
> >In the call to kobject_unregister(), which has then later in the series
> >been converted to a call to kobject_put().
> >
> Hm, working on LDD 3.1? :-)

No, unfortunatly :(

Actually, the documentation that was written in this patch series, would
be good to replace the existing kobject documentation in LDD 3. But
it's a bit hard to just replace a chapter at a time in a book that is
already published, we really don't have the mechanism in place for such
a thing...

thanks,

greg k-h

2008-01-29 05:50:37

by Rusty Russell

[permalink] [raw]
Subject: Re: [GIT PATCH] driver core patches against 2.6.24

On Sunday 27 January 2008 17:42:28 Linus Torvalds wrote:
> My problem is that the *driver* already exists (because it's compiled in),
> and has already initialized itself, and has already registered.
>
> Then, initrd tries to load an old module for that driver.

I hate to say it, but this is user error. And it used to be that for some
drivers you'd actually end up with two in-kernel if you did that.

But if even *you* don't get this right, it should finally prompt us to fix
this...

Thanks,
Rusty.