Message ID | 20230914035035.3765754-3-ruanjinjie@huawei.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | media: siano: Fix two bugs in smsdvb_debugfs_create() | expand |
On 14/09/2023 05:50, Jinjie Ruan wrote: > If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which > is created by debugfs_create_dir() and debugfs_create_file() is > not freed. So use debugfs_remove_recursive() to free them. > > Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file") > Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> > --- > drivers/media/common/siano/smsdvb-debugfs.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c > index 16d3b9ab31c5..38b25e88ce57 100644 > --- a/drivers/media/common/siano/smsdvb-debugfs.c > +++ b/drivers/media/common/siano/smsdvb-debugfs.c > @@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client) > } > > debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL); > - if (!debug_data) > + if (!debug_data) { > + debugfs_remove_recursive(client->debugfs); > return -ENOMEM; > + } > > client->debug_data = debug_data; > client->prt_dvb_stats = smsdvb_print_dvb_stats; It's much better to first allocate debug_data before calling debugfs_create_dir. No need to clean anything up in that case. You can also ignore any errors from debugfs_create_file. Regards, Hans
On 2023/10/5 16:30, Hans Verkuil wrote: > On 14/09/2023 05:50, Jinjie Ruan wrote: >> If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which >> is created by debugfs_create_dir() and debugfs_create_file() is >> not freed. So use debugfs_remove_recursive() to free them. >> >> Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file") >> Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> >> --- >> drivers/media/common/siano/smsdvb-debugfs.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c >> index 16d3b9ab31c5..38b25e88ce57 100644 >> --- a/drivers/media/common/siano/smsdvb-debugfs.c >> +++ b/drivers/media/common/siano/smsdvb-debugfs.c >> @@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client) >> } >> >> debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL); >> - if (!debug_data) >> + if (!debug_data) { >> + debugfs_remove_recursive(client->debugfs); >> return -ENOMEM; >> + } >> >> client->debug_data = debug_data; >> client->prt_dvb_stats = smsdvb_print_dvb_stats; > > It's much better to first allocate debug_data before calling debugfs_create_dir. Right! After that the code will be more cleaner. > > No need to clean anything up in that case. > > You can also ignore any errors from debugfs_create_file. > > Regards, > > Hans >
diff --git a/drivers/media/common/siano/smsdvb-debugfs.c b/drivers/media/common/siano/smsdvb-debugfs.c index 16d3b9ab31c5..38b25e88ce57 100644 --- a/drivers/media/common/siano/smsdvb-debugfs.c +++ b/drivers/media/common/siano/smsdvb-debugfs.c @@ -375,8 +375,10 @@ int smsdvb_debugfs_create(struct smsdvb_client_t *client) } debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL); - if (!debug_data) + if (!debug_data) { + debugfs_remove_recursive(client->debugfs); return -ENOMEM; + } client->debug_data = debug_data; client->prt_dvb_stats = smsdvb_print_dvb_stats;
If kzalloc() fails in smsdvb_debugfs_create(), the dir and file which is created by debugfs_create_dir() and debugfs_create_file() is not freed. So use debugfs_remove_recursive() to free them. Fixes: 503efe5cfc9f ("[media] siano: split debugfs code into a separate file") Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> --- drivers/media/common/siano/smsdvb-debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)