提交 16ffadfc 编写于 作者: D David Brownell 提交者: Jean Delvare

i2c: Class attribute cleanup

This patch is a minor cleanup/code shrink, using class infrastructure
in i2c-core to manage the i2c_adapter attribute.
Signed-off-by: NDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: NJean Delvare <khali@linux-fr.org>
上级 2096b956
...@@ -64,16 +64,6 @@ static u32 isa_func(struct i2c_adapter *adapter) ...@@ -64,16 +64,6 @@ static u32 isa_func(struct i2c_adapter *adapter)
} }
/* Copied from i2c-core */
static ssize_t show_adapter_name(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
return sprintf(buf, "%s\n", adap->name);
}
static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
/* We implement an interface which resembles i2c_{add,del}_driver, /* We implement an interface which resembles i2c_{add,del}_driver,
but for i2c-isa drivers. We don't have to remember and handle lists but for i2c-isa drivers. We don't have to remember and handle lists
of drivers and adapters so this is much more simple, of course. */ of drivers and adapters so this is much more simple, of course. */
...@@ -146,20 +136,11 @@ static int __init i2c_isa_init(void) ...@@ -146,20 +136,11 @@ static int __init i2c_isa_init(void)
printk(KERN_ERR "i2c-isa: Failed to register device\n"); printk(KERN_ERR "i2c-isa: Failed to register device\n");
goto exit; goto exit;
} }
err = device_create_file(&isa_adapter.dev, &dev_attr_name);
if (err) {
printk(KERN_ERR "i2c-isa: Failed to create name file\n");
goto exit_unregister;
}
dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
return 0; return 0;
exit_unregister:
init_completion(&isa_adapter.dev_released); /* Needed? */
device_unregister(&isa_adapter.dev);
wait_for_completion(&isa_adapter.dev_released);
exit: exit:
return err; return err;
} }
...@@ -187,7 +168,6 @@ static void __exit i2c_isa_exit(void) ...@@ -187,7 +168,6 @@ static void __exit i2c_isa_exit(void)
/* Clean up the sysfs representation */ /* Clean up the sysfs representation */
dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
init_completion(&isa_adapter.dev_released); init_completion(&isa_adapter.dev_released);
device_remove_file(&isa_adapter.dev, &dev_attr_name);
device_unregister(&isa_adapter.dev); device_unregister(&isa_adapter.dev);
/* Wait for sysfs to drop all references */ /* Wait for sysfs to drop all references */
......
...@@ -107,28 +107,32 @@ struct bus_type i2c_bus_type = { ...@@ -107,28 +107,32 @@ struct bus_type i2c_bus_type = {
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* I2C bus adapters -- one roots each I2C or SMBUS segment */
void i2c_adapter_dev_release(struct device *dev) void i2c_adapter_dev_release(struct device *dev)
{ {
struct i2c_adapter *adap = dev_to_i2c_adapter(dev); struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
complete(&adap->dev_released); complete(&adap->dev_released);
} }
/* ------------------------------------------------------------------------- */ static ssize_t
show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
{
struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
return sprintf(buf, "%s\n", adap->name);
}
/* I2C bus adapters -- one roots each I2C or SMBUS segment */ static struct device_attribute i2c_adapter_attrs[] = {
__ATTR(name, S_IRUGO, show_adapter_name, NULL),
{ },
};
struct class i2c_adapter_class = { struct class i2c_adapter_class = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.name = "i2c-adapter", .name = "i2c-adapter",
.dev_attrs = i2c_adapter_attrs,
}; };
static ssize_t show_adapter_name(struct device *dev, struct device_attribute *attr, char *buf)
{
struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
return sprintf(buf, "%s\n", adap->name);
}
static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
static void i2c_client_release(struct device *dev) static void i2c_client_release(struct device *dev)
{ {
...@@ -201,9 +205,6 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -201,9 +205,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
res = device_register(&adap->dev); res = device_register(&adap->dev);
if (res) if (res)
goto out_list; goto out_list;
res = device_create_file(&adap->dev, &dev_attr_name);
if (res)
goto out_unregister;
dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
...@@ -219,10 +220,6 @@ int i2c_add_adapter(struct i2c_adapter *adap) ...@@ -219,10 +220,6 @@ int i2c_add_adapter(struct i2c_adapter *adap)
mutex_unlock(&core_lists); mutex_unlock(&core_lists);
return res; return res;
out_unregister:
init_completion(&adap->dev_released); /* Needed? */
device_unregister(&adap->dev);
wait_for_completion(&adap->dev_released);
out_list: out_list:
list_del(&adap->list); list_del(&adap->list);
idr_remove(&i2c_adapter_idr, adap->nr); idr_remove(&i2c_adapter_idr, adap->nr);
...@@ -278,7 +275,6 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -278,7 +275,6 @@ int i2c_del_adapter(struct i2c_adapter *adap)
/* clean up the sysfs representation */ /* clean up the sysfs representation */
init_completion(&adap->dev_released); init_completion(&adap->dev_released);
device_remove_file(&adap->dev, &dev_attr_name);
device_unregister(&adap->dev); device_unregister(&adap->dev);
list_del(&adap->list); list_del(&adap->list);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册