All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
To: linux-usb@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, kernel@collabora.com
Subject: [PATCH] usb: gadget: function: Simplify error messaging in printer open/close
Date: Tue, 22 Nov 2022 15:16:03 +0100	[thread overview]
Message-ID: <20221122141603.70242-1-andrzej.p@collabora.com> (raw)
In-Reply-To: <1894a272-4816-c44c-61d5-bfcfe478d7e5@collabora.com>

Don't issue any messages if printer_open() is successful.
Also don't issue them if unsuccessful - the error code is propagated
to the calling layers and should be acted on appropriately there. Just as
it is with the -ENODEV case.

For those who really want this message leave an option to compile-in
with composite framework's VDBG() by uncommenting #define VERBOSE_DEBUG.

While at it, visually detach the "return ret;" statement.

Use __func__ instead of explicitly hardcoding the function name. This, in
turn makes checkpatch issue this for the message in printer_close():

WARNING: Unnecessary ftrace-like logging - prefer using ftrace
54: FILE: drivers/usb/gadget/function/f_printer.c:387:
+	VDBG(dev, "%s\n", __func__);

which lets us eliminate the debug message from printer_close() altogether.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
Attention

This patch depends on a recent patch from Dan Carpenter:

usb: gadget: function: use after free in printer_close()

 drivers/usb/gadget/function/f_printer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 01e842e1ba2f..d686c7be4fb5 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -11,6 +11,8 @@
  * Copyright (C) 2006 Craig W. Nadler
  */
 
+/* #define VERBOSE_DEBUG */
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
@@ -364,7 +366,8 @@ printer_open(struct inode *inode, struct file *fd)
 	spin_unlock_irqrestore(&dev->lock, flags);
 
 	kref_get(&dev->kref);
-	DBG(dev, "printer_open returned %x\n", ret);
+	VDBG(dev, "%s returned %x\n", __func__, ret);
+
 	return ret;
 }
 
@@ -381,7 +384,6 @@ printer_close(struct inode *inode, struct file *fd)
 	dev->printer_status &= ~PRINTER_SELECTED;
 	spin_unlock_irqrestore(&dev->lock, flags);
 
-	DBG(dev, "printer_close\n");
 	kref_put(&dev->kref, printer_dev_free);
 
 	return 0;
-- 
2.25.1


  reply	other threads:[~2022-11-22 14:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 14:44 [PATCH] usb: gadget: function: use after free in printer_close() Dan Carpenter
2022-11-21 15:32 ` Andrzej Pietrasiewicz
2022-11-22  7:00   ` Dan Carpenter
2022-11-22  9:49     ` Andrzej Pietrasiewicz
2022-11-22 14:16       ` Andrzej Pietrasiewicz [this message]
2022-11-22 15:54         ` [PATCH] usb: gadget: function: Simplify error messaging in printer open/close Greg Kroah-Hartman
2022-11-23 11:07           ` [PATCH] usb: gadget: function: Simplify diagnostic messaging in printer Andrzej Pietrasiewicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221122141603.70242-1-andrzej.p@collabora.com \
    --to=andrzej.p@collabora.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@collabora.com \
    --cc=linux-usb@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.