usb: gadget: f_mass_storage: remove unnecessary open check
PATCH v2 1/1 usb: gadget: f_mass_storage: remove unnecessary open check
The fsg_lun_is_open() test can be eliminated and the code merged with the preceding conditional, because the LUN won't be open if cfg->filename wasn't set. Similarly, the error_lun label will never be reached with an open lun (non-null filp) so remove the unnecessary fsg_lun_close() call.
---
Changes since v1:
- reword commit message, following Alan Stern's suggestions
drivers/usb/gadget/function/f_mass_storage.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/usb/gadget/function/f_mass_storage.c +2 -6
@@ -2857,7 +2857,7 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, const char **name_pfx) {struct fsg_lun *lun; -char *pathbuf, *p; +char *pathbuf =NULL , *p ="(no medium)" ;int rc = -ENOMEM ;if (id >=ARRAY_SIZE (common->luns))
@@ -2907,12 +2907,9 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, rc =fsg_lun_open (lun, cfg->filename);if (rc) goto error_lun; - } - pathbuf =kmalloc (PATH_MAX ,GFP_KERNEL ); - p ="(no medium)" ; -if (fsg_lun_is_open (lun)) { p ="(error)" ; + pathbuf =kmalloc (PATH_MAX ,GFP_KERNEL );if (pathbuf) { p =file_path (lun->filp, pathbuf,PATH_MAX );if (IS_ERR (p))
@@ -2931,7 +2928,6 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, error_lun:if (device_is_registered (&lun->dev))device_unregister (&lun->dev); -fsg_lun_close (lun); common->luns[id] =NULL ; error_sysfs:kfree (lun);
Signature · 1 line
2.35.3
Quoted 42 lines · David Disseldorp
The
fsg_lun_is_open()test can be eliminated and the code merged with the preceding conditional, because the LUN won't be open ifcfg->filenamewasn't set. Similarly, theerror_lunlabel will never be reached with an open lun (non-null filp) so remove the unnecessaryfsg_lun_close()call.Signed-off-by David Disseldorp <[email protected]>---
Changes since v1:
- reword commit message, following Alan Stern's suggestionsdrivers/usb/gadget/function/f_mass_storage.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/usb/gadget/function/f_mass_storage.c +2
-5@@ -2857,7 +2857,7 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, const char **name_pfx) {struct fsg_lun *lun; -char *pathbuf, *p; +char *pathbuf =NULL , *p ="(no medium)" ;int rc = -ENOMEM ;if (id >=ARRAY_SIZE (common->luns))@@ -2907,12 +2907,9 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, rc =fsg_lun_open (lun, cfg->filename);if (rc) goto error_lun; - } - pathbuf =kmalloc (PATH_MAX ,GFP_KERNEL ); - p ="(no medium)" ; -if (fsg_lun_is_open (lun)) { p ="(error)" ; + pathbuf =kmalloc (PATH_MAX ,GFP_KERNEL );if (pathbuf) { p =file_path (lun->filp, pathbuf,PATH_MAX );if (IS_ERR (p))
drivers/usb/gadget/function/f_mass_storage.c int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, · line 2933
Quoted 7 lines
drivers/usb/gadget/function/f_mass_storage.c +0
-1@@ -2931,7 +2928,6 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, error_lun:if (device_is_registered (&lun->dev))device_unregister (&lun->dev); -fsg_lun_close (lun); common->luns[id] =NULL ; error_sysfs:kfree (lun);
Okay, now I see what's going on. Thanks for making this change.
Alan Stern