public inbox for linux-fbdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: fbtft: use guard() to simplify code
@ 2026-01-28 21:26 Paul Retourné
  2026-01-28 22:08 ` Andy Shevchenko
  2026-01-29  4:38 ` Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Retourné @ 2026-01-28 21:26 UTC (permalink / raw)
  To: andy, gregkh
  Cc: Paul Retourné, dri-devel, linux-fbdev, linux-staging,
	linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-29  9:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28 21:26 [PATCH] staging: fbtft: use guard() to simplify code Paul Retourné
2026-01-28 22:08 ` Andy Shevchenko
2026-01-29  9:18   ` Paul Retourne
2026-01-29  4:38 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox