Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3508986rwb; Mon, 5 Sep 2022 13:03:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qPpnrkBW/aR8wTAuH2A3e1ztItVPqMcpal81xnoIB8X33XRvwXUUKGiXFd1ZRPhS4STcN X-Received: by 2002:a63:1f03:0:b0:434:a741:8576 with SMTP id f3-20020a631f03000000b00434a7418576mr37775pgf.364.1662408196287; Mon, 05 Sep 2022 13:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662408196; cv=none; d=google.com; s=arc-20160816; b=Y6bSLdTqrL8SQDB98V5Ne32bVBQ7KZEEqrZw2KJxovraBiDf4yZJxeMO1iOhK8RPFA UsA0xfhwj/1kJS5QZk8CDcRu0ekTOpZ44mJxrkgMh62FxgieZjO74ByGqXN0DZXpRd4F FNNUUsOqBmNFlx3++8g3SdhxLqYjrbTMY5zk+YIJKLtYCftsI96NakOsYo+CzhjUGr22 T2nuJXpc3nJzuPV9zGLNtOBFrzEtQFAlGqUW8neY3pOp+TQrAJL2UlP4rTuE+E14vPuX 7MkXmB/5B9ZajO2M4AFipxvz58R+q4GDMqQwUi6WLw1C1oCr6ak3oCCj2ppPe3FbMIQl GV8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=G9Qf5nb4X9K1i84KXH4HdM00CRNAf5tzFBdtc+b4TKE=; b=yVZl3pHMkYSC0/EsPHxn960mL15VfXvJUAzkPzZEXkrGENqq2SK54o6OK3oUUblBmy XnvAiot8h4zTARUP/rfQvMJWzGyMc7aRZ49hqNVfrXV/LQducuaffu3qkKCImMilMlxU 8+UDuAorqva1KPUM8gE3jm5kTzCrPHsoCrcMK0zbUN7595Zp+KSoTnl1BlngsWAWcFTN Jn+kWON3SHqFYvZYuz7Fmabc4PyG/RW5TlIGUqVd8UTKZbuo99U/O6K6JSmZ749Vo5Gw sGTENCLaGIuFXCoGcB1yZmNRq0e/kHoy4BaIxvLHBehQtk7Hfp70JqFNMQjEe0F8dTvO 5iYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cWny7dbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a62e90d000000b0053adb3105b7si10573795pfh.67.2022.09.05.13.03.05; Mon, 05 Sep 2022 13:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=cWny7dbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232269AbiIETri (ORCPT + 99 others); Mon, 5 Sep 2022 15:47:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231392AbiIETrg (ORCPT ); Mon, 5 Sep 2022 15:47:36 -0400 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F9B5550BE; Mon, 5 Sep 2022 12:47:35 -0700 (PDT) Received: by mail-pj1-x1029.google.com with SMTP id o4so9169330pjp.4; 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=6U10j9hf0Ix6pdhcruQhYGd2uldeJwqCn2lb1Hu4FuyskOA1ZS8LBOyuICyhQqJgi1 SrQd/wq3H/avtn64tNeS7diVHCMnVFMjov4yz6l/WxBKGB1qrCN1fR0tXT94kXKiiRtY 0hogn+RqtOj8G2caYkB1zrbembYm5hS1ReZQrYqMXy1R5friaDrcoPMlfRT74fzDgD6P gv1k4AzoQKJ4pkodFIhffxNUQLU6dBE1wV1R7l+nlmJq3zz6i5/be2W9n7ySCLAYTCUr +GO9qzW6CPeogw2l9h5OAqSpwKZ0w3+VQ5S7/AJpo8bb6rYL2zHeTcqMqvXIInVSV/zr 0Y0w== X-Gm-Message-State: ACgBeo2ko67eL+r3qHHLx75mJR2rphPlhCDIMtRvlG0Y4NYUFU/gyB/s TBfwWY4JmMMlDeRrSW68Ks0= 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 Cc: Andy Shevchenko , Thierry Reding , Mark Brown , Matti Vaittinen , Lorenzo Pieralisi , Claudiu Beznea , Liam Girdwood , Wim Van Sebroeck , Greg Kroah-Hartman , Miquel Raynal , Linus Walleij , Felipe Balbi , Alexandre Belloni , Krzysztof =?utf-8?Q?Wilczy=C5=84ski?= , Vignesh Raghavendra , Daniel Vetter , Thomas Petazzoni , Alexandre Torgue , Marc Zyngier , Richard Weinberger , David Airlie , Nicolas Ferre , Alyssa Rosenzweig , Bartosz Golaszewski , Jonathan Hunter , Rob Herring , Maxime Coquelin , Bjorn Helgaas , Pali =?iso-8859-1?Q?Roh=E1r?= , LINUXWATCHDOG , USB , "open list:GPIO SUBSYSTEM" , linux-pci , linux-tegra , "open list:MEMORY TECHNOLOGY..." , Linux Kernel Mailing List , dri-devel , linux-stm32@st-md-mailman.stormreply.com, linux-arm Mailing List 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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