Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp136986rwa; Sat, 20 Aug 2022 00:21:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR7v6js5papfWl1rdmHp3uYFzHOmDvYIiQLcg0631W1T10eeNS3/4dON5wjAicvDqdWykiT/ X-Received: by 2002:a17:907:2711:b0:73b:8c50:80f with SMTP id w17-20020a170907271100b0073b8c50080fmr7092722ejk.150.1660980095639; Sat, 20 Aug 2022 00:21:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660980095; cv=none; d=google.com; s=arc-20160816; b=KdY+qUBFS3s+cZzKUR8V589EIaWMplUMlZqqQ8VP/dN/vuE1N6Za8uiWACPejTJIoB 1NApuLdzF7mA4UeieGv4Xvsa2nVB2LaPOznzokiV5puJZFTVYZuiBN9Fxa45z/xSyr4N wRY6MK+JqApaYzT7CG6vcjWRxefU2k7HQkanCaYJ7pszEPPRDunrD5rdcmbxnsP7B1+R KArzG9oGlAEb7JRwHIW0+1QXe0AcUkQFwslATcYDuPq9ZArQrCKBQN3A6EKGrzvJs0Ir VTSxTSxquwEahyJMj9+dcEqK+iX92ub6LCJJ46DwXukasvXd3HpHm3p22pwwGz/APKPK ZvPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RfHnMtcUMETMR/Aa5CV8kPSlFBKpFrMW9OaR7NTF/mw=; b=tWJA2fhO8CUIjlTpHlKlz9f/AaXAc85zgptst6C1/IKvkJZNbbCYpDAGmnV4xMGtyJ dlKJxEDx80Xae6xjW205xx4YRCUVHvo6CjJ6bwg30H2XD+mMqhYhhho0KDf+NxikKbo4 YCjRFLAQ+/vEiObW+aqpfwXztcJ/oziRPlM7lNFO2YNYOhfanfB6HIM3JotBcnxpx9Ne gymi1DyIztASMn+mJyZ2cRioW5a6q8Nav7zKEjFF7qhsOhG2tiE58ocyxFCm8iGDZz37 pjLQFuA3y0mZiY1RK1MjAH6rhigP8VUOZhjt7GPvJeNXErqPO7DBb5neXhvmoL0/XqyV /xVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="gErxLB/H"; 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 oz16-20020a1709077d9000b007309e3750acsi4779310ejc.652.2022.08.20.00.21.09; Sat, 20 Aug 2022 00:21:35 -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="gErxLB/H"; 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 S1344400AbiHTHTP (ORCPT + 99 others); Sat, 20 Aug 2022 03:19:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344259AbiHTHSz (ORCPT ); Sat, 20 Aug 2022 03:18:55 -0400 Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C853883073; Sat, 20 Aug 2022 00:18:51 -0700 (PDT) Received: by mail-qk1-x736.google.com with SMTP id m5so4728392qkk.1; Sat, 20 Aug 2022 00:18:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=RfHnMtcUMETMR/Aa5CV8kPSlFBKpFrMW9OaR7NTF/mw=; b=gErxLB/H9EPF/1o1mS8x9cvyBOD3vCmxe0xHdLOMdgdrrHDot66YlGqsTRSS3Za0nW 7uudGW4aoWfPavvjHQWv6p6GLXRfPhtO9uRZvnAPDNKfCsvYLELF3ObwXlWxdA84ukYT 9RbDlyybycQwsDqDoEGRNUXwGWykstwGmqhd/zSlxqR7I2kn1gair8nLqF9uU4JtVQLv 21Szigiu0we8EpjFIu+w/EpCpeazOi7eyoKhKLOyNPCxm525RbbCXSPVLFthmg1njgld hZ06fVPfOmmM8367dduaQQ/sWZrvNrWpg2xX1UMyoY479Gxuc3claNaCabt+9MT5Cm// E2AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=RfHnMtcUMETMR/Aa5CV8kPSlFBKpFrMW9OaR7NTF/mw=; b=SrjjZXyx9BndxtPK2bA6r+VHeZH53lYi3QSE596JPg5nfqXeCQAR9gSdJNDYcH6yqr yppLC2pudPaVijBmWeLJAviEx1YKcSlxVzOLe/R5eEDn3v7GwUczOMbyn4F/U5vhmSQf GYuN56fSVQlWGnEgpWv/998nRRx26Eu8MhUl63cT1c2I7uRONwNn5GmNkMb3zx6khWyR ydvmTUzjAdWLjTpWPcKCZ5c806qtzYPrA3nPgA9zShPqOIwwI+v1yDhrYS6V9RiubM4h sJD44gHMqkezsZBmzkm7mc+wk2APhSDc2+cLQZvXCSXvnVs3xnyHb+q9u8laj9991ZKq lvzQ== X-Gm-Message-State: ACgBeo1gLwYhXnosLlmSnW3niet+90zNH98OqYKsUGKflJtNIZuI8js2 YvycyAF5rPJlTohvfcKBPBKSuEl4sefvXbqK/J70LT+dYZPllA== X-Received: by 2002:ae9:e311:0:b0:6ba:e711:fb27 with SMTP id v17-20020ae9e311000000b006bae711fb27mr7336251qkf.320.1660979930527; Sat, 20 Aug 2022 00:18:50 -0700 (PDT) MIME-Version: 1.0 References: <3fd11489356b1c73a3d7b4bd9dec7e12c9fe8788.1660934107.git.mazziesaccount@gmail.com> <795d16f2-4dee-7492-4a87-e928020efebe@fi.rohmeurope.com> <0823a6e8-b325-78c5-d060-c5f9442e3df8@fi.rohmeurope.com> In-Reply-To: <0823a6e8-b325-78c5-d060-c5f9442e3df8@fi.rohmeurope.com> From: Andy Shevchenko Date: Sat, 20 Aug 2022 10:18:14 +0300 Message-ID: Subject: Re: [PATCH v3 08/14] iio: bmg160_core: Simplify using devm_regulator_*get_enable() To: "Vaittinen, Matti" Cc: Matti Vaittinen , Jonathan Cameron , Lars-Peter Clausen , Miaoqian Lin , Andy Shevchenko , Xiang wangx , linux-iio , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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 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. > >>> 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). > > > > "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. > > 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. That's why it's really not good practice. I would rather see it outside of the function _esp_ because it's static const. -- With Best Regards, Andy Shevchenko