From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E2E1C433B4 for ; Wed, 28 Apr 2021 09:05:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02CE8613F3 for ; Wed, 28 Apr 2021 09:05:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238122AbhD1JGk (ORCPT ); Wed, 28 Apr 2021 05:06:40 -0400 Received: from mga01.intel.com ([192.55.52.88]:5299 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238012AbhD1JGV (ORCPT ); Wed, 28 Apr 2021 05:06:21 -0400 IronPort-SDR: ByPV1SVmv/mNQFjlaSOeTmdJdBMqkm24nTkV2Ax1a2BS/ZWk4csag1IcI3If8aXSUa5DSd6gG6 22W2B47+Bu7A== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="217410454" X-IronPort-AV: E=Sophos;i="5.82,257,1613462400"; d="scan'208";a="217410454" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2021 02:05:32 -0700 IronPort-SDR: ZRDuHKAkIZIEQtnwRKrmALvCPJ/RvrG3HHP5Rbxu/XnRe5KPaP9G5tCKsz/WQ5DHYEBe99+SYX NfOaK822QbOg== X-IronPort-AV: E=Sophos;i="5.82,257,1613462400"; d="scan'208";a="604826516" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2021 02:05:29 -0700 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1lbg8M-007q14-L3; Wed, 28 Apr 2021 12:05:26 +0300 Date: Wed, 28 Apr 2021 12:05:26 +0300 From: Andy Shevchenko To: Christophe JAILLET Cc: gregkh@linuxfoundation.org, jirislaby@kernel.org, lukas@wunner.de, yangyingliang@huawei.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Message-ID: References: <14024ddeb2b3a8c5b0138b5ba5083f54d00164a9.1619594713.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14024ddeb2b3a8c5b0138b5ba5083f54d00164a9.1619594713.git.christophe.jaillet@wanadoo.fr> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 28, 2021 at 09:30:40AM +0200, Christophe JAILLET wrote: > Use 'hlist_for_each_entry' instead of hand writing it. > This saves a few lines of code. > > The comment about warning generated by some gcc version is also removed. > The way 'hlist_for_each_entry' is written should prevent such a warning to > be emitted. I checked the implementation of the macros vs. this usage and below seems legit. However it indeed needs more test coverage because it's sensitive piece of code. FWIW, Reviewed-by: Andy Shevchenko (with the above caveat) > Signed-off-by: Christophe JAILLET > --- > Compile tested only > --- > drivers/tty/serial/8250/8250_core.c | 18 ++++-------------- > 1 file changed, 4 insertions(+), 14 deletions(-) > > diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c > index cae61d1ebec5..081b773a54c9 100644 > --- a/drivers/tty/serial/8250/8250_core.c > +++ b/drivers/tty/serial/8250/8250_core.c > @@ -172,7 +172,6 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up) > static int serial_link_irq_chain(struct uart_8250_port *up) > { > struct hlist_head *h; > - struct hlist_node *n; > struct irq_info *i; > int ret; > > @@ -180,13 +179,11 @@ static int serial_link_irq_chain(struct uart_8250_port *up) > > h = &irq_lists[up->port.irq % NR_IRQ_HASH]; > > - hlist_for_each(n, h) { > - i = hlist_entry(n, struct irq_info, node); > + hlist_for_each_entry(i, h, node) > if (i->irq == up->port.irq) > break; > - } > > - if (n == NULL) { > + if (i == NULL) { > i = kzalloc(sizeof(struct irq_info), GFP_KERNEL); > if (i == NULL) { > mutex_unlock(&hash_mutex); > @@ -220,25 +217,18 @@ static int serial_link_irq_chain(struct uart_8250_port *up) > > static void serial_unlink_irq_chain(struct uart_8250_port *up) > { > - /* > - * yes, some broken gcc emit "warning: 'i' may be used uninitialized" > - * but no, we are not going to take a patch that assigns NULL below. > - */ > struct irq_info *i; > - struct hlist_node *n; > struct hlist_head *h; > > mutex_lock(&hash_mutex); > > h = &irq_lists[up->port.irq % NR_IRQ_HASH]; > > - hlist_for_each(n, h) { > - i = hlist_entry(n, struct irq_info, node); > + hlist_for_each_entry(i, h, node) > if (i->irq == up->port.irq) > break; > - } > > - BUG_ON(n == NULL); > + BUG_ON(i == NULL); > BUG_ON(i->head == NULL); > > if (list_empty(i->head)) > -- > 2.30.2 > -- With Best Regards, Andy Shevchenko