linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: mtu3: cleanup with list_first_entry_or_null()
@ 2017-05-20 17:05 Masahiro Yamada
  2017-05-20 19:19 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2017-05-20 17:05 UTC (permalink / raw)
  To: linux-usb; +Cc: Masahiro Yamada, Greg Kroah-Hartman, Chunfeng Yun, linux-kernel

The combo of list_empty() and list_first_entry() can be replaced with
list_first_entry_or_null().

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 drivers/usb/mtu3/mtu3.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index aa6fd6a..7b6dc23 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -356,12 +356,8 @@ static inline struct mtu3_ep *to_mtu3_ep(struct usb_ep *ep)
 
 static inline struct mtu3_request *next_request(struct mtu3_ep *mep)
 {
-	struct list_head *queue = &mep->req_list;
-
-	if (list_empty(queue))
-		return NULL;
-
-	return list_first_entry(queue, struct mtu3_request, list);
+	return list_first_entry_or_null(&mep->req_list, struct mtu3_request,
+					list);
 }
 
 static inline void mtu3_writel(void __iomem *base, u32 offset, u32 data)
-- 
2.7.4

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

* Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null()
  2017-05-20 17:05 [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Masahiro Yamada
@ 2017-05-20 19:19 ` Greg Kroah-Hartman
  2017-05-22  1:21   ` Chunfeng Yun
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-05-20 19:19 UTC (permalink / raw)
  To: Masahiro Yamada; +Cc: linux-usb, Chunfeng Yun, linux-kernel

On Sun, May 21, 2017 at 02:05:31AM +0900, Masahiro Yamada wrote:
> The combo of list_empty() and list_first_entry() can be replaced with
> list_first_entry_or_null().
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
> 
>  drivers/usb/mtu3/mtu3.h | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
> index aa6fd6a..7b6dc23 100644
> --- a/drivers/usb/mtu3/mtu3.h
> +++ b/drivers/usb/mtu3/mtu3.h
> @@ -356,12 +356,8 @@ static inline struct mtu3_ep *to_mtu3_ep(struct usb_ep *ep)
>  
>  static inline struct mtu3_request *next_request(struct mtu3_ep *mep)
>  {
> -	struct list_head *queue = &mep->req_list;
> -
> -	if (list_empty(queue))
> -		return NULL;
> -
> -	return list_first_entry(queue, struct mtu3_request, list);
> +	return list_first_entry_or_null(&mep->req_list, struct mtu3_request,
> +					list);

Even better, why is this an inlined function at all?  Why not just have
it "open coded" everywhere it is used?

thanks,

greg k-h

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

* Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null()
  2017-05-20 19:19 ` Greg Kroah-Hartman
@ 2017-05-22  1:21   ` Chunfeng Yun
  2017-05-25 12:26     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Chunfeng Yun @ 2017-05-22  1:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Masahiro Yamada, linux-usb, linux-kernel

Hi,
On Sat, 2017-05-20 at 21:19 +0200, Greg Kroah-Hartman wrote:
> On Sun, May 21, 2017 at 02:05:31AM +0900, Masahiro Yamada wrote:
> > The combo of list_empty() and list_first_entry() can be replaced with
> > list_first_entry_or_null().
> > 
> > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> > ---
> > 
> >  drivers/usb/mtu3/mtu3.h | 8 ++------
> >  1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
> > index aa6fd6a..7b6dc23 100644
> > --- a/drivers/usb/mtu3/mtu3.h
> > +++ b/drivers/usb/mtu3/mtu3.h
> > @@ -356,12 +356,8 @@ static inline struct mtu3_ep *to_mtu3_ep(struct usb_ep *ep)
> >  
> >  static inline struct mtu3_request *next_request(struct mtu3_ep *mep)
> >  {
> > -	struct list_head *queue = &mep->req_list;
> > -
> > -	if (list_empty(queue))
> > -		return NULL;
> > -
> > -	return list_first_entry(queue, struct mtu3_request, list);
> > +	return list_first_entry_or_null(&mep->req_list, struct mtu3_request,
> > +					list);
> 
> Even better, why is this an inlined function at all?  Why not just have
> it "open coded" everywhere it is used?
> 
This can avoid repeated function definition, currently it is used in
three files.

> thanks,
> 
> greg k-h

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

* Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null()
  2017-05-22  1:21   ` Chunfeng Yun
@ 2017-05-25 12:26     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2017-05-25 12:26 UTC (permalink / raw)
  To: Chunfeng Yun; +Cc: Masahiro Yamada, linux-usb, linux-kernel

On Mon, May 22, 2017 at 09:21:33AM +0800, Chunfeng Yun wrote:
> Hi,
> On Sat, 2017-05-20 at 21:19 +0200, Greg Kroah-Hartman wrote:
> > On Sun, May 21, 2017 at 02:05:31AM +0900, Masahiro Yamada wrote:
> > > The combo of list_empty() and list_first_entry() can be replaced with
> > > list_first_entry_or_null().
> > > 
> > > Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> > > ---
> > > 
> > >  drivers/usb/mtu3/mtu3.h | 8 ++------
> > >  1 file changed, 2 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
> > > index aa6fd6a..7b6dc23 100644
> > > --- a/drivers/usb/mtu3/mtu3.h
> > > +++ b/drivers/usb/mtu3/mtu3.h
> > > @@ -356,12 +356,8 @@ static inline struct mtu3_ep *to_mtu3_ep(struct usb_ep *ep)
> > >  
> > >  static inline struct mtu3_request *next_request(struct mtu3_ep *mep)
> > >  {
> > > -	struct list_head *queue = &mep->req_list;
> > > -
> > > -	if (list_empty(queue))
> > > -		return NULL;
> > > -
> > > -	return list_first_entry(queue, struct mtu3_request, list);
> > > +	return list_first_entry_or_null(&mep->req_list, struct mtu3_request,
> > > +					list);
> > 
> > Even better, why is this an inlined function at all?  Why not just have
> > it "open coded" everywhere it is used?
> > 
> This can avoid repeated function definition, currently it is used in
> three files.

Ok, makes sense.

greg k-h

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

end of thread, other threads:[~2017-05-25 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-20 17:05 [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Masahiro Yamada
2017-05-20 19:19 ` Greg Kroah-Hartman
2017-05-22  1:21   ` Chunfeng Yun
2017-05-25 12:26     ` 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;
as well as URLs for NNTP newsgroup(s).