Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_mass_storage: remove unnecessary open check
@ 2023-06-06 22:15 David Disseldorp
  2023-06-06 22:33 ` Alan Stern
  0 siblings, 1 reply; 4+ messages in thread
From: David Disseldorp @ 2023-06-06 22:15 UTC (permalink / raw)
  To: linux-usb; +Cc: Alan Stern, Greg Kroah-Hartman, David Disseldorp

fsg_lun_is_open() will always and only be true after a successful
fsg_lun_open() call, so drop the unnecessary conditional. Similarly,
the error_lun label will never be reached with an open lun (non-null
filp) so remove the unnecessary fsg_lun_close() call.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 drivers/usb/gadget/function/f_mass_storage.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 3a30feb47073f..da07e45ae6df5 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -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);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-07 14:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06 22:15 [PATCH] usb: gadget: f_mass_storage: remove unnecessary open check David Disseldorp
2023-06-06 22:33 ` Alan Stern
2023-06-07  8:15   ` David Disseldorp
2023-06-07 14:11     ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox