Re: [PATCH 1/7] drivers/rtc/sysfs: move code to count_attribute_groups()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <max.kellermann@xxxxxxxxx>
> ---
>  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




[Index of Archives]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux