Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3318372rwb; Mon, 5 Sep 2022 09:33:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR5UCd2fdjewAtfvM/8sX10I3LC/73Bt2cTaiE+jtA7UQWv9V8VAqIfZKMIcDEKOgxBKMqDX X-Received: by 2002:a17:902:e80c:b0:174:e386:c5b7 with SMTP id u12-20020a170902e80c00b00174e386c5b7mr36024383plg.84.1662395632895; Mon, 05 Sep 2022 09:33:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662395632; cv=none; d=google.com; s=arc-20160816; b=pdOqrSoIQEkj9gXDyMntSZzW6Xtpag4d0l77zrHXxwnsHmmU0vihEZ2g3PfXKcGayy XwxLfuyWwHCnYKFLZKi+a3MCV01tolGEPR7HJcLEcS3TcS2qHLNo8b+8uoom9Guo/NzS wvV9+R9KhCQDLKncwuPfHBYkbW4lhMOTHBXdJP67awAEcfzik9HKm6B9GkxeUE5353av RuDFA+GTemb3ySUGvl7RBbGwB2eXXxYaZiOJ/jbUPglWQ/HLqWQYTuYiTj5VSnKbeLBI NpPmc9tlW8F6RDtDRZ9cxrdxXOhAu06MO64fTH6s4KgJGHNsQxX0nPssj5L3JoIdZ9iY YpPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:sender:dkim-signature; bh=3XrVUU9T8R4LO8OA1f5h+alUXAX2S0TQoRT3c9Li0zE=; b=KHA3Zea015iGl+rZIenEfiYWQR6iNVC8buDoh5n4MJkEES7D57t8eSSp8VSqix5Fh3 jB+DieVtdm7xZHGFBL0Ksxbh1mEJq6048IsG61hPLxII5cVf8r0UuRiQXRJ0M7KDH3BF Yf9/sju7OE00fPH0IMvj5/a9TW3JucusT7qzRd0a5ulK0jGD2USlKLavz+pKURknBPtb rHbV+u1K2VnQ/ZzFtHs4MPisAchzNozzSyDV1xnKCAUqbfT19p91HUQyWjsGN3+nuaIR Yxw3/J/rVDvwJj2I8VLgPua5uS11JzyOo2qX6pRY+av7gp/ZNmxeuxVtC4IUPU/l48yd SZvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fb+biuem; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oc1-20020a17090b1c0100b001f74beebefasi4127726pjb.88.2022.09.05.09.33.18; Mon, 05 Sep 2022 09:33:52 -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=fb+biuem; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238528AbiIEPuJ (ORCPT + 99 others); Mon, 5 Sep 2022 11:50:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237925AbiIEPuF (ORCPT ); Mon, 5 Sep 2022 11:50:05 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C414D15FEF; Mon, 5 Sep 2022 08:50:03 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id t3so3776852ply.2; Mon, 05 Sep 2022 08:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:sender :from:to:cc:subject:date; bh=3XrVUU9T8R4LO8OA1f5h+alUXAX2S0TQoRT3c9Li0zE=; b=fb+biuem+7b7djICmUqeW/BHTeNp/mSIkZ0RvN2SXnaFs/5YyeMU+evecpiT94v82W Wxfn0CSNmSmyFNdPp1gzvwV0fM9AjmN0MOmTdZboebJPVCoX17sG9lmzebM9ao53ceUW yVd7msO4mdC3TWp+151flO1HCijMCEaMLiYb6sFX8Glvs7ZTTgoL3lCtGTKQ7fyXm+Gg pHh/glh3NMkFwNQZT6QZHQG62OtYie95f/rnYvvh4Y8aPOmfyT9Ar+2EHwInZ1j+1+j+ Oy+Ig/euXQdz3oHAXN56OD5BQH1j8orR8xHQaKEnUQLjJ5W8lICDNDnwnI3x7eyp41JE 4G+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:sender :x-gm-message-state:from:to:cc:subject:date; bh=3XrVUU9T8R4LO8OA1f5h+alUXAX2S0TQoRT3c9Li0zE=; b=hHJgc5TAzDP2StbI84l5K++P9LI6cA0wdfIuqRNmYwprvXNfSGmRIZHXjdhs10aF+a NAeRtAKt1VTR5sK9YDy62ZJfyqmID3XON7MxSVQnYY/B8rEHgp5yHK/h7MOeqKw4Z9NM lUU5ez8gA/0DB2awELe+nIm1ygW4MdugFPRDxeKQYH4dNWhlkGGrc2v8z4bBJC11pYEm CraelHcL2vggAnqf3yP4pKVYL0Yvw+rYPB8Hi5lLOXZWVha9aBT4SL2fOebJA6GNyGd3 r6wUkjFQuKz8USFZN09KiNM5RMBtFtjyXMX3RQAmCIDsjgMaH/VkWa03XE4zy/h2AnXJ jkpw== X-Gm-Message-State: ACgBeo3wMIO3o1CdQFyFWh2irfNwn4mlGIyNkdUQgBqnvieVchG38a3/ +h7uhQ1triWJNlWLoUqT0Fo= X-Received: by 2002:a17:90a:c706:b0:1fd:e21e:7cb1 with SMTP id o6-20020a17090ac70600b001fde21e7cb1mr20626775pjt.234.1662393003052; Mon, 05 Sep 2022 08:50:03 -0700 (PDT) Received: from ?IPV6:2600:1700:e321:62f0:329c:23ff:fee3:9d7c? ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id p1-20020a17090a348100b001faa4a6691asm10512410pjb.30.2022.09.05.08.49.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 05 Sep 2022 08:50:01 -0700 (PDT) Sender: Guenter Roeck Message-ID: Date: Mon, 5 Sep 2022 08:49:58 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Andy Shevchenko Cc: Dmitry Torokhov , 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 , =?UTF-8?Q?Krzysztof_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 , =?UTF-8?Q?Pali_Roh=c3=a1r?= , 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 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> From: Guenter Roeck Subject: Re: [PATCH v1 10/11] watchdog: bd9576_wdt: switch to using devm_fwnode_gpiod_get() In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,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 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. Thanks, Guenter >>>> - if (ret == 2) { >>>> - hw_margin_max = hw_margin[1]; >>>> - hw_margin_min = hw_margin[0]; >>>> + if (count == 1) >>>> + hw_margin_max = hw_margin[0]; >>>> + >>>> + if (count == 2) { >>>> + hw_margin_max = hw_margin[1]; >>>> + hw_margin_min = hw_margin[0]; >>>> + } >>>> } >