Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2360628rdb; Tue, 10 Oct 2023 01:15:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCKdi+Yhfl71Fw22mcAYe3axw5N5RyqJDQAemh+QPLfXQE6NXU1M71P3JV9G8n7s8NxcVG X-Received: by 2002:a05:6a00:2da2:b0:68f:cc47:fcd7 with SMTP id fb34-20020a056a002da200b0068fcc47fcd7mr19752953pfb.28.1696925741769; Tue, 10 Oct 2023 01:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696925741; cv=none; d=google.com; s=arc-20160816; b=wcFSAy6/wNVowOpHYvWPoa+4TXzjOEYDlObdfAcpFbW9fFphMwEWrPd7fnfiueOFaI mMSbFzeMOeJg6u1F52A4KCle5jqLULPB8E9jtQzethRczRYkcqExWjK2qDG07/31GGZR Aqn5LILI1YBGdurYarB25j1+IunBqeN8flIvv2CmlSRXRIg8NnBam0y5aVLZy3o/rkM5 zwg4N+u9GLm+aGPE+aX41fvnZeMP3mQXRjmiz/HG6g6pAnwiZX34Kb2k68X/TDxzMSdr i88ahLlmdbGgz+xoBsZ6zQSPI/QeW0lha+Q8DgIg5dqdi7ISglnrzi3SOIYYIbSBMg9R +QdA== 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=3tRpb3t7fopvwXtyYlHe5ClDQc/xxw7GjN/sHh0MTOA=; fh=7c7ihNDCjBFOr+AYoMn0cr74RjYm+wWyyou0ZWog34s=; b=ZcPmXL8zT9FwuoIicbdcuuHixCZMcBnOJVfLZqqJVwbNJDxA6rAyU+uYbe+ca0+97S fNkPi0lsssqeQ9LfV+d/BO8H+BjrJbNK7AO61urF9RriXLWjh9wPpNibOS9A/VO18blA Dr0e4oUfIz5xcmnSCVh1d766ixOWziGkT1QZqdh3e99xvYgU0eKyu+h8US/397+4NRd+ aj93DXLNZHLgT1dgZw88IJGyW0AhW6BktXdftZa33ZCt8asHWbiGHKodsmJmOUGXLkmS a3hYq2D+HXTncEGHCPdnL/6R7PJGO5XDs4kj9MkmP+1joEspU/G2pFFzJx0WiwjGOGJx twaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UC5MhKsZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a13-20020a056a000c8d00b0068e256c6366si9239824pfv.352.2023.10.10.01.15.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:15:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UC5MhKsZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DFFFA823A29C; Tue, 10 Oct 2023 01:15:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442696AbjJJIPN (ORCPT + 99 others); Tue, 10 Oct 2023 04:15:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442638AbjJJIPL (ORCPT ); Tue, 10 Oct 2023 04:15:11 -0400 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89CA997; Tue, 10 Oct 2023 01:15:09 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id B9F241C0009; Tue, 10 Oct 2023 08:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1696925708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3tRpb3t7fopvwXtyYlHe5ClDQc/xxw7GjN/sHh0MTOA=; b=UC5MhKsZOHE76bgSA8mh7nAAx4qWRNSNw9OgpGZSuq7yDVsPbi0cXr6AQEb3h0y5Ba5KCI r2buftggrKtGjoAUdspBQGxQUmy28Wsw/3z1rqL6ULb0+tRAdVWg8hUIPTIcVb0RVa7NVa Z/QwTsWkYgy23zdLpqndm92BBkjccPZzeUHnnMIaurLrRT67Qm+7jzXQ8vRr8HzeRY7e7w u2uVn484d6G3juiE7R1mY/5finbi+tQ8WUHefk6OhrSG6izCdL7b9V5pfne1El15z6E5hd FI8Kj1qkn45O6eBbMAPvgr9gdM9en5CODzUo6Xy3zPT7528nSnqwHELlzDAL0A== Date: Tue, 10 Oct 2023 10:15:07 +0200 From: Alexandre Belloni To: Max Kellermann Cc: Alessandro Zummo , linux-rtc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups() Message-ID: <202310100815076048fb2c@mail.local> References: <20231009165741.746184-1-max.kellermann@ionos.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009165741.746184-1-max.kellermann@ionos.com> X-GND-Sasl: alexandre.belloni@bootlin.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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 10 Oct 2023 01:15:39 -0700 (PDT) X-Spam-Level: ** On 09/10/2023 18:57:34+0200, Max Kellermann wrote: > This avoids overloading the "groups" variable for three different > purposes > > Signed-off-by: Max Kellermann > --- > drivers/rtc/sysfs.c | 20 ++++++++++++-------- > 1 file changed, 12 insertions(+), 8 deletions(-) > > diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c > index e3062c4d3f2c..617933d52324 100644 > --- a/drivers/rtc/sysfs.c > +++ b/drivers/rtc/sysfs.c > @@ -313,21 +313,25 @@ const struct attribute_group **rtc_get_dev_attribute_groups(void) > return rtc_attr_groups; > } > > +static size_t count_attribute_groups(const struct attribute_group *const*groups) Shouldn't that live out of the rtc subsystem? > +{ > + size_t count = 0; > + > + for (; *groups; ++groups) > + ++count; > + return count; > +} > + > int rtc_add_groups(struct rtc_device *rtc, const struct attribute_group **grps) > { > - size_t old_cnt = 0, add_cnt = 0, new_cnt; > + size_t old_cnt, add_cnt, new_cnt; > const struct attribute_group **groups, **old; > > if (!grps) > return -EINVAL; > > - groups = rtc->dev.groups; > - if (groups) > - for (; *groups; groups++) > - old_cnt++; > - > - for (groups = grps; *groups; groups++) > - add_cnt++; > + old_cnt = rtc->dev.groups ? count_attribute_groups(rtc->dev.groups) : 0; > + add_cnt = count_attribute_groups(grps); > > new_cnt = old_cnt + add_cnt + 1; > groups = devm_kcalloc(&rtc->dev, new_cnt, sizeof(*groups), GFP_KERNEL); > -- > 2.39.2 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com