Haiyang Zhang
2011-Feb-23 20:19 UTC
[PATCH 1/4] staging: hv: Fix the code depending on struct vmbus_driver_context data order
The patch fixed the code depending on the exact order of fields in the struct vmbus_driver_context, so the unused field drv_ctx can be removed, and drv_obj doesn't have to be the second field in this structure. Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> Signed-off-by: Hank Janssen <hjanssen at microsoft.com> --- drivers/staging/hv/blkvsc_drv.c | 2 ++ drivers/staging/hv/netvsc_drv.c | 2 ++ drivers/staging/hv/storvsc_drv.c | 2 ++ drivers/staging/hv/vmbus.h | 2 +- drivers/staging/hv/vmbus_drv.c | 14 +------------- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c index 36a0adb..293ab8e 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -177,6 +177,8 @@ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; int ret; + drv_ctx->hv_drv = &storvsc_drv_obj->base; + storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index 03f9740..364b6c7 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -500,6 +500,8 @@ static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; int ret; + drv_ctx->hv_drv = &net_drv_obj->base; + net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE; net_drv_obj->recv_cb = netvsc_recv_callback; net_drv_obj->link_status_change = netvsc_linkstatus_callback; diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index a8427ff..33acee5 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -140,6 +140,8 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; + drv_ctx->hv_drv = &storvsc_drv_obj->base; + storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ diff --git a/drivers/staging/hv/vmbus.h b/drivers/staging/hv/vmbus.h index 42f2adb..fd9d00f 100644 --- a/drivers/staging/hv/vmbus.h +++ b/drivers/staging/hv/vmbus.h @@ -30,8 +30,8 @@ struct driver_context { struct hv_guid class_id; - struct device_driver driver; + struct hv_driver *hv_drv; /* * Use these methods instead of the struct device_driver so 2.6 kernel diff --git a/drivers/staging/hv/vmbus_drv.c b/drivers/staging/hv/vmbus_drv.c index 459c707..1f4e46d 100644 --- a/drivers/staging/hv/vmbus_drv.c +++ b/drivers/staging/hv/vmbus_drv.c @@ -42,11 +42,6 @@ /* Main vmbus driver data structure */ struct vmbus_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME, this is a bug */ - /* The driver field is not used in here. Instead, the bus field is */ - /* used to represent the driver */ - struct driver_context drv_ctx; struct hv_driver drv_obj; struct bus_type bus; @@ -869,14 +864,7 @@ static int vmbus_match(struct device *device, struct device_driver *driver) /* We found our driver ? */ if (memcmp(&device_ctx->class_id, &driver_ctx->class_id, sizeof(struct hv_guid)) == 0) { - /* - * !! NOTE: The driver_ctx is not a vmbus_drv_ctx. We typecast - * it here to access the struct hv_driver field - */ - struct vmbus_driver_context *vmbus_drv_ctx - (struct vmbus_driver_context *)driver_ctx; - - device_ctx->device_obj.drv = &vmbus_drv_ctx->drv_obj; + device_ctx->device_obj.drv = driver_ctx->hv_drv; DPRINT_INFO(VMBUS_DRV, "device object (%p) set to driver object (%p)", &device_ctx->device_obj, -- 1.6.3.2
Haiyang Zhang
2011-Feb-23 20:19 UTC
[PATCH 2/4] staging: hv: Fix the code depending on struct netvsc_driver_context data order
The patch fixed the code depending on the exact order of fields in the struct netvsc_driver_context. Now, we use container_of() instead of type casting from the first field to the container struct. Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> Signed-off-by: Hank Janssen <hjanssen at microsoft.com> --- drivers/staging/hv/netvsc_drv.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c index 364b6c7..c78624c 100644 --- a/drivers/staging/hv/netvsc_drv.c +++ b/drivers/staging/hv/netvsc_drv.c @@ -49,8 +49,6 @@ struct net_device_context { }; struct netvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* Which is a bug FIXME! */ struct driver_context drv_ctx; struct netvsc_driver drv_obj; }; @@ -137,8 +135,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) struct net_device_context *net_device_ctx = netdev_priv(net); struct driver_context *driver_ctx driver_to_driver_context(net_device_ctx->device_ctx->device.driver); - struct netvsc_driver_context *net_drv_ctx - (struct netvsc_driver_context *)driver_ctx; + struct netvsc_driver_context *net_drv_ctx = container_of(driver_ctx, + struct netvsc_driver_context, drv_ctx); struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; struct hv_netvsc_packet *packet; int ret; @@ -342,8 +340,8 @@ static int netvsc_probe(struct device *device) { struct driver_context *driver_ctx driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx - (struct netvsc_driver_context *)driver_ctx; + struct netvsc_driver_context *net_drv_ctx = container_of(driver_ctx, + struct netvsc_driver_context, drv_ctx); struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); struct hv_device *device_obj = &device_ctx->device_obj; @@ -414,8 +412,8 @@ static int netvsc_remove(struct device *device) { struct driver_context *driver_ctx driver_to_driver_context(device->driver); - struct netvsc_driver_context *net_drv_ctx - (struct netvsc_driver_context *)driver_ctx; + struct netvsc_driver_context *net_drv_ctx = container_of(driver_ctx, + struct netvsc_driver_context, drv_ctx); struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); struct net_device *net = dev_get_drvdata(&device_ctx->device); -- 1.6.3.2
Haiyang Zhang
2011-Feb-23 20:19 UTC
[PATCH 3/4] staging: hv: Fix the code depending on struct blkvsc_driver_context data order
The patch fixed the code depending on the exact order of fields in the struct blkvsc_driver_context. Now, we use container_of() instead of type casting from the first field to the container struct. Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> Signed-off-by: Hank Janssen <hjanssen at microsoft.com> --- drivers/staging/hv/blkvsc_drv.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c index 293ab8e..8f38895 100644 --- a/drivers/staging/hv/blkvsc_drv.c +++ b/drivers/staging/hv/blkvsc_drv.c @@ -117,8 +117,6 @@ struct block_device_context { /* Per driver */ struct blkvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME this is a bug! */ struct driver_context drv_ctx; struct storvsc_driver_object drv_obj; }; @@ -248,7 +246,7 @@ static int blkvsc_probe(struct device *device) struct driver_context *driver_ctx driver_to_driver_context(device->driver); struct blkvsc_driver_context *blkvsc_drv_ctx - (struct blkvsc_driver_context *)driver_ctx; + container_of(driver_ctx, struct blkvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &blkvsc_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); @@ -733,7 +731,7 @@ static int blkvsc_remove(struct device *device) struct driver_context *driver_ctx driver_to_driver_context(device->driver); struct blkvsc_driver_context *blkvsc_drv_ctx - (struct blkvsc_driver_context *)driver_ctx; + container_of(driver_ctx, struct blkvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &blkvsc_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); @@ -856,7 +854,7 @@ static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, struct driver_context *driver_ctx driver_to_driver_context(device_ctx->device.driver); struct blkvsc_driver_context *blkvsc_drv_ctx - (struct blkvsc_driver_context *)driver_ctx; + container_of(driver_ctx, struct blkvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &blkvsc_drv_ctx->drv_obj; struct hv_storvsc_request *storvsc_req; -- 1.6.3.2
Haiyang Zhang
2011-Feb-23 20:19 UTC
[PATCH 4/4] staging: hv: Fix the code depending on struct storvsc_driver_context data order
The patch fixed the code depending on the exact order of fields in the struct storvsc_driver_context. Now, we use container_of() instead of type casting from the first field to the container struct. Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> Signed-off-by: Hank Janssen <hjanssen at microsoft.com> --- drivers/staging/hv/storvsc_drv.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c index 33acee5..a364627 100644 --- a/drivers/staging/hv/storvsc_drv.c +++ b/drivers/staging/hv/storvsc_drv.c @@ -64,8 +64,6 @@ struct storvsc_cmd_request { }; struct storvsc_driver_context { - /* !! These must be the first 2 fields !! */ - /* FIXME this is a bug... */ struct driver_context drv_ctx; struct storvsc_driver_object drv_obj; }; @@ -223,8 +221,8 @@ static int storvsc_probe(struct device *device) int ret; struct driver_context *driver_ctx driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx - (struct storvsc_driver_context *)driver_ctx; + struct storvsc_driver_context *storvsc_drv_ctx = container_of( + driver_ctx, struct storvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &storvsc_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); @@ -308,8 +306,8 @@ static int storvsc_remove(struct device *device) int ret; struct driver_context *driver_ctx driver_to_driver_context(device->driver); - struct storvsc_driver_context *storvsc_drv_ctx - (struct storvsc_driver_context *)driver_ctx; + struct storvsc_driver_context *storvsc_drv_ctx = container_of( + driver_ctx, struct storvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &storvsc_drv_ctx->drv_obj; struct vm_device *device_ctx = device_to_vm_device(device); @@ -606,8 +604,8 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, struct vm_device *device_ctx = host_device_ctx->device_ctx; struct driver_context *driver_ctx driver_to_driver_context(device_ctx->device.driver); - struct storvsc_driver_context *storvsc_drv_ctx - (struct storvsc_driver_context *)driver_ctx; + struct storvsc_driver_context *storvsc_drv_ctx = container_of( + driver_ctx, struct storvsc_driver_context, drv_ctx); struct storvsc_driver_object *storvsc_drv_obj &storvsc_drv_ctx->drv_obj; struct hv_storvsc_request *request; -- 1.6.3.2
Greg KH
2011-Feb-23 21:26 UTC
[PATCH 1/4] staging: hv: Fix the code depending on struct vmbus_driver_context data order
On Wed, Feb 23, 2011 at 12:19:55PM -0800, Haiyang Zhang wrote:> The patch fixed the code depending on the exact order of fields in the > struct vmbus_driver_context, so the unused field drv_ctx can be removed, > and drv_obj doesn't have to be the second field in this structure. > > Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> > Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> > Signed-off-by: Hank Janssen <hjanssen at microsoft.com> > > --- > drivers/staging/hv/blkvsc_drv.c | 2 ++ > drivers/staging/hv/netvsc_drv.c | 2 ++ > drivers/staging/hv/storvsc_drv.c | 2 ++ > drivers/staging/hv/vmbus.h | 2 +- > drivers/staging/hv/vmbus_drv.c | 14 +------------- > 5 files changed, 8 insertions(+), 14 deletions(-) > > diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c > index 36a0adb..293ab8e 100644 > --- a/drivers/staging/hv/blkvsc_drv.c > +++ b/drivers/staging/hv/blkvsc_drv.c > @@ -177,6 +177,8 @@ static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) > struct driver_context *drv_ctx = &g_blkvsc_drv.drv_ctx; > int ret; > > + drv_ctx->hv_drv = &storvsc_drv_obj->base; > + > storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; > > /* Callback to client driver to complete the initialization */ > diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c > index 03f9740..364b6c7 100644 > --- a/drivers/staging/hv/netvsc_drv.c > +++ b/drivers/staging/hv/netvsc_drv.c > @@ -500,6 +500,8 @@ static int netvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) > struct driver_context *drv_ctx = &g_netvsc_drv.drv_ctx; > int ret; > > + drv_ctx->hv_drv = &net_drv_obj->base; > + > net_drv_obj->ring_buf_size = ring_size * PAGE_SIZE; > net_drv_obj->recv_cb = netvsc_recv_callback; > net_drv_obj->link_status_change = netvsc_linkstatus_callback; > diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c > index a8427ff..33acee5 100644 > --- a/drivers/staging/hv/storvsc_drv.c > +++ b/drivers/staging/hv/storvsc_drv.c > @@ -140,6 +140,8 @@ static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) > struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv.drv_obj; > struct driver_context *drv_ctx = &g_storvsc_drv.drv_ctx; > > + drv_ctx->hv_drv = &storvsc_drv_obj->base; > + > storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size; > > /* Callback to client driver to complete the initialization */ > diff --git a/drivers/staging/hv/vmbus.h b/drivers/staging/hv/vmbus.h > index 42f2adb..fd9d00f 100644 > --- a/drivers/staging/hv/vmbus.h > +++ b/drivers/staging/hv/vmbus.h > @@ -30,8 +30,8 @@ > > struct driver_context { > struct hv_guid class_id; > - > struct device_driver driver; > + struct hv_driver *hv_drv;If you have a pointer to hv_driver, why do you need a full 'struct device_driver' here? That sounds really wrong. Actually, having 'struct device_driver' within a structure called "driver_context" seems wrong, this should be what 'struct hv_driver' really is, right? So no, I can't take this patch, as it isn't solving the root problem here. thanks, greg k-h
Greg KH
2011-Feb-23 21:27 UTC
[PATCH 2/4] staging: hv: Fix the code depending on struct netvsc_driver_context data order
On Wed, Feb 23, 2011 at 12:19:56PM -0800, Haiyang Zhang wrote:> The patch fixed the code depending on the exact order of fields in the > struct netvsc_driver_context. Now, we use container_of() instead of type > casting from the first field to the container struct. > > Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> > Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> > Signed-off-by: Hank Janssen <hjanssen at microsoft.com> > > --- > drivers/staging/hv/netvsc_drv.c | 14 ++++++-------- > 1 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/drivers/staging/hv/netvsc_drv.c b/drivers/staging/hv/netvsc_drv.c > index 364b6c7..c78624c 100644 > --- a/drivers/staging/hv/netvsc_drv.c > +++ b/drivers/staging/hv/netvsc_drv.c > @@ -49,8 +49,6 @@ struct net_device_context { > }; > > struct netvsc_driver_context { > - /* !! These must be the first 2 fields !! */ > - /* Which is a bug FIXME! */ > struct driver_context drv_ctx; > struct netvsc_driver drv_obj; > }; > @@ -137,8 +135,8 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) > struct net_device_context *net_device_ctx = netdev_priv(net); > struct driver_context *driver_ctx > driver_to_driver_context(net_device_ctx->device_ctx->device.driver); > - struct netvsc_driver_context *net_drv_ctx > - (struct netvsc_driver_context *)driver_ctx; > + struct netvsc_driver_context *net_drv_ctx = container_of(driver_ctx, > + struct netvsc_driver_context, drv_ctx); > struct netvsc_driver *net_drv_obj = &net_drv_ctx->drv_obj; > struct hv_netvsc_packet *packet; > int ret; > @@ -342,8 +340,8 @@ static int netvsc_probe(struct device *device) > { > struct driver_context *driver_ctx > driver_to_driver_context(device->driver); > - struct netvsc_driver_context *net_drv_ctx > - (struct netvsc_driver_context *)driver_ctx; > + struct netvsc_driver_context *net_drv_ctx = container_of(driver_ctx, > + struct netvsc_driver_context, drv_ctx);container_of calls should be turned into either a macro, or an inline function, to make them smaller and easier to understand what is going on. Do that and you will solve the line-length problems as well. Please do that here. thanks, greg k-h
Greg KH
2011-Feb-23 21:28 UTC
[PATCH 3/4] staging: hv: Fix the code depending on struct blkvsc_driver_context data order
On Wed, Feb 23, 2011 at 12:19:57PM -0800, Haiyang Zhang wrote:> The patch fixed the code depending on the exact order of fields in the > struct blkvsc_driver_context. Now, we use container_of() instead of type > casting from the first field to the container struct. > > Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> > Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> > Signed-off-by: Hank Janssen <hjanssen at microsoft.com> > > --- > drivers/staging/hv/blkvsc_drv.c | 8 +++----- > 1 files changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/staging/hv/blkvsc_drv.c b/drivers/staging/hv/blkvsc_drv.c > index 293ab8e..8f38895 100644 > --- a/drivers/staging/hv/blkvsc_drv.c > +++ b/drivers/staging/hv/blkvsc_drv.c > @@ -117,8 +117,6 @@ struct block_device_context { > > /* Per driver */ > struct blkvsc_driver_context { > - /* !! These must be the first 2 fields !! */ > - /* FIXME this is a bug! */ > struct driver_context drv_ctx; > struct storvsc_driver_object drv_obj; > }; > @@ -248,7 +246,7 @@ static int blkvsc_probe(struct device *device) > struct driver_context *driver_ctx > driver_to_driver_context(device->driver); > struct blkvsc_driver_context *blkvsc_drv_ctx > - (struct blkvsc_driver_context *)driver_ctx; > + container_of(driver_ctx, struct blkvsc_driver_context, drv_ctx);Same container_of() complaint here, make it a macro or inline function. thanks, greg k-h
Greg KH
2011-Feb-23 21:28 UTC
[PATCH 4/4] staging: hv: Fix the code depending on struct storvsc_driver_context data order
On Wed, Feb 23, 2011 at 12:19:58PM -0800, Haiyang Zhang wrote:> The patch fixed the code depending on the exact order of fields in the > struct storvsc_driver_context. Now, we use container_of() instead of type > casting from the first field to the container struct. > > Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com> > Signed-off-by: K. Y. Srinivasan <kys at microsoft.com> > Signed-off-by: Hank Janssen <hjanssen at microsoft.com> > > --- > drivers/staging/hv/storvsc_drv.c | 14 ++++++-------- > 1 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c > index 33acee5..a364627 100644 > --- a/drivers/staging/hv/storvsc_drv.c > +++ b/drivers/staging/hv/storvsc_drv.c > @@ -64,8 +64,6 @@ struct storvsc_cmd_request { > }; > > struct storvsc_driver_context { > - /* !! These must be the first 2 fields !! */ > - /* FIXME this is a bug... */ > struct driver_context drv_ctx; > struct storvsc_driver_object drv_obj; > }; > @@ -223,8 +221,8 @@ static int storvsc_probe(struct device *device) > int ret; > struct driver_context *driver_ctx > driver_to_driver_context(device->driver); > - struct storvsc_driver_context *storvsc_drv_ctx > - (struct storvsc_driver_context *)driver_ctx; > + struct storvsc_driver_context *storvsc_drv_ctx = container_of( > + driver_ctx, struct storvsc_driver_context, drv_ctx);Same container_of() macro/inline function issue. thanks, greg k-h
Maybe Matching Threads
- [PATCH 1/4] staging: hv: Fix the code depending on struct vmbus_driver_context data order
- [PATCH 5/6] Staging: hv: Rename driver_context to hyperv_driver
- [PATCH 5/6] Staging: hv: Rename driver_context to hyperv_driver
- [PATCH ] Staging: hv: Hyper-V driver cleanup
- [PATCH ] Staging: hv: Hyper-V driver cleanup