Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1657053 > unrolled thread

[PATCH 0/3] nvmem: core: series with smaller refactorings

Started byHeiner Kallweit <hkallweit1@gmail.com>
First post2017-06-04 12:50 +0200
Last post2017-06-04 13:10 +0200
Articles 6 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/3] nvmem: core: series with smaller refactorings Heiner Kallweit <hkallweit1@gmail.com> - 2017-06-04 12:50 +0200
    [PATCH 1/3] nvmem: core: remove member users from struct nvmem_device Heiner Kallweit <hkallweit1@gmail.com> - 2017-06-04 13:10 +0200
      Re: [PATCH 1/3] nvmem: core: remove member users from struct  nvmem_device Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2017-06-07 17:40 +0200
    [PATCH 2/3] nvmem: core: add locking to nvmem_find_cell Heiner Kallweit <hkallweit1@gmail.com> - 2017-06-04 13:10 +0200
      Re: [PATCH 2/3] nvmem: core: add locking to nvmem_find_cell Srinivas Kandagatla <srinivas.kandagatla@linaro.org> - 2017-06-07 17:40 +0200
    [PATCH 3/3] nvmem: core: remove nvmem_mutex Heiner Kallweit <hkallweit1@gmail.com> - 2017-06-04 13:10 +0200

#1657053 — [PATCH 0/3] nvmem: core: series with smaller refactorings

FromHeiner Kallweit <hkallweit1@gmail.com>
Date2017-06-04 12:50 +0200
Subject[PATCH 0/3] nvmem: core: series with smaller refactorings
Message-ID<tOBgB-3Og-13@gated-at.bofh.it>
Series with smaller refactorings of the nvmem core.

Heiner Kallweit (3):
  nvmem: core: remove member users from struct nvmem_device
  nvmem: core: add locking to nvmem_find_cell
  nvmem: core: remove nvmem_mutex

 drivers/nvmem/core.c | 37 +++++++++----------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

-- 
2.13.0

[toc] | [next] | [standalone]


#1657054 — [PATCH 1/3] nvmem: core: remove member users from struct nvmem_device

FromHeiner Kallweit <hkallweit1@gmail.com>
Date2017-06-04 13:10 +0200
Subject[PATCH 1/3] nvmem: core: remove member users from struct nvmem_device
Message-ID<tOBzX-4bP-1@gated-at.bofh.it>
In reply to#1657053
Member users is used only to check whether we're allowed to remove
the module. So in case of built-in it's not used at all and in case
that owner is a module we have the module refcount for the same
purpose already. Whenever users is incremented the owner's refcount
is incremented too. Therefore users isn't needed.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/nvmem/core.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 8c830a80..4e07f3f8 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -33,7 +33,6 @@ struct nvmem_device {
 	int			word_size;
 	int			ncells;
 	int			id;
-	int			users;
 	size_t			size;
 	bool			read_only;
 	int			flags;
@@ -517,13 +516,6 @@ EXPORT_SYMBOL_GPL(nvmem_register);
  */
 int nvmem_unregister(struct nvmem_device *nvmem)
 {
-	mutex_lock(&nvmem_mutex);
-	if (nvmem->users) {
-		mutex_unlock(&nvmem_mutex);
-		return -EBUSY;
-	}
-	mutex_unlock(&nvmem_mutex);
-
 	if (nvmem->flags & FLAG_COMPAT)
 		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
 
@@ -562,7 +554,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 		}
 	}
 
-	nvmem->users++;
 	mutex_unlock(&nvmem_mutex);
 
 	if (!try_module_get(nvmem->owner)) {
@@ -570,10 +561,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 			"could not increase module refcount for cell %s\n",
 			nvmem->name);
 
-		mutex_lock(&nvmem_mutex);
-		nvmem->users--;
-		mutex_unlock(&nvmem_mutex);
-
 		return ERR_PTR(-EINVAL);
 	}
 
@@ -583,9 +570,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 static void __nvmem_device_put(struct nvmem_device *nvmem)
 {
 	module_put(nvmem->owner);
-	mutex_lock(&nvmem_mutex);
-	nvmem->users--;
-	mutex_unlock(&nvmem_mutex);
 }
 
 static int nvmem_match(struct device *dev, void *data)
-- 
2.13.0

[toc] | [prev] | [next] | [standalone]


#1659929 — Re: [PATCH 1/3] nvmem: core: remove member users from struct nvmem_device

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2017-06-07 17:40 +0200
SubjectRe: [PATCH 1/3] nvmem: core: remove member users from struct nvmem_device
Message-ID<tPLdT-8rQ-1@gated-at.bofh.it>
In reply to#1657054

On 04/06/17 12:01, Heiner Kallweit wrote:
> Member users is used only to check whether we're allowed to remove
> the module. So in case of built-in it's not used at all and in case

nvmem providers doesn't have to be independent drivers, providers could 
be part of the other driver which can dynamically register and 
unregister nvmem providers. For example at24 and at25 drivers.

This patch will break such cases !!



