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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA952ECAAD5 for ; Mon, 5 Sep 2022 20:12:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qvPBQ1KrQWD5hl1pAHei5Fn+HpAPNSfO9p/uPlxQYow=; b=QF2Z6JzTdT6iGI 5d68DJteypCfvm4U2PSa1gedtj7tDopQFUa6oHvA60HwuQZC5M+i3ogAg/O4rkNP8CNYUKJHv9QyR fnJlgcghV25T+FNopI/FU30J7hDC1ZEQjLDsi9S7TjSGpUN2WSDFM1Oph5RuyNjvAopLb8+JWtqry 1eBp8WU+reyyFnwjqZK4rRHedXgJePn5GlEIjP8w/wcbW8w5awndhHuX3loknbFmMszq7CZSYsN5/ dPG12eEnHny1aoJight4TfgifOv+UWATdJgX93B2ihhn7x+AfVArgCSbrKgBbQrIhrApqm2o7BN3e kJVI5zT7mpyUMT0oR9QA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oVIQq-00A1Te-6Q; Mon, 05 Sep 2022 20:10:56 +0000 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oVI4G-009cwv-S0; Mon, 05 Sep 2022 19:47:38 +0000 Received: by mail-pl1-x629.google.com with SMTP id jm11so9227327plb.13; Mon, 05 Sep 2022 12:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=G9Qf5nb4X9K1i84KXH4HdM00CRNAf5tzFBdtc+b4TKE=; b=cWny7dbbvfDII4XkGp5mcFhDW7xnoXHh4AKp8q/idS35yLNxXCSkBzhGNbyJdfKcgw I98s6U9AGgEVnvf/Otkfnonv1p93zecPAa1Wxa3KSM+UL95+uWumTNi/u3z4jHg0grzX JtIxbBCRknabFNdt+fjzwr65uC6OsrsW5a4sEZz0NEuBTvgOr4Bn6uiqxSSkgXONv6VT dMkF/Ehj96BrC/2YGY47othtHiCKBlZNyPsKpaY7eBC/Q5vm7GnaEikiaZ3BvOwvpZmX nN/ytcT90lHjiXGbNBizBZZroVETT+W7vOuh6f97BaXqY726iRuZQ2CjSiog5B/naWka hITg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=G9Qf5nb4X9K1i84KXH4HdM00CRNAf5tzFBdtc+b4TKE=; b=xNzZmziQM3PftRFgkREYIpxDsWzQm4LkBhJ49N4y3xHqO1xGCnN2r/KC05b0DQzvBD 2axcK9NZzggCZy1p5PS38jvTNSQxeNnDOX2+YWQZHi59VYSoHAv85cD5baGBLPNZxGgL dRbBMT3VDTPzTkzDo+btadmCwwM7M3VeQXMB4YcEVEHxu5pQwV2Nq5AYUzvXPzPG6aYF yMBS4BUpowvPKDsIvM1xxuSfM0vlYdt1TB7Ck2o8iUidIxWCv7FFurYsMtNyBnqmbSVS HpjfD4QStjGMqtJ+vYkrRPAy5muE4a6x8lQU3nUV8lwBdknut7duOp/bxOUV0PrJabT7 bSxw== X-Gm-Message-State: ACgBeo26bXD0J88I/ekR2EPgP9p4x9lzk6MlJY6BF5jSzVV4rmepaFR+ uh3ZiZSFhO1oSR+742YNp1E= X-Google-Smtp-Source: AA6agR4rG9EXV1E/55fesrVFOXE77lWvaBqXkzFJkUjVwNbVeqHEEiHG7UvgGt+kX2D0zKBcZVYK9g== X-Received: by 2002:a17:90a:3c89:b0:1fa:acc2:bafe with SMTP id g9-20020a17090a3c8900b001faacc2bafemr21251569pjc.84.1662407254825; Mon, 05 Sep 2022 12:47:34 -0700 (PDT) Received: from google.com ([2620:15c:202:201:7332:f188:2984:5930]) by smtp.gmail.com with ESMTPSA id v63-20020a622f42000000b0053e20a0333fsm27362pfv.93.2022.09.05.12.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Sep 2022 12:47:34 -0700 (PDT) Date: Mon, 5 Sep 2022 12:47:30 -0700 From: Dmitry Torokhov To: Guenter Roeck Subject: Re: [PATCH v1 10/11] watchdog: bd9576_wdt: switch to using devm_fwnode_gpiod_get() Message-ID: References: <20220903-gpiod_get_from_of_node-remove-v1-0-b29adfb27a6c@gmail.com> <20220903-gpiod_get_from_of_node-remove-v1-10-b29adfb27a6c@gmail.com> <75e60144-9fa2-d6ba-bc92-edd23f7e7189@roeck-us.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220905_124736_963667_3AEBCA3D X-CRM114-Status: GOOD ( 31.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Alexandre Belloni , Vignesh Raghavendra , David Airlie , linux-pci , Linus Walleij , Alexandre Torgue , dri-devel , Liam Girdwood , linux-tegra , Thierry Reding , "open list:MEMORY TECHNOLOGY..." , Thomas Petazzoni , Miquel Raynal , linux-stm32@st-md-mailman.stormreply.com, Alyssa Rosenzweig , LINUXWATCHDOG , Rob Herring , Marc Zyngier , Bartosz Golaszewski , Jonathan Hunter , Andy Shevchenko , Lorenzo Pieralisi , Maxime Coquelin , Matti Vaittinen , "open list:GPIO SUBSYSTEM" , Mark Brown , Bjorn Helgaas , Wim Van Sebroeck , linux-arm Mailing List , Felipe Balbi , Greg Kroah-Hartman , USB , Linux Kernel Mailing List , Daniel Vetter , Richard Weinberger , Pali =?iso-8859-1?Q?Roh=E1r?= , Claudiu Beznea Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Sep 05, 2022 at 08:49:58AM -0700, Guenter Roeck wrote: > On 9/5/22 08:21, Andy Shevchenko wrote: > > On Mon, Sep 5, 2022 at 6:13 PM Guenter Roeck wrote: > > > On 9/5/22 04:09, Andy Shevchenko wrote: > > > > On Mon, Sep 5, 2022 at 9:33 AM Dmitry Torokhov > > > > wrote: > > > > ... > > > > > > > + count = device_property_count_u32(dev->parent, "rohm,hw-timeout-ms"); > > > > > + if (count < 0 && count != -EINVAL) > > > > > + return count; > > > > > + > > > > > + if (count > 0) { > > > > > > > > > + if (count > ARRAY_SIZE(hw_margin)) > > > > > + return -EINVAL; > > > > > > > > Why double check? You may move it out of the (count > 0). > > > > > Two checks will always be needed, so I don't entirely see > > > how that would be better. > > > > But not nested. That's my point: > > > > if (count > ARRAY_SIZE()) > > return ... > > if (count > 0) > > ... > > > > The old code has either 1 or two checks if there is no error. > Your suggested code has always two checks. I don't see how that > is an improvement. > > > > > > - if (ret == 1) > > > > > - hw_margin_max = hw_margin[0]; > > > > > > > > > + ret = device_property_read_u32_array(dev->parent, > > > > > + "rohm,hw-timeout-ms", > > > > > + hw_margin, count); > > > > > + if (ret < 0) > > > > > + return ret; > > > > > > > > So, only this needs the count > 0 check since below already has it implicitly. > > > > > > > Sorry, I don't understand this comment. > > > > if (count > 0) { > > ret = device_property_read_u32_array(...); > > ... > > } > > if (count == 1) > > ... > > if (count == 2) > > ... > > > > But here it might be better to have the nested conditionals. > > > > We know that count is either 1 or 2 here, so strictly speaking > if (count == 1) { > } else { > } > would be sufficient. On the other side, that depends on ARRAY_SIZE() being > exactly 2, so > if (count == 1) { > } else if (count == 2) { > } > would also make sense. Either way is fine with me. I'll leave it up > to Dmitry to decide what he wants to do. My goal is to drop usage of devm_gpiod_get_from_of_node(), beyond that I do not have strong preferences either way really. It is probing code, so performance is not critical, but I'm obviously satisfied with how the code looks now, or I would not have sent it. Thanks. -- Dmitry _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel