Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1646161 > unrolled thread

[PATCH] usb: mtu3: cleanup with list_first_entry_or_null()

Started byMasahiro Yamada <yamada.masahiro@socionext.com>
First post2017-05-20 19:10 +0200
Last post2017-05-25 14:30 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-05-20 19:10 +0200
    Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-05-20 21:30 +0200
      Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Chunfeng Yun <chunfeng.yun@mediatek.com> - 2017-05-22 03:30 +0200
        Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2017-05-25 14:30 +0200

#1646161 — [PATCH] usb: mtu3: cleanup with list_first_entry_or_null()

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2017-05-20 19:10 +0200
Subject[PATCH] usb: mtu3: cleanup with list_first_entry_or_null()
Message-ID<tJg37-4h7-1@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1646199

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2017-05-20 21:30 +0200
Message-ID<tJieB-5A2-1@gated-at.bofh.it>
In reply to#1646161
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

[toc] | [prev] | [next] | [standalone]


#1646480

FromChunfeng Yun <chunfeng.yun@mediatek.com>
Date2017-05-22 03:30 +0200
Message-ID<tJKkx-74C-3@gated-at.bofh.it>
In reply to#1646199
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

[toc] | [prev] | [next] | [standalone]


#1650447

FromGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Date2017-05-25 14:30 +0200
Message-ID<tL03U-89G-11@gated-at.bofh.it>
In reply to#1646480
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web