Skip to contentSkip to conversation

nvmem: fix nvmem_cell_get_from_lookup()

PATCH In review Bartosz Golaszewski 2 participants 3 messages Oct 1, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: fix nvmem_cell_get_from_lookup()

From: Bartosz Golaszewski <[email protected]>

We check if the pointer returned by __nvmem_device_get() is not NULL while we should actually check if it is not IS_ERR(nvmem). Fix it.

While we're at it: fix the next error path where we should assign an error value to cell before returning.

---
 drivers/nvmem/core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvmem/core.c +3 -2
index ad1227df1984..8249621d11a6 100644
@@ -952,9 +952,9 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
 		    (strcmp(lookup->con_id, con_id) == 0)) {
 			/* This is the right entry. */
 			nvmem = __nvmem_device_get(NULL, lookup->nvmem_name);
-			if (!nvmem) {
+			if (IS_ERR(nvmem)) {
 				/* Provider may not be registered yet. */
-				cell = ERR_PTR(-EPROBE_DEFER);
+				cell = (struct nvmem_cell *)nvmem;
 				goto out;
 			}
 
@@ -962,6 +962,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
 						       lookup->cell_name);
 			if (!cell) {
 				__nvmem_device_put(nvmem);
+				cell = ERR_PTR(-ENOENT);
 				goto out;
 			}
 		}
Signature · 1 line
2.18.0
#1 lore raw
Quoted 18 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

We check if the pointer returned by __nvmem_device_get() is not NULL while we should actually check if it is not IS_ERR(nvmem). Fix it.

While we're at it: fix the next error path where we should assign an error value to cell before returning.

---
  drivers/nvmem/core.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/nvmem/core.c +0 -0
index ad1227df1984..8249621d11a6 100644

drivers/nvmem/core.c nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) · line 957

Quoted 8 lines
drivers/nvmem/core.c +2 -2
@@ -952,9 +952,9 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
  		    (strcmp(lookup->con_id, con_id) == 0)) {
  			/* This is the right entry. */
  			nvmem = __nvmem_device_get(NULL, lookup->nvmem_name);
-			if (!nvmem) {
+			if (IS_ERR(nvmem)) {
  				/* Provider may not be registered yet. */
-				cell = ERR_PTR(-EPROBE_DEFER);
+				cell = (struct nvmem_cell *)nvmem;

perhaps ERR_CAST() would better indicate the intent here?

Quoted 12 lines
drivers/nvmem/core.c +1 -0
  				goto out;
  			}
 
@@ -962,6 +962,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
  						       lookup->cell_name);
  			if (!cell) {
  				__nvmem_device_put(nvmem);
+				cell = ERR_PTR(-ENOENT);
  				goto out;
  			}
  		}
#2 lore raw

pon., 1 pa? 2018 o 18:03 David Lechner <[email protected]> napisa?(a):

Quoted 15 lines · Bartosz Golaszewski
Quoted 13 lines

From: Bartosz Golaszewski <[email protected]>

We check if the pointer returned by __nvmem_device_get() is not NULL while we should actually check if it is not IS_ERR(nvmem). Fix it.

While we're at it: fix the next error path where we should assign an error value to cell before returning.

---
  drivers/nvmem/core.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/nvmem/core.c nvmem_cell_get_from_lookup(struct device *dev, const char *con_id) · line 957

Quoted 13 lines
drivers/nvmem/core.c +2 -2
index ad1227df1984..8249621d11a6 100644
@@ -952,9 +952,9 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
                  (strcmp(lookup->con_id, con_id) == 0)) {
                      /* This is the right entry. */
                      nvmem = __nvmem_device_get(NULL, lookup->nvmem_name);
-                     if (!nvmem) {
+                     if (IS_ERR(nvmem)) {
                              /* Provider may not be registered yet. */
-                             cell = ERR_PTR(-EPROBE_DEFER);
+                             cell = (struct nvmem_cell *)nvmem;

perhaps ERR_CAST() would better indicate the intent here?

Wow so that exists too...

Thanks, I'll resend tomorrow.

Bart

Quoted 13 lines
Quoted 12 lines
drivers/nvmem/core.c +1 -0
                              goto out;
                      }
 
@@ -962,6 +962,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)
                                                     lookup->cell_name);
                      if (!cell) {
                              __nvmem_device_put(nvmem);
+                             cell = ERR_PTR(-ENOENT);
                              goto out;
                      }
              }