LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Anton Vorontsov <avorontsov@mvista.com>
To: Greg Kroah-Hartman <gregkh@suse.de>
Cc: linuxppc-dev@ozlabs.org, linux-usb@vger.kernel.org
Subject: [PATCH v2] USB: FHCI: cq_get() should check kfifo_out()'s return value
Date: Fri, 14 May 2010 18:33:18 +0400	[thread overview]
Message-ID: <20100514143318.GA14034@oksana.dev.rtsoft.ru> (raw)

Since commit 7acd72eb85f1c7a15e8b5eb554994949241737f1 ("kfifo: rename
kfifo_put... into kfifo_in... and kfifo_get... into kfifo_out..."),
kfifo_out() is marked __must_check, and that causes gcc to produce
lots of warnings like this:

  CC      drivers/usb/host/fhci-mem.o
In file included from drivers/usb/host/fhci-hcd.c:34:
drivers/usb/host/fhci.h: In function 'cq_get':
drivers/usb/host/fhci.h:520: warning: ignoring return value of 'kfifo_out', declared with attribute warn_unused_result
...

This patch fixes the issue by properly checking the return value.

Signed-off-by: Anton Vorontsov <avorontsov@mvista.com>
---

On Tue, May 04, 2010 at 12:17:19PM -0700, Greg KH wrote:
> On Sun, May 02, 2010 at 09:30:25PM +0400, Anton Vorontsov wrote:
> > Since commit 7acd72eb85f1c7a15e8b5eb554994949241737f1 ("kfifo: rename
> > kfifo_put... into kfifo_in... and kfifo_get... into kfifo_out..."),
> > kfifo_out() is marked __must_check, and that causes gcc to produce
> > lots of warnings like this:
> > 
> >   CC      drivers/usb/host/fhci-mem.o
> > In file included from drivers/usb/host/fhci-hcd.c:34:
> > drivers/usb/host/fhci.h: In function 'cq_get':
> > drivers/usb/host/fhci.h:520: warning: ignoring return value of 'kfifo_out', declared with attribute warn_unused_result
> > ...
> > 
> > Fix it with BUG_ON() check. We could just forcibly ignore return
> > value, but it's better to check if we really got a whole pointer.
> 
> No, you don't want to crash the whole machine for something like this.
> 
> Please just handle the error normally and pass it up to the upper levels
> if possible.

OK, here it is. Thanks!

 drivers/usb/host/fhci.h |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/fhci.h b/drivers/usb/host/fhci.h
index 72dae1c..3b6e864 100644
--- a/drivers/usb/host/fhci.h
+++ b/drivers/usb/host/fhci.h
@@ -20,6 +20,7 @@
 
 #include <linux/kernel.h>
 #include <linux/types.h>
+#include <linux/bug.h>
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/kfifo.h>
@@ -515,9 +516,13 @@ static inline int cq_put(struct kfifo *kfifo, void *p)
 
 static inline void *cq_get(struct kfifo *kfifo)
 {
-	void *p = NULL;
+	unsigned int sz;
+	void *p;
+
+	sz = kfifo_out(kfifo, (void *)&p, sizeof(p));
+	if (sz != sizeof(p))
+		return NULL;
 
-	kfifo_out(kfifo, (void *)&p, sizeof(p));
 	return p;
 }
 
-- 
1.7.0.5

                 reply	other threads:[~2010-05-14 14:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20100514143318.GA14034@oksana.dev.rtsoft.ru \
    --to=avorontsov@mvista.com \
    --cc=gregkh@suse.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox