From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1765595AbdEYM0e (ORCPT ); Thu, 25 May 2017 08:26:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39338 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbdEYM0d (ORCPT ); Thu, 25 May 2017 08:26:33 -0400 Date: Thu, 25 May 2017 14:26:20 +0200 From: Greg Kroah-Hartman To: Chunfeng Yun Cc: Masahiro Yamada , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: mtu3: cleanup with list_first_entry_or_null() Message-ID: <20170525122620.GA2982@kroah.com> References: <1495299931-10418-1-git-send-email-yamada.masahiro@socionext.com> <20170520191940.GA29597@kroah.com> <1495416093.25536.6.camel@mhfsdcap03> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1495416093.25536.6.camel@mhfsdcap03> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > > --- > > > > > > 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