diff mbox series

[f2fs-dev,23/31] mtd: block: use a simple bool to track open for write

Message ID 20230606073950.225178-24-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [f2fs-dev,01/31] block: also call ->open for incremental partition opens | expand

Commit Message

Christoph Hellwig June 6, 2023, 7:39 a.m. UTC
Instead of propagating the fmode_t, just use a bool to track if a mtd
block device was opened for writing.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/mtd/mtd_blkdevs.c    | 2 +-
 drivers/mtd/mtdblock.c       | 2 +-
 include/linux/mtd/blktrans.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

Richard Weinberger June 6, 2023, 8:24 a.m. UTC | #1
----- Ursprüngliche Mail -----
> Von: "hch" <hch@lst.de>
> Instead of propagating the fmode_t, just use a bool to track if a mtd
> block device was opened for writing.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/mtd/mtd_blkdevs.c    | 2 +-
> drivers/mtd/mtdblock.c       | 2 +-
> include/linux/mtd/blktrans.h | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
> index f0bb09fde95e3a..bd0b7545364349 100644
> --- a/drivers/mtd/mtd_blkdevs.c
> +++ b/drivers/mtd/mtd_blkdevs.c
> @@ -208,7 +208,7 @@ static int blktrans_open(struct gendisk *disk, fmode_t mode)
> 	ret = __get_mtd_device(dev->mtd);
> 	if (ret)
> 		goto error_release;
> -	dev->file_mode = mode;
> +	dev->writable = mode & FMODE_WRITE;
> 
> unlock:
> 	dev->open++;
> diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
> index a0a1194dc1d902..fa476fb4dffb6c 100644
> --- a/drivers/mtd/mtdblock.c
> +++ b/drivers/mtd/mtdblock.c
> @@ -294,7 +294,7 @@ static void mtdblock_release(struct mtd_blktrans_dev *mbd)
> 		 * It was the last usage. Free the cache, but only sync if
> 		 * opened for writing.
> 		 */
> -		if (mbd->file_mode & FMODE_WRITE)
> +		if (mbd->writable)
> 			mtd_sync(mbd->mtd);
> 		vfree(mtdblk->cache_data);
> 	}
> diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
> index 15cc9b95e32b52..6e471436bba556 100644
> --- a/include/linux/mtd/blktrans.h
> +++ b/include/linux/mtd/blktrans.h
> @@ -34,7 +34,7 @@ struct mtd_blktrans_dev {
> 	struct blk_mq_tag_set *tag_set;
> 	spinlock_t queue_lock;
> 	void *priv;
> -	fmode_t file_mode;
> +	bool writable;
> };

Acked-by: Richard Weinberger <richard@nod.at>

Thanks,
//richard
Christian Brauner June 7, 2023, 9 a.m. UTC | #2
On Tue, Jun 06, 2023 at 09:39:42AM +0200, Christoph Hellwig wrote:
> Instead of propagating the fmode_t, just use a bool to track if a mtd
> block device was opened for writing.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Looks good to me,
Acked-by: Christian Brauner <brauner@kernel.org>
Hannes Reinecke June 7, 2023, 1:07 p.m. UTC | #3
On 6/6/23 09:39, Christoph Hellwig wrote:
> Instead of propagating the fmode_t, just use a bool to track if a mtd
> block device was opened for writing.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   drivers/mtd/mtd_blkdevs.c    | 2 +-
>   drivers/mtd/mtdblock.c       | 2 +-
>   include/linux/mtd/blktrans.h | 2 +-
>   3 files changed, 3 insertions(+), 3 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index f0bb09fde95e3a..bd0b7545364349 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -208,7 +208,7 @@  static int blktrans_open(struct gendisk *disk, fmode_t mode)
 	ret = __get_mtd_device(dev->mtd);
 	if (ret)
 		goto error_release;
-	dev->file_mode = mode;
+	dev->writable = mode & FMODE_WRITE;
 
 unlock:
 	dev->open++;
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index a0a1194dc1d902..fa476fb4dffb6c 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -294,7 +294,7 @@  static void mtdblock_release(struct mtd_blktrans_dev *mbd)
 		 * It was the last usage. Free the cache, but only sync if
 		 * opened for writing.
 		 */
-		if (mbd->file_mode & FMODE_WRITE)
+		if (mbd->writable)
 			mtd_sync(mbd->mtd);
 		vfree(mtdblk->cache_data);
 	}
diff --git a/include/linux/mtd/blktrans.h b/include/linux/mtd/blktrans.h
index 15cc9b95e32b52..6e471436bba556 100644
--- a/include/linux/mtd/blktrans.h
+++ b/include/linux/mtd/blktrans.h
@@ -34,7 +34,7 @@  struct mtd_blktrans_dev {
 	struct blk_mq_tag_set *tag_set;
 	spinlock_t queue_lock;
 	void *priv;
-	fmode_t file_mode;
+	bool writable;
 };
 
 struct mtd_blktrans_ops {