linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open()
@ 2021-02-17 21:18 Alexander A Sverdlin
  2021-02-17 21:18 ` [PATCH 2/2] mtd: char: Get rid of Big MTD Lock Alexander A Sverdlin
  2021-03-02 17:14 ` [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Miquel Raynal
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander A Sverdlin @ 2021-02-17 21:18 UTC (permalink / raw)
  To: linux-mtd
  Cc: Richard Weinberger, Alexander Sverdlin, Vignesh Raghavendra,
	linux-kernel, Miquel Raynal

From: Alexander Sverdlin <alexander.sverdlin@nokia.com>

It looks unnecessary in the function, remove it from the function
having in mind to remove it completely.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
---
 drivers/mtd/mtdchar.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 323035d..f31390d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -58,13 +58,10 @@ static int mtdchar_open(struct inode *inode, struct file *file)
 	if ((file->f_mode & FMODE_WRITE) && (minor & 1))
 		return -EACCES;
 
-	mutex_lock(&mtd_mutex);
 	mtd = get_mtd_device(NULL, devnum);
 
-	if (IS_ERR(mtd)) {
-		ret = PTR_ERR(mtd);
-		goto out;
-	}
+	if (IS_ERR(mtd))
+		return PTR_ERR(mtd);
 
 	if (mtd->type == MTD_ABSENT) {
 		ret = -ENODEV;
@@ -84,13 +81,10 @@ static int mtdchar_open(struct inode *inode, struct file *file)
 	}
 	mfi->mtd = mtd;
 	file->private_data = mfi;
-	mutex_unlock(&mtd_mutex);
 	return 0;
 
 out1:
 	put_mtd_device(mtd);
-out:
-	mutex_unlock(&mtd_mutex);
 	return ret;
 } /* mtdchar_open */
 
-- 
2.10.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* [PATCH 2/2] mtd: char: Get rid of Big MTD Lock
  2021-02-17 21:18 [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Alexander A Sverdlin
@ 2021-02-17 21:18 ` Alexander A Sverdlin
  2021-03-02 17:13   ` Miquel Raynal
  2021-03-02 17:14 ` [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Alexander A Sverdlin @ 2021-02-17 21:18 UTC (permalink / raw)
  To: linux-mtd
  Cc: Richard Weinberger, Alexander Sverdlin, Vignesh Raghavendra,
	linux-kernel, Miquel Raynal

From: Alexander Sverdlin <alexander.sverdlin@nokia.com>

Get rid of central chrdev MTD lock, which prevents simultaneous operations
on completely independent physical MTD chips. Replace it with newly
introduced per-master mutex.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
---
 drivers/mtd/mtdchar.c   | 14 ++++++++------
 drivers/mtd/mtdcore.c   |  1 +
 include/linux/mtd/mtd.h |  1 +
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f31390d..57c4a2f 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -27,8 +27,6 @@
 
 #include "mtdcore.h"
 
-static DEFINE_MUTEX(mtd_mutex);
-
 /*
  * Data structure to hold the pointer to the mtd device as well
  * as mode information of various use cases.
@@ -1020,11 +1018,14 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg)
 
 static long mtdchar_unlocked_ioctl(struct file *file, u_int cmd, u_long arg)
 {
+	struct mtd_file_info *mfi = file->private_data;
+	struct mtd_info *mtd = mfi->mtd;
+	struct mtd_info *master = mtd_get_master(mtd);
 	int ret;
 
-	mutex_lock(&mtd_mutex);
+	mutex_lock(&master->master.chrdev_lock);
 	ret = mtdchar_ioctl(file, cmd, arg);
-	mutex_unlock(&mtd_mutex);
+	mutex_unlock(&master->master.chrdev_lock);
 
 	return ret;
 }
@@ -1045,10 +1046,11 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 {
 	struct mtd_file_info *mfi = file->private_data;
 	struct mtd_info *mtd = mfi->mtd;
+	struct mtd_info *master = mtd_get_master(mtd);
 	void __user *argp = compat_ptr(arg);
 	int ret = 0;
 
-	mutex_lock(&mtd_mutex);
+	mutex_lock(&master->master.chrdev_lock);
 
 	switch (cmd) {
 	case MEMWRITEOOB32:
@@ -1111,7 +1113,7 @@ static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd,
 		ret = mtdchar_ioctl(file, cmd, (unsigned long)argp);
 	}
 
-	mutex_unlock(&mtd_mutex);
+	mutex_unlock(&master->master.chrdev_lock);
 
 	return ret;
 }
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 2d6423d..0b09597 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -773,6 +773,7 @@ static void mtd_set_dev_defaults(struct mtd_info *mtd)
 
 	INIT_LIST_HEAD(&mtd->partitions);
 	mutex_init(&mtd->master.partitions_lock);
+	mutex_init(&mtd->master.chrdev_lock);
 }
 
 /**
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 157357e..ceabc2c 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -229,6 +229,7 @@ struct mtd_part {
  */
 struct mtd_master {
 	struct mutex partitions_lock;
+	struct mutex chrdev_lock;
 	unsigned int suspended : 1;
 };
 
-- 
2.10.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 2/2] mtd: char: Get rid of Big MTD Lock
  2021-02-17 21:18 ` [PATCH 2/2] mtd: char: Get rid of Big MTD Lock Alexander A Sverdlin
@ 2021-03-02 17:13   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2021-03-02 17:13 UTC (permalink / raw)
  To: Alexander A Sverdlin, linux-mtd
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-kernel

On Wed, 2021-02-17 at 21:18:45 UTC, Alexander A Sverdlin wrote:
> From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> 
> Get rid of central chrdev MTD lock, which prevents simultaneous operations
> on completely independent physical MTD chips. Replace it with newly
> introduced per-master mutex.
> 
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open()
  2021-02-17 21:18 [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Alexander A Sverdlin
  2021-02-17 21:18 ` [PATCH 2/2] mtd: char: Get rid of Big MTD Lock Alexander A Sverdlin
@ 2021-03-02 17:14 ` Miquel Raynal
  1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2021-03-02 17:14 UTC (permalink / raw)
  To: Alexander A Sverdlin, linux-mtd
  Cc: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra, linux-kernel

On Wed, 2021-02-17 at 21:18:44 UTC, Alexander A Sverdlin wrote:
> From: Alexander Sverdlin <alexander.sverdlin@nokia.com>
> 
> It looks unnecessary in the function, remove it from the function
> having in mind to remove it completely.
> 
> Signed-off-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2021-03-03 19:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-17 21:18 [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Alexander A Sverdlin
2021-02-17 21:18 ` [PATCH 2/2] mtd: char: Get rid of Big MTD Lock Alexander A Sverdlin
2021-03-02 17:13   ` Miquel Raynal
2021-03-02 17:14 ` [PATCH 1/2] mtd: char: Drop mtd_mutex usage from mtdchar_open() Miquel Raynal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).