Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp265154rwa; Sat, 20 Aug 2022 03:25:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR567KPsg1tNmDzeod1hCgdUvmtfLw0WROLSqaiMkLUBHqIKHPcMBJixwczkDtliP/2YwCk0 X-Received: by 2002:a05:6402:27ca:b0:43e:ce64:ca07 with SMTP id c10-20020a05640227ca00b0043ece64ca07mr9401326ede.66.1660991106283; Sat, 20 Aug 2022 03:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660991106; cv=none; d=google.com; s=arc-20160816; b=rtCwKJdXUuyPEV9EJ9+ANqyG/++qtIvLBC4sZwLlCyS1ofARDt71scfpwIryKh5KjO r5ixyqR1/KbjlbVtAptfeSqBbEc5owFJkUADb1kQRYqtuIXf4Z69h02IFFNIqNnZm5+8 IE8G9ZYvTZIgAj5TDGYNCxHPcqq3liRdlIqHXc+1NbyB03pmXXfFUeCoPp/jG9SssKar EYN38d6w7iGQrKzou43KRBkmUY3Z62WZ6iN7oA7kFB4p0eCvHE1kJjtFrnNhEF8tPcu6 79mDNKR65CowVRfZdwoOVxBQVT1e4Psar9b1IreqiPiu8UoXVL19EvgwKfbG7QZqXq+L cIBg== 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:dkim-signature; bh=8p9wZS7+CAEWP1ZjSQIY5E7ypxKx2jvelFx36fNvhPw=; b=toT7DbMwceFQ5oOzW1hH6HFGSpaW2jkZNefpFw5ejGyQJxPhNktmzf43GYuvqc9gmc u+8mhstj+4qtEYF9U8u77dQuoTWkGrdZXEhbS7znKVhMQocwrO7JE31BkbM/ARBUDS+A d4Yopgi3gDo35/q7GTg3SNe9GxVAz4/Nw6k6nq+oaMHZ9fylFJYl8I81fAwZhrfKwOyf LVgfI6BC1/LUgReAeo/51rIc8yNoFhYxOGD8hCRDp2lUZx5rF8qTCoiApqEuC/t9dAUL ohMt1aHzrRp0OsRMZVTTELb3VH8EWxCdHS9xflJy3ZK7et9L0pidLOc4WFDw6Jm+c7fc oJxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XBgmRnDh; 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 s12-20020a1709064d8c00b0073d6a11ff3dsi510552eju.456.2022.08.20.03.24.33; Sat, 20 Aug 2022 03:25:06 -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=XBgmRnDh; 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 S1344726AbiHTKFd (ORCPT + 99 others); Sat, 20 Aug 2022 06:05:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344722AbiHTKFb (ORCPT ); Sat, 20 Aug 2022 06:05:31 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 805785C9DD; Sat, 20 Aug 2022 03:05:30 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id n24so4491957ljc.13; Sat, 20 Aug 2022 03:05:30 -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:from:to:cc; bh=8p9wZS7+CAEWP1ZjSQIY5E7ypxKx2jvelFx36fNvhPw=; b=XBgmRnDhjwqFKOpVaxIGJhGx/EUHpbk+0hwjAWJWZtpvsHDjwHe2FKxsuVuahE04U2 JPBZdU4Z2qJHpPKqSVkQsKAPRswumsomsmCGw5hXL7AOrLNk9FcrhOfG/+WV7DN1X69V fc2h0u8B90SWIGeDDaT6+YOiJilOhTnWEXEFMX5cpx2s7inCVfD5j5UC3YOT+7k766xp kbjlk2zDCMQLnoFF3P6ENfTAtC08x1PlcZ98m016Pq6H+r/IbTLnruzNvt0Qyug6p1LQ 5dTLlGSgyJyWpmamTxllXQ2tLGVQf9D0aMupe3NAUgYzNbjTLB6LW/ouZbq8saQrIXB8 nizA== 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 :x-gm-message-state:from:to:cc; bh=8p9wZS7+CAEWP1ZjSQIY5E7ypxKx2jvelFx36fNvhPw=; b=EQbeMOww5A1UTC8nJKrgtVdAKOFQ5pBd+pydPcTFdCKg0Re3yG2pYVzhGcoP0dckle V3xDYk3278Q2TOte3gOq4cYVOGT0KEy5oRonCiWlUK1K3wUBvTpZyErqkyYI8PWaek+m IXIZVUBwS+gUMdEcdXnAfrLd7dY7yv/43+MnBPXDilLIQFttxvYuKbYMnbSEWRnNLYpM UBTN4EZ6ghUgMVWpOnfHh6mqLYVVavNk5uQlBUWF5dQkksH8qO59bKR4F4MJZIgMWf9a qU79JWkDfw/sur40zHwkE7N9QeyB4FHSOBvXZ8IgLob54VFHdsxuf5yaZmoR+f9y9cgC fGZA== X-Gm-Message-State: ACgBeo3dQlQZwintYg+toRWoLBs63jvXENeNEOOl1O0DR/zpwZ71qWrH 6CvCz+d5WaRlcCnEUPUrmqMqigB7+P4= X-Received: by 2002:a05:651c:230c:b0:25e:7295:5cd3 with SMTP id bi12-20020a05651c230c00b0025e72955cd3mr3354390ljb.158.1660989928692; Sat, 20 Aug 2022 03:05:28 -0700 (PDT) Received: from ?IPV6:2001:14ba:16f3:4a00::1? (dc75zzyyyyyyyyyyyyyyt-3.rev.dnainternet.fi. [2001:14ba:16f3:4a00::1]) by smtp.gmail.com with ESMTPSA id a2-20020a05651c030200b002619257da21sm969899ljp.118.2022.08.20.03.05.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 20 Aug 2022 03:05:28 -0700 (PDT) Message-ID: Date: Sat, 20 Aug 2022 13:05:25 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US To: Andy Shevchenko , "Vaittinen, Matti" Cc: Jonathan Cameron , Lars-Peter Clausen , Miaoqian Lin , Andy Shevchenko , Xiang wangx , linux-iio , Linux Kernel Mailing List References: <3fd11489356b1c73a3d7b4bd9dec7e12c9fe8788.1660934107.git.mazziesaccount@gmail.com> <795d16f2-4dee-7492-4a87-e928020efebe@fi.rohmeurope.com> <0823a6e8-b325-78c5-d060-c5f9442e3df8@fi.rohmeurope.com> From: Matti Vaittinen Subject: Re: [PATCH v3 08/14] iio: bmg160_core: Simplify using devm_regulator_*get_enable() In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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,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 8/20/22 10:18, Andy Shevchenko wrote: > On Sat, Aug 20, 2022 at 9:48 AM Vaittinen, Matti > wrote: >> On 8/20/22 09:25, Andy Shevchenko wrote: >>> On Sat, Aug 20, 2022 at 9:19 AM Vaittinen, Matti >>> wrote: >>>> On 8/20/22 02:30, Andy Shevchenko wrote: >>>>> On Fri, Aug 19, 2022 at 10:21 PM Matti Vaittinen >>>>> wrote: >>> >>> What did I miss? >> >> >>>> struct bmg160_data *data; >> >>>> struct iio_dev *indio_dev; >> >> This does already violate the rule. > > Indeed, I am reading this with an MTA that has True Type fonts, and I > can't see it at the first glance. But this breaks that rule slightly > while your added line breaks it significantly. Yes. As I said, I think the reverse xmas tree rule is not too well justified. Bunch of the subsystems do not really follow it, nor did this function. Yet, as I said, I can move the array to the first line in the function when I respin the series.. >>>>> this case you even can move it out of the function, so we will see >>>>> clearly that this is (not a hidden) global variable. >>>> >>>> Here I do disagree with you. Moving the array out of the function makes >>>> it _much_ less obvious it is not used outside this function. Reason for >>>> making is "static const" is to allow the data be placed in read-only >>>> area (thanks to Guenter who originally gave me this tip). Just wanted to correct - it was Sebastian Reichel, not Guenter who explained me why doing local static const arrays is better than plain const. >>> >>> "static" in C language means two things (that's what come to my mind): >>> - for functions this tells that a function is not used outside of the module; >>> - for variables that it is a _global_ variable. >>> >>> Hiding static inside functions is not a good coding practice since it >>> hides scope of the variable. >> >> For const arrays the static in function does make sense. Being able to >> place the data in read-only areas do help with the memory on limited >> systems. > > I'm not sure we are on the same page. I do not object to the "const" > part and we are _not_ talking about that. > Maybe the explanation by Sebastian here can put us on the same page: https://lore.kernel.org/all/20190502073539.GB7864@localhost.localdomain/ https://lore.kernel.org/all/322fa765ddd72972aba931c706657661ca685afa.camel@fi.rohmeurope.com/ >>> And if you look into the kernel code, I >>> believe the use you are proposing is in minority. >> >> I don't know about the statistics. What I know is that we do have a >> technical benefits when we use static const arrays instead of non static >> ones in the functions. I do also believe placing the variables in blocks >> is a good practice. > > Yes, and global variables are better to be seen as global variables. > >> I tend to agree with you that using local, non const statics has >> pitfalls - but the pitfalls do not really apply with const ones. You >> know the value and have no races. Benefit is that just by seeing that no >> pointer is returned you can be sure that no "sane code" uses the data >> outside the function it resides. > > Putting a global variable (const or non-const) to the function will > hide its scope and it is prone to getting two variables with the same > or very similar names with quite different semantics. I don't see how moving something from a local block to a global scope does make conflicts less of an issue? On the contrary, it makes things worse as then the moved variable will collide with any other variable in any of the functions in the whole file. Having the array as function local static makes the naming collisions to be issue only if another global variable has the same name. And if that happened - the chances are code would still be correct as the function here is clearly intended to use the local one. If someone really later adds a global with the same name - and uses the global in this function - then he should have noted we have local variable with same name. Additionally - such user would be using terribly bad name for a global variable. Please note that scope of the function local static variable is limited to function even if the life-time is not just the life-time of a function. > That's why it's > really not good practice. I would rather see it outside of the > function _esp_ because it's static const. Sorry, I really don't agree with your reasoning here. :( -- Matti Vaittinen Linux kernel developer at ROHM Semiconductors Oulu Finland ~~ When things go utterly wrong vim users can always type :help! ~~ Discuss - Estimate - Plan - Report and finally accomplish this: void do_work(int time) __attribute__ ((const));