> that owner is a module we have the module refcount for the same
> purpose already. Whenever users is incremented the owner's refcount
> is incremented too. Therefore users isn't needed.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/nvmem/core.c | 16 ----------------
>  1 file changed, 16 deletions(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 8c830a80..4e07f3f8 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -33,7 +33,6 @@ struct nvmem_device {
>  	int			word_size;
>  	int			ncells;
>  	int			id;
> -	int			users;
>  	size_t			size;
>  	bool			read_only;
>  	int			flags;
> @@ -517,13 +516,6 @@ EXPORT_SYMBOL_GPL(nvmem_register);
>   */
>  int nvmem_unregister(struct nvmem_device *nvmem)
>  {
> -	mutex_lock(&nvmem_mutex);
> -	if (nvmem->users) {
> -		mutex_unlock(&nvmem_mutex);
> -		return -EBUSY;
> -	}
> -	mutex_unlock(&nvmem_mutex);
> -
>  	if (nvmem->flags & FLAG_COMPAT)
>  		device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom);
>
> @@ -562,7 +554,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
>  		}
>  	}
>
> -	nvmem->users++;
>  	mutex_unlock(&nvmem_mutex);
>
>  	if (!try_module_get(nvmem->owner)) {
> @@ -570,10 +561,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
>  			"could not increase module refcount for cell %s\n",
>  			nvmem->name);
>
> -		mutex_lock(&nvmem_mutex);
> -		nvmem->users--;
> -		mutex_unlock(&nvmem_mutex);
> -
>  		return ERR_PTR(-EINVAL);
>  	}
>
> @@ -583,9 +570,6 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
>  static void __nvmem_device_put(struct nvmem_device *nvmem)
>  {
>  	module_put(nvmem->owner);
> -	mutex_lock(&nvmem_mutex);
> -	nvmem->users--;
> -	mutex_unlock(&nvmem_mutex);
>  }
>
>  static int nvmem_match(struct device *dev, void *data)
>

[toc] | [prev] | [next] | [standalone]


#1657055 — [PATCH 2/3] nvmem: core: add locking to nvmem_find_cell

FromHeiner Kallweit <hkallweit1@gmail.com>
Date2017-06-04 13:10 +0200
Subject[PATCH 2/3] nvmem: core: add locking to nvmem_find_cell
Message-ID<tOBzX-4bP-3@gated-at.bofh.it>
In reply to#1657053
Adding entries to nvmem_cells and deleting entries from it is
protected by nvmem_cells_mutex. Therefore this mutex should
also protect iterating over the list.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/nvmem/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 4e07f3f8..1aa6d25a 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -286,9 +286,15 @@ static struct nvmem_cell *nvmem_find_cell(const char *cell_id)
 {
 	struct nvmem_cell *p;
 
+	mutex_lock(&nvmem_cells_mutex);
+
 	list_for_each_entry(p, &nvmem_cells, node)
-		if (p && !strcmp(p->name, cell_id))
+		if (p && !strcmp(p->name, cell_id)) {
+			mutex_unlock(&nvmem_cells_mutex);
 			return p;
+		}
+
+	mutex_unlock(&nvmem_cells_mutex);
 
 	return NULL;
 }
-- 
2.13.0

[toc] | [prev] | [next] | [standalone]


#1659936 — Re: [PATCH 2/3] nvmem: core: add locking to nvmem_find_cell

FromSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Date2017-06-07 17:40 +0200
SubjectRe: [PATCH 2/3] nvmem: core: add locking to nvmem_find_cell
Message-ID<tPLdT-8rQ-13@gated-at.bofh.it>
In reply to#1657055

On 04/06/17 12:01, Heiner Kallweit wrote:
> Adding entries to nvmem_cells and deleting entries from it is
> protected by nvmem_cells_mutex. Therefore this mutex should
> also protect iterating over the list.
>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/nvmem/core.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 4e07f3f8..1aa6d25a 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
> @@ -286,9 +286,15 @@ static struct nvmem_cell *nvmem_find_cell(const char *cell_id)
>  {
>  	struct nvmem_cell *p;
>
> +	mutex_lock(&nvmem_cells_mutex);
> +
>  	list_for_each_entry(p, &nvmem_cells, node)
> -		if (p && !strcmp(p->name, cell_id))
> +		if (p && !strcmp(p->name, cell_id)) {
> +			mutex_unlock(&nvmem_cells_mutex);
>  			return p;
> +		}
> +
> +	mutex_unlock(&nvmem_cells_mutex);
>
Thanks for the patch, I will queue this up.

Thanks,
srini
>  	return NULL;
>  }
>

[toc] | [prev] | [next] | [standalone]


#1657056 — [PATCH 3/3] nvmem: core: remove nvmem_mutex

FromHeiner Kallweit <hkallweit1@gmail.com>
Date2017-06-04 13:10 +0200
Subject[PATCH 3/3] nvmem: core: remove nvmem_mutex
Message-ID<tOBzX-4bP-5@gated-at.bofh.it>
In reply to#1657053
Mutex nvmem_mutex is used in __nvmem_device_get only and isn't needed
due to:

- of_nvmem_find just calls bus_find_device which doesn't need locking
- nvmem_find_cell is protected by nvmem_cells_mutex

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/nvmem/core.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 1aa6d25a..783eb431 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -55,7 +55,6 @@ struct nvmem_cell {
 	struct list_head	node;
 };
 
-static DEFINE_MUTEX(nvmem_mutex);
 static DEFINE_IDA(nvmem_ida);
 
 static LIST_HEAD(nvmem_cells);
@@ -538,14 +537,10 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 {
 	struct nvmem_device *nvmem = NULL;
 
-	mutex_lock(&nvmem_mutex);
-
 	if (np) {
 		nvmem = of_nvmem_find(np);
-		if (!nvmem) {
-			mutex_unlock(&nvmem_mutex);
+		if (!nvmem)
 			return ERR_PTR(-EPROBE_DEFER);
-		}
 	} else {
 		struct nvmem_cell *cell = nvmem_find_cell(cell_id);
 
@@ -554,14 +549,10 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
 			*cellp = cell;
 		}
 
-		if (!nvmem) {
-			mutex_unlock(&nvmem_mutex);
+		if (!nvmem)
 			return ERR_PTR(-ENOENT);
-		}
 	}
 
-	mutex_unlock(&nvmem_mutex);
-
 	if (!try_module_get(nvmem->owner)) {
 		dev_err(&nvmem->dev,
 			"could not increase module refcount for cell %s\n",
-- 
2.13.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web