lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 10 Aug 2023 17:39:32 +0300
From:   Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To:     Bartosz Golaszewski <brgl@...ev.pl>
Cc:     Linus Walleij <linus.walleij@...aro.org>,
        Kent Gibson <warthog618@...il.com>, linux-gpio@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH 2/2] gpio: sim: simplify code with cleanup helpers

On Wed, Aug 09, 2023 at 03:14:42PM +0200, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> 
> Use macros defined in linux/cleanup.h to automate resource lifetime
> control in the gpio-simulator.

gpio-sim ?

...

> -	mutex_lock(&chip->lock);
> +	guard(mutex)(&chip->lock);

I hoped to see somehing like

	guard_mutex(...);

But looking into cleanup.h it seems to me that the lock itself on GPIO library
can be defined with respective class, no?

...

> +	scoped_guard(mutex, &chip->lock)
> +		bitmap_replace(chip->value_map, chip->value_map, bits, mask,
> +			       gc->ngpio);

Perhaps with {} ?

...

>  	int ret;
>  
> -	mutex_lock(&dev->lock);
> +	guard(mutex)(&dev->lock);
> +
>  	pdev = dev->pdev;
>  	if (pdev)
>  		ret = sprintf(page, "%s\n", dev_name(&pdev->dev));
>  	else
>  		ret = sprintf(page, "gpio-sim.%d\n", dev->id);
> -	mutex_unlock(&dev->lock);
>  
>  	return ret;

Now can be

	if (...)
		return ...
	else // if you wish (not needed)
		return ...

...

>  	int ret;
>  
> -	mutex_lock(&dev->lock);
> +	guard(mutex)(&dev->lock);
> +
>  	if (gpio_sim_device_is_live_unlocked(dev))
>  		ret = device_for_each_child(&dev->pdev->dev, &ctx,
>  					    gpio_sim_emit_chip_name);
>  	else
>  		ret = sprintf(page, "none\n");
> -	mutex_unlock(&dev->lock);
>  
>  	return ret;

As per above. And may be other functions as well.

...

>  	int ret;
>  
> -	mutex_lock(&dev->lock);
> -	ret = sprintf(page, "%s\n", line->name ?: "");
> -	mutex_unlock(&dev->lock);
> +	scoped_guard(mutex, &dev->lock)
> +		ret = sprintf(page, "%s\n", line->name ?: "");
>  
>  	return ret;

Why not

	guard(...);
	return sprintf(...);

?

-- 
With Best Regards,
Andy Shevchenko


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