mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-03-01 15:09:40 +07:00
virtio: add drv_to_virtio to make code clearly
Add drv_to_virtio wrapper to get virtio_driver from device_driver. 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>
This commit is contained in:
parent
9bffdca8c6
commit
9a2bdcc85d
@ -73,7 +73,7 @@ static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
|
|||||||
struct virtio_device *dev = dev_to_virtio(_dv);
|
struct virtio_device *dev = dev_to_virtio(_dv);
|
||||||
const struct virtio_device_id *ids;
|
const struct virtio_device_id *ids;
|
||||||
|
|
||||||
ids = container_of(_dr, struct virtio_driver, driver)->id_table;
|
ids = drv_to_virtio(_dr)->id_table;
|
||||||
for (i = 0; ids[i].device; i++)
|
for (i = 0; ids[i].device; i++)
|
||||||
if (virtio_id_match(dev, &ids[i]))
|
if (virtio_id_match(dev, &ids[i]))
|
||||||
return 1;
|
return 1;
|
||||||
@ -97,8 +97,7 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
|
|||||||
unsigned int fbit)
|
unsigned int fbit)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct virtio_driver *drv = container_of(vdev->dev.driver,
|
struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
|
||||||
struct virtio_driver, driver);
|
|
||||||
|
|
||||||
for (i = 0; i < drv->feature_table_size; i++)
|
for (i = 0; i < drv->feature_table_size; i++)
|
||||||
if (drv->feature_table[i] == fbit)
|
if (drv->feature_table[i] == fbit)
|
||||||
@ -111,8 +110,7 @@ static int virtio_dev_probe(struct device *_d)
|
|||||||
{
|
{
|
||||||
int err, i;
|
int err, i;
|
||||||
struct virtio_device *dev = dev_to_virtio(_d);
|
struct virtio_device *dev = dev_to_virtio(_d);
|
||||||
struct virtio_driver *drv = container_of(dev->dev.driver,
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
||||||
struct virtio_driver, driver);
|
|
||||||
u32 device_features;
|
u32 device_features;
|
||||||
|
|
||||||
/* We have a driver! */
|
/* We have a driver! */
|
||||||
@ -152,8 +150,7 @@ static int virtio_dev_probe(struct device *_d)
|
|||||||
static int virtio_dev_remove(struct device *_d)
|
static int virtio_dev_remove(struct device *_d)
|
||||||
{
|
{
|
||||||
struct virtio_device *dev = dev_to_virtio(_d);
|
struct virtio_device *dev = dev_to_virtio(_d);
|
||||||
struct virtio_driver *drv = container_of(dev->dev.driver,
|
struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
|
||||||
struct virtio_driver, driver);
|
|
||||||
|
|
||||||
drv->remove(dev);
|
drv->remove(dev);
|
||||||
|
|
||||||
|
@ -119,6 +119,11 @@ struct virtio_driver {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv)
|
||||||
|
{
|
||||||
|
return container_of(drv, struct virtio_driver, driver);
|
||||||
|
}
|
||||||
|
|
||||||
int register_virtio_driver(struct virtio_driver *drv);
|
int register_virtio_driver(struct virtio_driver *drv);
|
||||||
void unregister_virtio_driver(struct virtio_driver *drv);
|
void unregister_virtio_driver(struct virtio_driver *drv);
|
||||||
#endif /* _LINUX_VIRTIO_H */
|
#endif /* _LINUX_VIRTIO_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user