Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2040329rdb; Mon, 9 Oct 2023 10:28:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjIKhVnE5dmGzZOMmr8iQkORrlz2JtJF+dhSRafl6Ntv+U86F0ah3UBWFBfrguHG8bjGzF X-Received: by 2002:a05:6a20:12d0:b0:12e:5f07:7ede with SMTP id v16-20020a056a2012d000b0012e5f077edemr20415466pzg.41.1696872490788; Mon, 09 Oct 2023 10:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696872490; cv=none; d=google.com; s=arc-20160816; b=oG30JAYEweTn34dJtDZyehVQdMU4XLAM2Z1SHWZw7XW9OBif78M0ZIrbAmszlMuDoV AYg9q/0wL7O7sr2Mv8KPAtsbS49GsdX5OWL6kydQqvUR2c1mt8L1+6Sm4fEXqX5Od5Oy lNBazU+1cKZWUy1Q/qIU/MTMtjhMijerGlieC14BxXWLMntiYdo7GJBJjAQOeag9XBTz iHVLSJecqb/IerRyVmmPmC3Ezp+kiKyKeqTIoOYzs1tnw177HMWRb+oGjwHoqQcxBdV7 eAE+bhVxsSHGRduyWpNdLEb3G0ETMKeropIEaxb7KNfTeHG6vikXS25i9aLlz4Xq2jia eQZA== 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:feedback-id :dkim-signature:dkim-signature; bh=bpxIn05uY/U08nfsYtT4rBYIesMTzEwaJpdO00XFU2s=; fh=9Ii3Uo9ntAqzpI/+CVqhvBnr2vvhEpAQq3PmopJvj/w=; b=pXoctpuY4D/6ysTbkK1JmbfmtkKW4txqRtrqyXhZp0kb+B1fDjCPmugiaiwhzVRNbC 0xACqJPIsaWIYnGOBZOCZP8LD2+Bnm3I85x6B0aBAPAZ4it18afwqyk5vm31agTZA+XR 3pqxj0Wqqlw49RuRvwgwANRk8FboE9zvh219Sipkpmb5k946eRhioO/YC4XNJK0N+1eM mys9csNkQZx4mc0fxwmvRABByjVV3wYwLam2ygGmbukDmgGS3mkT4bvizYjvcN0tY+ME axLXzF55W2x68xMGvaDAZnYOOqutRkZdfun/897i4NMnh+mvduDksf3PZ+6MNof14enT LW1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kroah.com header.s=fm2 header.b=E7HAb4+R; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ojOMwirz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id y22-20020a056a00191600b00690c0051dcdsi8105133pfi.143.2023.10.09.10.28.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:28:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kroah.com header.s=fm2 header.b=E7HAb4+R; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ojOMwirz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3D0AF803B2DF; Mon, 9 Oct 2023 10:28:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377289AbjJIR17 (ORCPT + 99 others); Mon, 9 Oct 2023 13:27:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376794AbjJIR16 (ORCPT ); Mon, 9 Oct 2023 13:27:58 -0400 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FA2194; Mon, 9 Oct 2023 10:27:56 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 71C225C0233; Mon, 9 Oct 2023 13:27:55 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 09 Oct 2023 13:27:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1696872475; x=1696958875; bh=bp xIn05uY/U08nfsYtT4rBYIesMTzEwaJpdO00XFU2s=; b=E7HAb4+REZTWGtcQrQ 1GjM4Pul71kt19zeswdWYM7IhscMTLXh0J02a0QJoMDYx5GKGRwNS0bijF6EsHn/ 6pKTuKTMwxchxYrO5IozEHZ+bHtmNvlpXeSl6zA3U7rN+i5tiipvkItzMJGOynnV KoyJJuke86Eo3848NINMcFKWFrZjJMSBtyp+9I1ItkxFUEysio5aShLbVhpGRVpI jGR6y7Ks6yYNArUk8jCF469KjtkVYOur0RgxGMS3QgO0+n8c8dgk1H14kyMKY1AR v+iu1KZpf9V9b1BkY9hhULHvcfrx9/r/0HMC0MVjUGCECtkVGlnlFiUQrvf/nuRy C/Vw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1696872475; x=1696958875; bh=bpxIn05uY/U08 nfsYtT4rBYIesMTzEwaJpdO00XFU2s=; b=ojOMwirzB0Lb9/TbEIyc2frjk+nci B3rsB4tEjr98/U8Pp0v4BJlySyhp0h/xCcninzSwbLHAywpKPZMXqU+ZghPzbSZY x/WjXH5t+Tt9BZFFqb/Vxg5yXwtT2xp9nc+fiuCIX4jNIx7jXLaLF9e0A9wu+LTQ C9mIFiA/f4pylVR1wwjxZwfZ6KAvCOiGN5Ffd/bNjyVDb2VTcmTaUygqbTQ5O2u9 276Orf9fj0hqxye9/iJkuf3yjaVJx4rzrElwHXmdxNredclZ2LUQgoX6/MYTyxZ5 GiDXHlpfGyl8/3+9UYgWVN5Votu6uvlItfAaNrOwkfNNmnDxh9wfxodZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrheefgdduudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuggftrfgrthhtvghrnhepheegvd evvdeljeeugfdtudduhfekledtiefhveejkeejuefhtdeufefhgfehkeetnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepghhrvghgsehkrhhorg hhrdgtohhm X-ME-Proxy: Feedback-ID: i787e41f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 9 Oct 2023 13:27:54 -0400 (EDT) Date: Mon, 9 Oct 2023 19:27:51 +0200 From: Greg KH To: Max Kellermann Cc: Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/7] drivers/hwmon: add local variable for newly allocated attribute_group** Message-ID: <2023100908-pouring-synapse-75bd@gregkh> References: <20231009165741.746184-1-max.kellermann@ionos.com> <20231009165741.746184-2-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009165741.746184-2-max.kellermann@ionos.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 10:28:08 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 06:57:35PM +0200, Max Kellermann wrote: > This allows the compiler to keep the pointer in a register and Maybe, maybe not, there's no guarantee for register usage. And it doesn't matter, this is a very slow path, no registers are required :) > prepares for making the struct field "const". What struct field? > > Signed-off-by: Max Kellermann > --- > drivers/hwmon/hwmon.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c > index c7dd3f5b2bd5..e50ab229b27d 100644 > --- a/drivers/hwmon/hwmon.c > +++ b/drivers/hwmon/hwmon.c > @@ -783,6 +783,7 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, > hdev = &hwdev->dev; > > if (chip) { > + const struct attribute_group **new_groups; > struct attribute **attrs; > int ngroups = 2; /* terminating NULL plus &hwdev->groups */ > > @@ -790,8 +791,8 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, > for (i = 0; groups[i]; i++) > ngroups++; > > - hwdev->groups = kcalloc(ngroups, sizeof(*groups), GFP_KERNEL); > - if (!hwdev->groups) { > + hwdev->groups = new_groups = kcalloc(ngroups, sizeof(*new_groups), GFP_KERNEL); So you have a const pointer AND a non-const pointer pointing to the same thing? > + if (!new_groups) { > err = -ENOMEM; > goto free_hwmon; > } > @@ -804,14 +805,14 @@ __hwmon_device_register(struct device *dev, const char *name, void *drvdata, > > hwdev->group.attrs = attrs; > ngroups = 0; > - hwdev->groups[ngroups++] = &hwdev->group; > + new_groups[ngroups++] = &hwdev->group; This shoul be identical, you assign both above the same way, so why change this? > > if (groups) { > for (i = 0; groups[i]; i++) > - hwdev->groups[ngroups++] = groups[i]; > + new_groups[ngroups++] = groups[i]; Same here. thanks, greg k-h