Linux USB
 help / color / mirror / Atom feed
* [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier
       [not found] <20210715031533.9553-1-justin.he@arm.com>
@ 2021-07-15  3:15 ` Jia He
  2021-07-15  7:26   ` Felipe Balbi
  2021-07-15  8:10   ` Greg Kroah-Hartman
  0 siblings, 2 replies; 3+ messages in thread
From: Jia He @ 2021-07-15  3:15 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Torvalds, Christoph Hellwig, nd, Jia He, Felipe Balbi,
	Greg Kroah-Hartman, Gustavo A. R. Silva, Chen Lin, linux-usb

After the behavior of '%pD' is changed to print the full path of file,
the log printing in fsg_common_create_lun() can be simplified.

Given the space with proper length would be allocated in vprintk_store(),
it is worthy of dropping kmalloc()/kfree() to avoid additional space
allocation. The error case is well handled in d_path_unsafe(), the error
string would be copied in '%pD' buffer, no need to additionally handle
IS_ERR().

Cc: Felipe Balbi <balbi@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Chen Lin <chen.lin5@zte.com.cn>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Jia He <justin.he@arm.com>
---
 drivers/usb/gadget/function/f_mass_storage.c | 28 ++++++++------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 4a4703634a2a..04d4e8a0f6fd 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -2738,7 +2738,6 @@ 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;
 	int rc = -ENOMEM;
 
 	if (id >= ARRAY_SIZE(common->luns))
@@ -2790,22 +2789,17 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg,
 			goto error_lun;
 	}
 
-	pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
-	p = "(no medium)";
-	if (fsg_lun_is_open(lun)) {
-		p = "(error)";
-		if (pathbuf) {
-			p = file_path(lun->filp, pathbuf, PATH_MAX);
-			if (IS_ERR(p))
-				p = "(error)";
-		}
-	}
-	pr_info("LUN: %s%s%sfile: %s\n",
-	      lun->removable ? "removable " : "",
-	      lun->ro ? "read only " : "",
-	      lun->cdrom ? "CD-ROM " : "",
-	      p);
-	kfree(pathbuf);
+	if (fsg_lun_is_open(lun))
+		pr_info("LUN: %s%s%sfile: %pD\n",
+			lun->removable ? "removable " : "",
+			lun->ro ? "read only " : "",
+			lun->cdrom ? "CD-ROM " : "",
+			lun->filp);
+	else
+		pr_info("LUN: %s%s%sfile: (no medium)\n",
+			lun->removable ? "removable " : "",
+			lun->ro ? "read only " : "",
+			lun->cdrom ? "CD-ROM " : "");
 
 	return 0;
 
-- 
2.17.1


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

* Re: [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier
  2021-07-15  3:15 ` [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier Jia He
@ 2021-07-15  7:26   ` Felipe Balbi
  2021-07-15  8:10   ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Felipe Balbi @ 2021-07-15  7:26 UTC (permalink / raw)
  To: Jia He, linux-kernel
  Cc: Linus Torvalds, Christoph Hellwig, nd, Jia He, Greg Kroah-Hartman,
	Gustavo A. R. Silva, Chen Lin, linux-usb

[-- Attachment #1: Type: text/plain, Size: 855 bytes --]

Jia He <justin.he@arm.com> writes:

> After the behavior of '%pD' is changed to print the full path of file,
> the log printing in fsg_common_create_lun() can be simplified.
>
> Given the space with proper length would be allocated in vprintk_store(),
> it is worthy of dropping kmalloc()/kfree() to avoid additional space
> allocation. The error case is well handled in d_path_unsafe(), the error
> string would be copied in '%pD' buffer, no need to additionally handle
> IS_ERR().
>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: Chen Lin <chen.lin5@zte.com.cn>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Jia He <justin.he@arm.com>

Acked-by: Felipe Balbi <balbi@kernel.org>

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 511 bytes --]

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

* Re: [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier
  2021-07-15  3:15 ` [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier Jia He
  2021-07-15  7:26   ` Felipe Balbi
@ 2021-07-15  8:10   ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-07-15  8:10 UTC (permalink / raw)
  To: Jia He
  Cc: linux-kernel, Linus Torvalds, Christoph Hellwig, nd, Felipe Balbi,
	Gustavo A. R. Silva, Chen Lin, linux-usb

On Thu, Jul 15, 2021 at 11:15:30AM +0800, Jia He wrote:
> After the behavior of '%pD' is changed to print the full path of file,
> the log printing in fsg_common_create_lun() can be simplified.
> 
> Given the space with proper length would be allocated in vprintk_store(),
> it is worthy of dropping kmalloc()/kfree() to avoid additional space
> allocation. The error case is well handled in d_path_unsafe(), the error
> string would be copied in '%pD' buffer, no need to additionally handle
> IS_ERR().
> 
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: Chen Lin <chen.lin5@zte.com.cn>
> Cc: linux-usb@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: Jia He <justin.he@arm.com>
> ---
>  drivers/usb/gadget/function/f_mass_storage.c | 28 ++++++++------------
>  1 file changed, 11 insertions(+), 17 deletions(-)

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

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

end of thread, other threads:[~2021-07-15  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210715031533.9553-1-justin.he@arm.com>
2021-07-15  3:15 ` [PATCH RFC 10/13] usb: gadget: simplify the printing with '%pD' specifier Jia He
2021-07-15  7:26   ` Felipe Balbi
2021-07-15  8:10   ` Greg Kroah-Hartman

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