Skip to contentSkip to conversation

nvmem: core: fix the return value check when calling the notifier chain

PATCH In review Bartosz Golaszewski 2 participants 5 messages Feb 14, 2019 – Feb 15, 2019

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

PATCH 1/1 nvmem: core: fix the return value check when calling the notifier chain

From: Bartosz Golaszewski <[email protected]>

blocking_notifier_call_chain() returns the value returned by the last registered callback. A positive return value doesn't indicate an error so check only if it's negative.

Fixes bee1138bea15 ("nvmem: add a notifier chain")
---
 drivers/nvmem/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvmem/core.c +1 -1
index f7301bb4ef3b..a3bed2d9aec7 100644
@@ -687,7 +687,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 		goto err_remove_cells;
 
 	rval = blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
-	if (rval)
+	if (rval < 0)
 		goto err_remove_cells;
 
 	return nvmem;
Signature · 1 line
2.20.1
#1 lore raw

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 691

Quoted 11 lines · Bartosz Golaszewski
drivers/nvmem/core.c +1 -1
index f7301bb4ef3b..a3bed2d9aec7 100644
@@ -687,7 +687,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
  		goto err_remove_cells;
 
  	rval = blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
-	if (rval)
+	if (rval < 0)
  		goto err_remove_cells;

rval will be masked with STOP MASK, so the above statement could be false even if we have error. So you should consider returning an errono which can be understood by user:

may be something like this:

if (rval & NOTIFY_STOP_MASK) {
	rval = notifier_to_errno(rval);
	goto err_remove_cells
}

--srini

#2 lore raw

pt., 15 lut 2019 o 10:28 Srinivas Kandagatla
<[email protected]> napisał(a):

Quoted 20 lines · Bartosz Golaszewski

drivers/nvmem/core.c struct nvmem_device *nvmem_register(const struct nvmem_config *config) · line 691

Quoted 11 lines
drivers/nvmem/core.c +1 -1
index f7301bb4ef3b..a3bed2d9aec7 100644
@@ -687,7 +687,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
              goto err_remove_cells;
 
      rval = blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem);
-     if (rval)
+     if (rval < 0)
              goto err_remove_cells;

rval will be masked with STOP MASK, so the above statement could be false even if we have error.
So you should consider returning an errono which can be understood by user:

Quoted 7 lines

may be something like this:

if (rval & NOTIFY_STOP_MASK) {
        rval = notifier_to_errno(rval);
        goto err_remove_cells
}

Actually I'm now thinking we can remove this check at all - most users never check the return values of notifier chain calls. This function cannot fail in itself. What do you think?

Bart

#3 lore raw
Quoted 6 lines · Bartosz Golaszewski
Quoted 6 lines

rval will be masked with STOP MASK, so the above statement could be false even if we have error.
So you should consider returning an errono which can be understood by user:

may be something like this:

Quoted 8 lines
Quoted 5 lines
if (rval & NOTIFY_STOP_MASK) {
         rval = notifier_to_errno(rval);
         goto err_remove_cells
}

Actually I'm now thinking we can remove this check at all - most users never check the return values of notifier chain calls. This function cannot fail in itself. What do you think?

Thats even better, I was about to suggest the same on the fact that we should allow nvmem provider to register to be successful irrespective of the notifier callback failures.

--srini

#4 lore raw

pt., 15 lut 2019 o 11:26 Srinivas Kandagatla
<[email protected]> napisał(a):

Quoted 15 lines · Bartosz Golaszewski
Quoted 11 lines
Quoted 11 lines

rval will be masked with STOP MASK, so the above statement could be false even if we have error.
So you should consider returning an errono which can be understood by user:

may be something like this:

if (rval & NOTIFY_STOP_MASK) {
         rval = notifier_to_errno(rval);
         goto err_remove_cells
}
Quoted 8 lines
Quoted 3 lines

Actually I'm now thinking we can remove this check at all - most users never check the return values of notifier chain calls. This function cannot fail in itself. What do you think?

Thats even better, I was about to suggest the same on the fact that we should allow nvmem provider to register to be successful irrespective of the notifier callback failures.

--srini

Right, I sent a different patch.

Bart