drivers/staging/fbtft/fb_ssd1305.c | 4 ++-- drivers/staging/fbtft/fb_ssd1306.c | 4 ++-- drivers/staging/fbtft/fbtft-sysfs.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-)
Use guard() to simplify mutex locking. No functional change.
Signed-off-by: Paul Retourné <paul.retourne@orange.fr>
---
drivers/staging/fbtft/fb_ssd1305.c | 4 ++--
drivers/staging/fbtft/fb_ssd1306.c | 4 ++--
drivers/staging/fbtft/fbtft-sysfs.c | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/staging/fbtft/fb_ssd1305.c b/drivers/staging/fbtft/fb_ssd1305.c
index 020fe48fed0be..d9215cb35e8f8 100644
--- a/drivers/staging/fbtft/fb_ssd1305.c
+++ b/drivers/staging/fbtft/fb_ssd1305.c
@@ -10,6 +10,7 @@
#include <linux/init.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
+#include <linux/cleanup.h>
#include "fbtft.h"
@@ -35,12 +36,11 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
if (par->gamma.curves[0] == 0) {
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
if (par->info->var.yres == 64)
par->gamma.curves[0] = 0xCF;
else
par->gamma.curves[0] = 0x8F;
- mutex_unlock(&par->gamma.lock);
}
/* Set Display OFF */
diff --git a/drivers/staging/fbtft/fb_ssd1306.c b/drivers/staging/fbtft/fb_ssd1306.c
index 478d710469b91..c230d599ff928 100644
--- a/drivers/staging/fbtft/fb_ssd1306.c
+++ b/drivers/staging/fbtft/fb_ssd1306.c
@@ -10,6 +10,7 @@
#include <linux/init.h>
#include <linux/gpio/consumer.h>
#include <linux/delay.h>
+#include <linux/cleanup.h>
#include "fbtft.h"
@@ -34,12 +35,11 @@ static int init_display(struct fbtft_par *par)
par->fbtftops.reset(par);
if (par->gamma.curves[0] == 0) {
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
if (par->info->var.yres == 64)
par->gamma.curves[0] = 0xCF;
else
par->gamma.curves[0] = 0x8F;
- mutex_unlock(&par->gamma.lock);
}
/* Set Display OFF */
diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
index e45c90a03a903..72d6cf899336e 100644
--- a/drivers/staging/fbtft/fbtft-sysfs.c
+++ b/drivers/staging/fbtft/fbtft-sysfs.c
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
+#include <linux/cleanup.h>
+
#include "fbtft.h"
#include "internal.h"
@@ -95,14 +97,13 @@ sprintf_gamma(struct fbtft_par *par, u32 *curves, char *buf)
ssize_t len = 0;
unsigned int i, j;
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
for (i = 0; i < par->gamma.num_curves; i++) {
for (j = 0; j < par->gamma.num_values; j++)
len += scnprintf(&buf[len], PAGE_SIZE,
"%04x ", curves[i * par->gamma.num_values + j]);
buf[len - 1] = '\n';
}
- mutex_unlock(&par->gamma.lock);
return len;
}
@@ -124,11 +125,10 @@ static ssize_t store_gamma_curve(struct device *device,
if (ret)
return ret;
- mutex_lock(&par->gamma.lock);
+ guard(mutex)(&par->gamma.lock);
memcpy(par->gamma.curves, tmp_curves,
par->gamma.num_curves * par->gamma.num_values *
sizeof(tmp_curves[0]));
- mutex_unlock(&par->gamma.lock);
return count;
}
--
2.52.0
On Wed, Jan 28, 2026 at 10:26:42PM +0100, Paul Retourné wrote: > Use guard() to simplify mutex locking. No functional change. It's best to use guard() for new code, not touching existing code as: > 3 files changed, 8 insertions(+), 8 deletions(-) This made no change overall at all :( thanks, greg k-h
On Wed, Jan 28, 2026 at 10:26:42PM +0100, Paul Retourné wrote:
> Use guard() to simplify mutex locking. No functional change.
...
> #include <linux/init.h>
> #include <linux/gpio/consumer.h>
> #include <linux/delay.h>
> +#include <linux/cleanup.h>
Try to squeeze the new inclusion into the longest ordered chain with some
pieces left unordered. With the given context the lease is to put it before
delay.h, but maybe there is a better place.
...
> if (par->gamma.curves[0] == 0) {
> - mutex_lock(&par->gamma.lock);
> + guard(mutex)(&par->gamma.lock);
> if (par->info->var.yres == 64)
> par->gamma.curves[0] = 0xCF;
> else
> par->gamma.curves[0] = 0x8F;
> - mutex_unlock(&par->gamma.lock);
> }
This has close to 0 added value. Don't do conversion just for fun.
...
> --- a/drivers/staging/fbtft/fb_ssd1306.c
> +++ b/drivers/staging/fbtft/fb_ssd1306.c
Ditto.
...
Sorry, but I don't see much value in this change.
--
With Best Regards,
Andy Shevchenko
On 1/28/26 23:08, Andy Shevchenko wrote: > Sorry, but I don't see much value in this change. Understood, I see the problem, I'll try to do changes that are actually useful in the future. Thank you for looking at it and taking the time to answer. -- Paul Retourné
© 2016 - 2026 Red Hat, Inc.