Commit 21351dbe authored by Kristian Høgsberg's avatar Kristian Høgsberg Committed by Stefan Richter

firewire: Make use of struct device_type.

The device_type struct is useful for setting attributes for a device
and overriding .release and .uevent for a group of devices.  This patch
uses it this way to clean up the sysfs code a bit.
Signed-off-by: default avatarKristian Høgsberg <krh@redhat.com>
Signed-off-by: default avatarStefan Richter <stefanr@s5r6.in-berlin.de>
parent 945ac222
...@@ -138,9 +138,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp, ...@@ -138,9 +138,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp,
int length = 0; int length = 0;
int i = 0; int i = 0;
if (!is_fw_unit(dev))
goto out;
get_modalias(unit, modalias, sizeof modalias); get_modalias(unit, modalias, sizeof modalias);
if (add_uevent_var(envp, num_envp, &i, if (add_uevent_var(envp, num_envp, &i,
...@@ -148,7 +145,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp, ...@@ -148,7 +145,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp,
"MODALIAS=%s", modalias)) "MODALIAS=%s", modalias))
return -ENOMEM; return -ENOMEM;
out:
envp[i] = NULL; envp[i] = NULL;
return 0; return 0;
...@@ -157,7 +153,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp, ...@@ -157,7 +153,6 @@ fw_unit_uevent(struct device *dev, char **envp, int num_envp,
struct bus_type fw_bus_type = { struct bus_type fw_bus_type = {
.name = "firewire", .name = "firewire",
.match = fw_unit_match, .match = fw_unit_match,
.uevent = fw_unit_uevent,
}; };
EXPORT_SYMBOL(fw_bus_type); EXPORT_SYMBOL(fw_bus_type);
...@@ -199,8 +194,8 @@ int fw_device_enable_phys_dma(struct fw_device *device) ...@@ -199,8 +194,8 @@ int fw_device_enable_phys_dma(struct fw_device *device)
EXPORT_SYMBOL(fw_device_enable_phys_dma); EXPORT_SYMBOL(fw_device_enable_phys_dma);
static ssize_t static ssize_t
show_modalias_attribute(struct device *dev, modalias_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct fw_unit *unit = fw_unit(dev); struct fw_unit *unit = fw_unit(dev);
int length; int length;
...@@ -211,41 +206,37 @@ show_modalias_attribute(struct device *dev, ...@@ -211,41 +206,37 @@ show_modalias_attribute(struct device *dev,
return length + 1; return length + 1;
} }
static struct device_attribute modalias_attribute = {
.attr = { .name = "modalias", .mode = S_IRUGO, },
.show = show_modalias_attribute,
};
static ssize_t static ssize_t
show_config_rom_attribute(struct device *dev, rom_index_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct fw_device *device = fw_device(dev); struct fw_device *device = fw_device(dev->parent);
struct fw_unit *unit = fw_unit(dev);
memcpy(buf, device->config_rom, device->config_rom_length * 4);
return device->config_rom_length * 4; return snprintf(buf, PAGE_SIZE, "%d\n",
(int)(unit->directory - device->config_rom));
} }
static struct device_attribute config_rom_attribute = { static struct device_attribute fw_unit_attributes[] = {
.attr = {.name = "config_rom", .mode = S_IRUGO,}, __ATTR_RO(modalias),
.show = show_config_rom_attribute, __ATTR_RO(rom_index),
__ATTR_NULL,
}; };
static ssize_t static ssize_t
show_rom_index_attribute(struct device *dev, config_rom_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct fw_device *device = fw_device(dev->parent); struct fw_device *device = fw_device(dev);
struct fw_unit *unit = fw_unit(dev);
return snprintf(buf, PAGE_SIZE, "%d\n", memcpy(buf, device->config_rom, device->config_rom_length * 4);
(int)(unit->directory - device->config_rom));
return device->config_rom_length * 4;
} }
static struct device_attribute rom_index_attribute = { static struct device_attribute fw_device_attributes[] = {
.attr = { .name = "rom_index", .mode = S_IRUGO, }, __ATTR_RO(config_rom),
.show = show_rom_index_attribute, __ATTR_NULL,
}; };
struct read_quadlet_callback_data { struct read_quadlet_callback_data {
...@@ -370,9 +361,15 @@ static void fw_unit_release(struct device *dev) ...@@ -370,9 +361,15 @@ static void fw_unit_release(struct device *dev)
kfree(unit); kfree(unit);
} }
static struct device_type fw_unit_type = {
.attrs = fw_unit_attributes,
.uevent = fw_unit_uevent,
.release = fw_unit_release,
};
static int is_fw_unit(struct device *dev) static int is_fw_unit(struct device *dev)
{ {
return dev->release == fw_unit_release; return dev->type == &fw_unit_type;
} }
static void create_units(struct fw_device *device) static void create_units(struct fw_device *device)
...@@ -397,7 +394,7 @@ static void create_units(struct fw_device *device) ...@@ -397,7 +394,7 @@ static void create_units(struct fw_device *device)
unit->directory = ci.p + value - 1; unit->directory = ci.p + value - 1;
unit->device.bus = &fw_bus_type; unit->device.bus = &fw_bus_type;
unit->device.release = fw_unit_release; unit->device.type = &fw_unit_type;
unit->device.parent = &device->device; unit->device.parent = &device->device;
snprintf(unit->device.bus_id, sizeof unit->device.bus_id, snprintf(unit->device.bus_id, sizeof unit->device.bus_id,
"%s.%d", device->device.bus_id, i++); "%s.%d", device->device.bus_id, i++);
...@@ -406,27 +403,12 @@ static void create_units(struct fw_device *device) ...@@ -406,27 +403,12 @@ static void create_units(struct fw_device *device)
kfree(unit); kfree(unit);
continue; continue;
} }
if (device_create_file(&unit->device, &modalias_attribute) < 0) {
device_unregister(&unit->device);
kfree(unit);
}
if (device_create_file(&unit->device, &rom_index_attribute) < 0) {
device_unregister(&unit->device);
kfree(unit);
}
} }
} }
static int shutdown_unit(struct device *device, void *data) static int shutdown_unit(struct device *device, void *data)
{ {
struct fw_unit *unit = fw_unit(device); device_unregister(device);
if (is_fw_unit(device)) {
device_remove_file(&unit->device, &modalias_attribute);
device_unregister(&unit->device);
}
return 0; return 0;
} }
...@@ -456,11 +438,15 @@ static void fw_device_shutdown(struct work_struct *work) ...@@ -456,11 +438,15 @@ static void fw_device_shutdown(struct work_struct *work)
up_write(&fw_bus_type.subsys.rwsem); up_write(&fw_bus_type.subsys.rwsem);
fw_device_cdev_remove(device); fw_device_cdev_remove(device);
device_remove_file(&device->device, &config_rom_attribute);
device_for_each_child(&device->device, NULL, shutdown_unit); device_for_each_child(&device->device, NULL, shutdown_unit);
device_unregister(&device->device); device_unregister(&device->device);
} }
static struct device_type fw_device_type = {
.attrs = fw_device_attributes,
.release = fw_device_release,
};
/* These defines control the retry behavior for reading the config /* These defines control the retry behavior for reading the config
* rom. It shouldn't be necessary to tweak these; if the device * rom. It shouldn't be necessary to tweak these; if the device
* doesn't respond to a config rom read within 10 seconds, it's not * doesn't respond to a config rom read within 10 seconds, it's not
...@@ -507,7 +493,7 @@ static void fw_device_init(struct work_struct *work) ...@@ -507,7 +493,7 @@ static void fw_device_init(struct work_struct *work)
goto error; goto error;
device->device.bus = &fw_bus_type; device->device.bus = &fw_bus_type;
device->device.release = fw_device_release; device->device.type = &fw_device_type;
device->device.parent = device->card->device; device->device.parent = device->card->device;
device->device.devt = MKDEV(fw_cdev_major, minor); device->device.devt = MKDEV(fw_cdev_major, minor);
snprintf(device->device.bus_id, sizeof device->device.bus_id, snprintf(device->device.bus_id, sizeof device->device.bus_id,
...@@ -518,11 +504,6 @@ static void fw_device_init(struct work_struct *work) ...@@ -518,11 +504,6 @@ static void fw_device_init(struct work_struct *work)
goto error_with_cdev; goto error_with_cdev;
} }
if (device_create_file(&device->device, &config_rom_attribute) < 0) {
fw_error("Failed to create config rom file.\n");
goto error_with_device;
}
create_units(device); create_units(device);
/* Transition the device to running state. If it got pulled /* Transition the device to running state. If it got pulled
...@@ -549,8 +530,6 @@ static void fw_device_init(struct work_struct *work) ...@@ -549,8 +530,6 @@ static void fw_device_init(struct work_struct *work)
return; return;
error_with_device:
device_del(&device->device);
error_with_cdev: error_with_cdev:
down_write(&fw_bus_type.subsys.rwsem); down_write(&fw_bus_type.subsys.rwsem);
idr_remove(&fw_device_idr, minor); idr_remove(&fw_device_idr, minor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment