Message ID | 20230829-cxl-clarify-ptrs-v1-1-40e0705c6188@intel.com |
---|---|
State | New, archived |
Headers | show |
Series | cxl/region: Clarify pointers in unregister_region() | expand |
On Tue, 29 Aug 2023 14:47:46 -0700 Ira Weiny <ira.weiny@intel.com> wrote: > devm_add_action_or_reset() passes a void * data parameter to the > callback. In the case of CXL regions, unregister_region() is passed a > struct cxl_region *. > > unregister_region() incorrectly interprets this as a struct device > pointer. Fortunately the device structure was the first member of > cxl_region. Therefore the code still works. However, should struct > cxl_region change the bug could be subtle. > > Use the proper types in unregister_region() and extract the device > pointer correctly. > > Fixes: 779dd20cfb56 ("cxl/region: Add region creation support") > Cc: Ben Widawsky <bwidawsk@kernel.org> > Signed-off-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > --- > drivers/cxl/core/region.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index e115ba382e04..471d305ef675 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -2018,10 +2018,11 @@ static struct cxl_region *to_cxl_region(struct device *dev) > return container_of(dev, struct cxl_region, dev); > } > > -static void unregister_region(void *dev) > +static void unregister_region(void *_cxlr) > { > - struct cxl_region *cxlr = to_cxl_region(dev); > + struct cxl_region *cxlr = _cxlr; > struct cxl_region_params *p = &cxlr->params; > + struct device *dev = &cxlr->dev; > int i; > > device_del(dev); > > --- > base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5 > change-id: 20230829-cxl-clarify-ptrs-f38255b7e52b > > Best regards,
On Tue, 29 Aug 2023, Ira Weiny wrote: >devm_add_action_or_reset() passes a void * data parameter to the >callback. In the case of CXL regions, unregister_region() is passed a >struct cxl_region *. > >unregister_region() incorrectly interprets this as a struct device >pointer. Fortunately the device structure was the first member of >cxl_region. Therefore the code still works. However, should struct >cxl_region change the bug could be subtle. > >Use the proper types in unregister_region() and extract the device >pointer correctly. > >Fixes: 779dd20cfb56 ("cxl/region: Add region creation support") >Cc: Ben Widawsky <bwidawsk@kernel.org> >Signed-off-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
On 8/29/23 14:47, Ira Weiny wrote: > devm_add_action_or_reset() passes a void * data parameter to the > callback. In the case of CXL regions, unregister_region() is passed a > struct cxl_region *. > > unregister_region() incorrectly interprets this as a struct device > pointer. Fortunately the device structure was the first member of > cxl_region. Therefore the code still works. However, should struct > cxl_region change the bug could be subtle. > > Use the proper types in unregister_region() and extract the device > pointer correctly. > > Fixes: 779dd20cfb56 ("cxl/region: Add region creation support") > Cc: Ben Widawsky <bwidawsk@kernel.org> > Signed-off-by: Ira Weiny <ira.weiny@intel.com> Great catch! Reviewed-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/region.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index e115ba382e04..471d305ef675 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -2018,10 +2018,11 @@ static struct cxl_region *to_cxl_region(struct device *dev) > return container_of(dev, struct cxl_region, dev); > } > > -static void unregister_region(void *dev) > +static void unregister_region(void *_cxlr) > { > - struct cxl_region *cxlr = to_cxl_region(dev); > + struct cxl_region *cxlr = _cxlr; > struct cxl_region_params *p = &cxlr->params; > + struct device *dev = &cxlr->dev; > int i; > > device_del(dev); > > --- > base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5 > change-id: 20230829-cxl-clarify-ptrs-f38255b7e52b > > Best regards,
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e115ba382e04..471d305ef675 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2018,10 +2018,11 @@ static struct cxl_region *to_cxl_region(struct device *dev) return container_of(dev, struct cxl_region, dev); } -static void unregister_region(void *dev) +static void unregister_region(void *_cxlr) { - struct cxl_region *cxlr = to_cxl_region(dev); + struct cxl_region *cxlr = _cxlr; struct cxl_region_params *p = &cxlr->params; + struct device *dev = &cxlr->dev; int i; device_del(dev);
devm_add_action_or_reset() passes a void * data parameter to the callback. In the case of CXL regions, unregister_region() is passed a struct cxl_region *. unregister_region() incorrectly interprets this as a struct device pointer. Fortunately the device structure was the first member of cxl_region. Therefore the code still works. However, should struct cxl_region change the bug could be subtle. Use the proper types in unregister_region() and extract the device pointer correctly. Fixes: 779dd20cfb56 ("cxl/region: Add region creation support") Cc: Ben Widawsky <bwidawsk@kernel.org> Signed-off-by: Ira Weiny <ira.weiny@intel.com> --- drivers/cxl/core/region.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- base-commit: 1c59d383390f970b891b503b7f79b63a02db2ec5 change-id: 20230829-cxl-clarify-ptrs-f38255b7e52b Best regards,