aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWanlong Gao <gaowanlong@cn.fujitsu.com>2012-12-10 19:34:50 -0500
committerRusty Russell <rusty@rustcorp.com.au>2012-12-17 23:50:42 -0500
commit9bffdca8c64a72ac54c47a552734ab457bc720d4 (patch)
treec009f6f19b689ceac28122a2ea7109b4fccada95
parent40f9938c4c69183c5ceaca74b77aff636cc79623 (diff)
virtio: use dev_to_virtio wrapper in virtio
Use dev_to_virtio wrapper in virtio to make code clearly. Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: "Michael S. Tsirkin" <mst@redhat.com> Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--drivers/virtio/virtio.c19
-rw-r--r--include/linux/virtio.h6
2 files changed, 14 insertions, 11 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 1e8659ca27ef..1346ae8e14f3 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -10,33 +10,32 @@ static DEFINE_IDA(virtio_index_ida);
10static ssize_t device_show(struct device *_d, 10static ssize_t device_show(struct device *_d,
11 struct device_attribute *attr, char *buf) 11 struct device_attribute *attr, char *buf)
12{ 12{
13 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 13 struct virtio_device *dev = dev_to_virtio(_d);
14 return sprintf(buf, "0x%04x\n", dev->id.device); 14 return sprintf(buf, "0x%04x\n", dev->id.device);
15} 15}
16static ssize_t vendor_show(struct device *_d, 16static ssize_t vendor_show(struct device *_d,
17 struct device_attribute *attr, char *buf) 17 struct device_attribute *attr, char *buf)
18{ 18{
19 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 19 struct virtio_device *dev = dev_to_virtio(_d);
20 return sprintf(buf, "0x%04x\n", dev->id.vendor); 20 return sprintf(buf, "0x%04x\n", dev->id.vendor);
21} 21}
22static ssize_t status_show(struct device *_d, 22static ssize_t status_show(struct device *_d,
23 struct device_attribute *attr, char *buf) 23 struct device_attribute *attr, char *buf)
24{ 24{
25 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 25 struct virtio_device *dev = dev_to_virtio(_d);
26 return sprintf(buf, "0x%08x\n", dev->config->get_status(dev)); 26 return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
27} 27}
28static ssize_t modalias_show(struct device *_d, 28static ssize_t modalias_show(struct device *_d,
29 struct device_attribute *attr, char *buf) 29 struct device_attribute *attr, char *buf)
30{ 30{
31 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 31 struct virtio_device *dev = dev_to_virtio(_d);
32
33 return sprintf(buf, "virtio:d%08Xv%08X\n", 32 return sprintf(buf, "virtio:d%08Xv%08X\n",
34 dev->id.device, dev->id.vendor); 33 dev->id.device, dev->id.vendor);
35} 34}
36static ssize_t features_show(struct device *_d, 35static ssize_t features_show(struct device *_d,
37 struct device_attribute *attr, char *buf) 36 struct device_attribute *attr, char *buf)
38{ 37{
39 struct virtio_device *dev = container_of(_d, struct virtio_device, dev); 38 struct virtio_device *dev = dev_to_virtio(_d);
40 unsigned int i; 39 unsigned int i;
41 ssize_t len = 0; 40 ssize_t len = 0;
42 41
@@ -71,7 +70,7 @@ static inline int virtio_id_match(const struct virtio_device *dev,
71static int virtio_dev_match(struct device *_dv, struct device_driver *_dr) 70static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
72{ 71{
73 unsigned int i; 72 unsigned int i;
74 struct virtio_device *dev = container_of(_dv,struct virtio_device,dev); 73 struct virtio_device *dev = dev_to_virtio(_dv);
75 const struct virtio_device_id *ids; 74 const struct virtio_device_id *ids;
76 75
77 ids = container_of(_dr, struct virtio_driver, driver)->id_table; 76 ids = container_of(_dr, struct virtio_driver, driver)->id_table;
@@ -83,7 +82,7 @@ static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
83 82
84static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env) 83static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env)
85{ 84{
86 struct virtio_device *dev = container_of(_dv,struct virtio_device,dev); 85 struct virtio_device *dev = dev_to_virtio(_dv);
87 86
88 return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X", 87 return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X",
89 dev->id.device, dev->id.vendor); 88 dev->id.device, dev->id.vendor);
@@ -111,7 +110,7 @@ EXPORT_SYMBOL_GPL(virtio_check_driver_offered_feature);
111static int virtio_dev_probe(struct device *_d) 110static int virtio_dev_probe(struct device *_d)
112{ 111{
113 int err, i; 112 int err, i;
114 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 113 struct virtio_device *dev = dev_to_virtio(_d);
115 struct virtio_driver *drv = container_of(dev->dev.driver, 114 struct virtio_driver *drv = container_of(dev->dev.driver,
116 struct virtio_driver, driver); 115 struct virtio_driver, driver);
117 u32 device_features; 116 u32 device_features;
@@ -152,7 +151,7 @@ static int virtio_dev_probe(struct device *_d)
152 151
153static int virtio_dev_remove(struct device *_d) 152static int virtio_dev_remove(struct device *_d)
154{ 153{
155 struct virtio_device *dev = container_of(_d,struct virtio_device,dev); 154 struct virtio_device *dev = dev_to_virtio(_d);
156 struct virtio_driver *drv = container_of(dev->dev.driver, 155 struct virtio_driver *drv = container_of(dev->dev.driver,
157 struct virtio_driver, driver); 156 struct virtio_driver, driver);
158 157
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 4b8f17d90458..5f1f80c76468 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -85,7 +85,11 @@ struct virtio_device {
85 void *priv; 85 void *priv;
86}; 86};
87 87
88#define dev_to_virtio(dev) container_of(dev, struct virtio_device, dev) 88static inline struct virtio_device *dev_to_virtio(struct device *_dev)
89{
90 return container_of(_dev, struct virtio_device, dev);
91}
92
89int register_virtio_device(struct virtio_device *dev); 93int register_virtio_device(struct virtio_device *dev);
90void unregister_virtio_device(struct virtio_device *dev); 94void unregister_virtio_device(struct virtio_device *dev);
91 95