firmware: arm_scmi: Fix leak in scmi_mailbox_check
PATCH 1/1 firmware: arm_scmi: Fix leak in scmi_mailbox_check
of_parse_phandle_with_args() requires the caller to call of_node_put() on the returned args->np pointer. Otherwise the reference count will remain incremented.
However, in this case, since we don't actually use the returned pointer, we can simply pass in NULL.
--- drivers/firmware/arm_scmi/driver.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/firmware/arm_scmi/driver.c +1 -3
@@ -654,9 +654,7 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)static int scmi_mailbox_check (struct device_node *np) { -struct of_phandle_args arg; - -return of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 , &arg); +return of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 ,NULL ); }static int scmi_mbox_free_channel (int id,void *p,void *data)
Signature · 1 line
2.20.1
Quoted 18 lines · Steven Price
of_parse_phandle_with_args()requires the caller to callof_node_put()on the returnedargs->nppointer. Otherwise the reference count will remain incremented.However, in this case, since we don't actually use the returned pointer, we can simply pass in NULL.
Fixes aa4f886f3893f ("firmware: arm_scmi: add basic driver infrastructure for SCMI")Signed-off-by Steven Price <[email protected]>--- drivers/firmware/arm_scmi/driver.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/firmware/arm_scmi/driver.c +0
-0
drivers/firmware/arm_scmi/driver.c static int scmi_xfer_info_init(struct scmi_info *sinfo) · line 657
Quoted 7 lines
drivers/firmware/arm_scmi/driver.c +1
-3@@ -654,9 +654,7 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)static int scmi_mailbox_check (struct device_node *np) { -struct of_phandle_args arg; - -return of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 , &arg); +return of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 ,NULL );
Although, it is not used but it is better to put arg->np instead of passing NULL.
Here, you are making the driver not to fill arguement which is customised solution, that may change in future.
Thanks.
Mukesh
Quoted 3 lines
drivers/firmware/arm_scmi/driver.c +0
-0}static int scmi_mbox_free_channel (int id,void *p,void *data)
Quoted 28 lines · Mukesh Ojha
Quoted 26 lines · Steven Price
of_parse_phandle_with_args()requires the caller to callof_node_put()on the returnedargs->nppointer. Otherwise the reference count will remain incremented.However, in this case, since we don't actually use the returned pointer, we can simply pass in NULL.
Fixes aa4f886f3893f ("firmware: arm_scmi: add basic driverinfrastructure for SCMI")
Signed-off-by Steven Price <[email protected]>---
drivers/firmware/arm_scmi/driver.c| 4 +---1 file changed, 1 insertion(+), 3 deletions(-)drivers/firmware/arm_scmi/driver.c +0
-3@@ -654,9 +654,7 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo) static int scmi_mailbox_check(struct device_node *np) { - struct of_phandle_args arg; - - return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0,
Quoted 8 lines
drivers/firmware/arm_scmi/driver.c static int scmi_xfer_info_init(struct scmi_info · line 659
Quoted 3 lines
drivers/firmware/arm_scmi/driver.c +1
-0&arg); + return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0,NULL );Although, it is not used but it is better to put
arg->npinstead of passing NULL.
Here, you are making the driver not to fill arguement which is customised solution, that may change in future.
The function of_parse_phandle_with_args() is documented thus:
Quoted 6 lines
*
of_parse_phandle_with_args()- Find a node pointed by phandle in a list
* @np: pointer to a device tree node containing a list
* @list_name: property name that contains a list
* @cells_name: property name that specifies phandles' arguments count
* @index: index of a phandle to parse out
* @out_args: optional pointer to output arguments structure (will be filled)
So I'm going by the documentation (and implementation) which both consider out_args to be optional. The alternative is of course:
Quoted 7 lines
drivers/firmware/arm_scmi/driver.c +0
-0@@ -655,8 +655,11 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)static int scmi_mailbox_check (struct device_node *np) {
drivers/firmware/arm_scmi/driver.c static int scmi_xfer_info_init(struct scmi_info *sinfo) · line 665
Quoted 10 lines
drivers/firmware/arm_scmi/driver.c +4
-1struct of_phandle_args arg; +int ret; -return of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 , &arg); + ret =of_parse_phandle_with_args (np,"mboxes" ,"#mbox-cells" ,0 , &arg); +of_node_put (arg->np); +return ret; }static int scmi_mbox_free_channel (int id,void *p,void *data)
But personally that doesn't seem as good. Is there any reason to think the interface of of_parse_phandle_with_args() will change?
Steve
Sudeep Holla
AppliedQuoted 4 lines · Steven Price
of_parse_phandle_with_args()requires the caller to callof_node_put()on the returnedargs->nppointer. Otherwise the reference count will remain incremented.
Good find and thanks for the fix.
Quoted 5 lines
However, in this case, since we don't actually use the returned pointer, we can simply pass in NULL.
Fixes aa4f886f3893f ("firmware: arm_scmi: add basic driver infrastructure for SCMI")Signed-off-by Steven Price <[email protected]>
Applied.
--
Regards,
Sudeep