Message ID | 170441750612.3632067.3372196682717758963.stgit@djiang5-mobl3 |
---|---|
State | Accepted |
Commit | 98e7ab3345e105339b7d919b4918f3c1879052ed |
Headers | show |
Series | find_cxl_root() related cleanups | expand |
Re: the title: cxl: Fix missing dereference of 'struct device' in cxl_port_perf_data_calculate() How about: cxl: Fix device reference leak in cxl_port_perf_data_calculate() ...to me "dereference" is a pointer operation. Other than that, looks good. Dave Jiang wrote: > cxl_port_perf_data_calculate() calls find_cxl_root() and does not > dereference the 'struct device' in the cxl_root->port. find_cxl_root() > calls get_device() and takes a reference on the port 'struct device' > member. Use the __free() macro to ensure the dereference happens. > > Fixes: 7a4f148dd8d5 ("cxl: Compute the entire CXL path latency and bandwidth data") > Signed-off-by: Dave Jiang <dave.jiang@intel.com> > --- > drivers/cxl/core/cdat.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c > index 0df5379cf02f..c6208aab452f 100644 > --- a/drivers/cxl/core/cdat.c > +++ b/drivers/cxl/core/cdat.c > @@ -162,7 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port, > struct xarray *dsmas_xa) > { > struct access_coordinate c; > - struct cxl_root *cxl_root; > struct dsmas_entry *dent; > int valid_entries = 0; > unsigned long index; > @@ -174,7 +173,11 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port, > return rc; > } > > - cxl_root = find_cxl_root(port); > + struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); > + > + if (!cxl_root) > + return -ENODEV; > + > if (!cxl_root->ops || !cxl_root->ops->qos_class) > return -EOPNOTSUPP; > > >
diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index 0df5379cf02f..c6208aab452f 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -162,7 +162,6 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port, struct xarray *dsmas_xa) { struct access_coordinate c; - struct cxl_root *cxl_root; struct dsmas_entry *dent; int valid_entries = 0; unsigned long index; @@ -174,7 +173,11 @@ static int cxl_port_perf_data_calculate(struct cxl_port *port, return rc; } - cxl_root = find_cxl_root(port); + struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port); + + if (!cxl_root) + return -ENODEV; + if (!cxl_root->ops || !cxl_root->ops->qos_class) return -EOPNOTSUPP;
cxl_port_perf_data_calculate() calls find_cxl_root() and does not dereference the 'struct device' in the cxl_root->port. find_cxl_root() calls get_device() and takes a reference on the port 'struct device' member. Use the __free() macro to ensure the dereference happens. Fixes: 7a4f148dd8d5 ("cxl: Compute the entire CXL path latency and bandwidth data") Signed-off-by: Dave Jiang <dave.jiang@intel.com> --- drivers/cxl/core/cdat.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)