cxl/region: Fix leakage in __construct_region()
Davidlohr Bueso
maintainerPATCH 1/1 cxl/region: Fix leakage in __construct_region()
Failing the first sysfs_update_group() needs to explicitly kfree the resource as it is too early for cxl_region_iomem_release() to do so.
--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/cxl/core/region.c +3 -1
@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + } rc =insert_resource (cxlrd->res, res);if (rc) {
Signature · 1 line
2.39.5
Davidlohr Bueso
maintainerQuoted 4 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.
Quoted 24 lines
Signed-off-by Davidlohr Bueso <[email protected]>---
drivers/cxl/core/region.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +3
-1@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + } rc =insert_resource (cxlrd->res, res);if (rc) {Signature · 1 line
2.39.5
Quoted 5 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>
lgtm
Alison Schofield
maintainerQuoted 14 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +0
-0
drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3801
Quoted 8 lines
drivers/cxl/core/region.c +3
-1@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + }
Can sysfs_update_group() be done earlier in __construct_region, before resource is allocated?
Quoted 6 lines
drivers/cxl/core/region.c +0
-0rc =insert_resource (cxlrd->res, res);if (rc) {Signature · 1 line
2.39.5
Davidlohr Bueso
maintainerQuoted 17 lines · Alison Schofield
Quoted 16 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +0
-0@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, }
Quoted 10 lines
drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3801
Quoted 6 lines
drivers/cxl/core/region.c +3
-1rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + }Can
sysfs_update_group()be done earlier in__construct_region, before resource is allocated?
I don't think so, extended_linear_cache_size is part of cxl_region_attrs.
Thanks,
Davidlohr
Quoted 15 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +0
-0@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, }
drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3804
Quoted 10 lines
drivers/cxl/core/region.c +3
-1rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + } rc =insert_resource (cxlrd->res, res);if (rc) {
There is another call to sysfs_update_group() with potential failure after the insert_resource(). Does that need to be handled? Or is the resource turned over to the root decoder at that point?
Assuming it is ok.
Ira
Davidlohr Bueso
maintainerQuoted 24 lines · Ira Weiny
Quoted 23 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +3
-1@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + }
Quoted 8 lines
drivers/cxl/core/region.c static int __construct_region(struct cxl_region *cxlr, · line 3804
Quoted 2 lines
drivers/cxl/core/region.c +0
-0rc =insert_resource (cxlrd->res, res);if (rc) {There is another call to
sysfs_update_group()with potential failure after theinsert_resource(). Does that need to be handled? Or is the resource turned over to the root decoder at that point?Assuming it is ok.
Yes, the second call failure is after the region param p->res = res so taken care of in cxl_region_iomem_release().
Quoted 1 line
Reviewed-by Ira Weiny <[email protected]>
Thanks!
Quoted 5 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>
Applied to cxl/fixes77b310bb7b5ff8c017524df83292e0242ba89791
Quoted 20 lines
--- drivers/cxl/core/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +3
-1@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + } rc =insert_resource (cxlrd->res, res);if (rc) {
Davidlohr Bueso
maintainerping? Dave, can this be picked up for the next round you send to Linus?
Thanks,
Davidlohr
Quoted 28 lines · Davidlohr Bueso
Failing the first
sysfs_update_group()needs to explicitly kfree the resource as it is too early forcxl_region_iomem_release()to do so.Signed-off-by Davidlohr Bueso <[email protected]>---
drivers/cxl/core/region.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)drivers/cxl/core/region.c +3
-2@@ -3795,8 +3795,10 @@ static int __construct_region(struct cxl_region *cxlr, } rc =sysfs_update_group (&cxlr->dev.kobj, &cxl_region_group); -if (rc) +if (rc) { +kfree (res);return rc; + } rc =insert_resource (cxlrd->res, res);if (rc) { --2.39.5