From: "Michael S. Tsirkin" <mst@redhat.com>
To: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 3/3] virtio: add drv_to_virtio to make code clearly
Date: Wed, 5 Dec 2012 13:17:47 +0200 [thread overview]
Message-ID: <20121205111747.GA10446@redhat.com> (raw)
In-Reply-To: <1354691009-25966-3-git-send-email-gaowanlong@cn.fujitsu.com>
On Wed, Dec 05, 2012 at 03:03:29PM +0800, Wanlong Gao wrote:
> Add drv_to_virtio wrapper to get virtio_driver from device_driver.
>
> Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
IMHO a function would be slightly better.
> ---
> drivers/virtio/virtio.c | 11 ++++-------
> include/linux/virtio.h | 1 +
> 2 files changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index 1346ae8..1c01ac3 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -73,7 +73,7 @@ static int virtio_dev_match(struct device *_dv, struct device_driver *_dr)
> struct virtio_device *dev = dev_to_virtio(_dv);
> 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++)
> if (virtio_id_match(dev, &ids[i]))
> return 1;
> @@ -97,8 +97,7 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
> unsigned int fbit)
> {
> unsigned int i;
> - struct virtio_driver *drv = container_of(vdev->dev.driver,
> - struct virtio_driver, driver);
> + struct virtio_driver *drv = drv_to_virtio(vdev->dev.driver);
>
> for (i = 0; i < drv->feature_table_size; i++)
> if (drv->feature_table[i] == fbit)
> @@ -111,8 +110,7 @@ static int virtio_dev_probe(struct device *_d)
> {
> int err, i;
> struct virtio_device *dev = dev_to_virtio(_d);
> - struct virtio_driver *drv = container_of(dev->dev.driver,
> - struct virtio_driver, driver);
> + struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
> u32 device_features;
>
> /* We have a driver! */
> @@ -152,8 +150,7 @@ static int virtio_dev_probe(struct device *_d)
> static int virtio_dev_remove(struct device *_d)
> {
> struct virtio_device *dev = dev_to_virtio(_d);
> - struct virtio_driver *drv = container_of(dev->dev.driver,
> - struct virtio_driver, driver);
> + struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
>
> drv->remove(dev);
>
> diff --git a/include/linux/virtio.h b/include/linux/virtio.h
> index 30fc3c9..8da5811 100644
> --- a/include/linux/virtio.h
> +++ b/include/linux/virtio.h
> @@ -109,6 +109,7 @@ struct virtio_driver {
> #endif
> };
>
> +#define drv_to_virtio(drv) container_of(drv, struct virtio_driver, driver)
> int register_virtio_driver(struct virtio_driver *drv);
> void unregister_virtio_driver(struct virtio_driver *drv);
> #endif /* _LINUX_VIRTIO_H */
> --
> 1.8.0
next prev parent reply other threads:[~2012-12-05 11:17 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-05 7:03 [PATCH 1/3] virtio: change to_vp_device to an inlined definition Wanlong Gao
2012-12-05 7:03 ` [PATCH 2/3] virtio: use dev_to_virtio wrapper in virtio Wanlong Gao
2012-12-05 11:16 ` Michael S. Tsirkin
2012-12-05 11:17 ` Michael S. Tsirkin
2012-12-05 12:59 ` Wanlong Gao
2012-12-05 7:03 ` [PATCH 3/3] virtio: add drv_to_virtio to make code clearly Wanlong Gao
2012-12-05 11:17 ` Michael S. Tsirkin [this message]
2012-12-05 11:25 ` [PATCH 1/3] virtio: change to_vp_device to an inlined definition Michael S. Tsirkin
2012-12-05 13:28 ` [PATCH V2 1/2] virtio: use dev_to_virtio wrapper in virtio Wanlong Gao
2012-12-05 13:28 ` [PATCH V2 2/2] virtio: add drv_to_virtio to make code clearly Wanlong Gao
2012-12-05 22:28 ` [PATCH 1/3] virtio: change to_vp_device to an inlined definition Stephen Hemminger
2012-12-05 23:28 ` Rusty Russell
2012-12-05 23:21 ` Rusty Russell
2012-12-06 6:10 ` Wanlong Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121205111747.GA10446@redhat.com \
--to=mst@redhat.com \
--cc=gaowanlong@cn.fujitsu.com \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.