[RFC PATCHv5 3/6] zram: take write lock in wb limit store handlers

Sergey Senozhatsky posted 6 patches 1 week, 4 days ago
There is a newer version of this series
[RFC PATCHv5 3/6] zram: take write lock in wb limit store handlers
Posted by Sergey Senozhatsky 1 week, 4 days ago
Write device attrs handlers should take write zram init_lock.
While at it, fixup coding styles.

Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 7904159e9226..71f37b960812 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -519,7 +519,8 @@ struct zram_wb_req {
 };
 
 static ssize_t writeback_limit_enable_store(struct device *dev,
-		struct device_attribute *attr, const char *buf, size_t len)
+					    struct device_attribute *attr,
+					    const char *buf, size_t len)
 {
 	struct zram *zram = dev_to_zram(dev);
 	u64 val;
@@ -528,18 +529,19 @@ static ssize_t writeback_limit_enable_store(struct device *dev,
 	if (kstrtoull(buf, 10, &val))
 		return ret;
 
-	down_read(&zram->init_lock);
+	down_write(&zram->init_lock);
 	spin_lock(&zram->wb_limit_lock);
 	zram->wb_limit_enable = val;
 	spin_unlock(&zram->wb_limit_lock);
-	up_read(&zram->init_lock);
+	up_write(&zram->init_lock);
 	ret = len;
 
 	return ret;
 }
 
 static ssize_t writeback_limit_enable_show(struct device *dev,
-		struct device_attribute *attr, char *buf)
+					   struct device_attribute *attr,
+					   char *buf)
 {
 	bool val;
 	struct zram *zram = dev_to_zram(dev);
@@ -554,7 +556,8 @@ static ssize_t writeback_limit_enable_show(struct device *dev,
 }
 
 static ssize_t writeback_limit_store(struct device *dev,
-		struct device_attribute *attr, const char *buf, size_t len)
+				     struct device_attribute *attr,
+				     const char *buf, size_t len)
 {
 	struct zram *zram = dev_to_zram(dev);
 	u64 val;
@@ -563,11 +566,11 @@ static ssize_t writeback_limit_store(struct device *dev,
 	if (kstrtoull(buf, 10, &val))
 		return ret;
 
-	down_read(&zram->init_lock);
+	down_write(&zram->init_lock);
 	spin_lock(&zram->wb_limit_lock);
 	zram->bd_wb_limit = val;
 	spin_unlock(&zram->wb_limit_lock);
-	up_read(&zram->init_lock);
+	up_write(&zram->init_lock);
 	ret = len;
 
 	return ret;
-- 
2.52.0.rc1.455.g30608eb744-goog
Re: [RFC PATCHv5 3/6] zram: take write lock in wb limit store handlers
Posted by Brian Geffon 1 week, 4 days ago
On Thu, Nov 20, 2025 at 10:22 AM Sergey Senozhatsky
<senozhatsky@chromium.org> wrote:
>
> Write device attrs handlers should take write zram init_lock.
> While at it, fixup coding styles.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>

Reviewed-by: Brian Geffon <bgeffon@google.com>

> ---
>  drivers/block/zram/zram_drv.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 7904159e9226..71f37b960812 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -519,7 +519,8 @@ struct zram_wb_req {
>  };
>
>  static ssize_t writeback_limit_enable_store(struct device *dev,
> -               struct device_attribute *attr, const char *buf, size_t len)
> +                                           struct device_attribute *attr,
> +                                           const char *buf, size_t len)
>  {
>         struct zram *zram = dev_to_zram(dev);
>         u64 val;
> @@ -528,18 +529,19 @@ static ssize_t writeback_limit_enable_store(struct device *dev,
>         if (kstrtoull(buf, 10, &val))
>                 return ret;
>
> -       down_read(&zram->init_lock);
> +       down_write(&zram->init_lock);
>         spin_lock(&zram->wb_limit_lock);
>         zram->wb_limit_enable = val;
>         spin_unlock(&zram->wb_limit_lock);
> -       up_read(&zram->init_lock);
> +       up_write(&zram->init_lock);
>         ret = len;
>
>         return ret;
>  }
>
>  static ssize_t writeback_limit_enable_show(struct device *dev,
> -               struct device_attribute *attr, char *buf)
> +                                          struct device_attribute *attr,
> +                                          char *buf)
>  {
>         bool val;
>         struct zram *zram = dev_to_zram(dev);
> @@ -554,7 +556,8 @@ static ssize_t writeback_limit_enable_show(struct device *dev,
>  }
>
>  static ssize_t writeback_limit_store(struct device *dev,
> -               struct device_attribute *attr, const char *buf, size_t len)
> +                                    struct device_attribute *attr,
> +                                    const char *buf, size_t len)
>  {
>         struct zram *zram = dev_to_zram(dev);
>         u64 val;
> @@ -563,11 +566,11 @@ static ssize_t writeback_limit_store(struct device *dev,
>         if (kstrtoull(buf, 10, &val))
>                 return ret;
>
> -       down_read(&zram->init_lock);
> +       down_write(&zram->init_lock);
>         spin_lock(&zram->wb_limit_lock);
>         zram->bd_wb_limit = val;
>         spin_unlock(&zram->wb_limit_lock);
> -       up_read(&zram->init_lock);
> +       up_write(&zram->init_lock);
>         ret = len;
>
>         return ret;
> --
> 2.52.0.rc1.455.g30608eb744-goog
>