Skip to contentSkip to conversation

clk: qcom: Return expected ENOMEM error on dynamic allocation failure

PATCH Applied Vladimir Zapolskiy 4 participants 5 messages Jun 29 – Aug 3

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

PATCH 1/1 clk: qcom: Return expected ENOMEM error on dynamic allocation failure

If a dynamic memory allocation fails, the returned error code in clock controller driver probe functions on a few legacy platforms should be set to -ENOMEM instead of -EINVAL.

Fixes ee15faffef11 ("clk: qcom: common: Add API to register board clocks backwards compatibly")
---
 drivers/clk/qcom/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/common.c +2 -2
index eec369d2173b..0e8f380873af 100644
@@ -169,7 +169,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
 	if (!node) {
 		fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL);
 		if (!fixed)
-			return -EINVAL;
+			return -ENOMEM;
 
 		fixed->fixed_rate = rate;
 		fixed->hw.init = &init_data;
@@ -186,7 +186,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
 	if (add_factor) {
 		factor = devm_kzalloc(dev, sizeof(*factor), GFP_KERNEL);
 		if (!factor)
-			return -EINVAL;
+			return -ENOMEM;
 
 		factor->mult = factor->div = 1;
 		factor->hw.init = &init_data;
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Vladimir Zapolskiy

If a dynamic memory allocation fails, the returned error code in clock controller driver probe functions on a few legacy platforms should be set to -ENOMEM instead of -EINVAL.

Fixes ee15faffef11 ("clk: qcom: common: Add API to register board clocks backwards compatibly")

---

Hm, I'dve assumed that static checkers would be able to find this pattern

+Dan do you still work on smatch nowadays? It doesn't seem to catch this one, but I think it'd be valuable to look for this pattern
- AFAICS it only flags returning -1 instead of -ENOMEM but I can't seem to trigger it with a manual edit to this file and the following args:

-p=kernel --pedantic --two-passes --assume-loops

For the patch

Konrad

Quoted 25 lines
 drivers/clk/qcom/common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/common.c +2 -2
index eec369d2173b..0e8f380873af 100644
@@ -169,7 +169,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
 	if (!node) {
 		fixed = devm_kzalloc(dev, sizeof(*fixed), GFP_KERNEL);
 		if (!fixed)
-			return -EINVAL;
+			return -ENOMEM;
 
 		fixed->fixed_rate = rate;
 		fixed->hw.init = &init_data;
@@ -186,7 +186,7 @@ static int _qcom_cc_register_board_clk(struct device *dev, const char *path,
 	if (add_factor) {
 		factor = devm_kzalloc(dev, sizeof(*factor), GFP_KERNEL);
 		if (!factor)
-			return -EINVAL;
+			return -ENOMEM;
 
 		factor->mult = factor->div = 1;
 		factor->hw.init = &init_data;
#2 lore raw
Quoted 17 lines · Konrad Dybcio
Quoted 7 lines · Vladimir Zapolskiy

If a dynamic memory allocation fails, the returned error code in clock controller driver probe functions on a few legacy platforms should be set to -ENOMEM instead of -EINVAL.

Fixes ee15faffef11 ("clk: qcom: common: Add API to register board clocks backwards compatibly")

---

Hm, I'dve assumed that static checkers would be able to find this pattern

+Dan do you still work on smatch nowadays? It doesn't seem to catch this one, but I think it'd be valuable to look for this pattern
- AFAICS it only flags returning -1 instead of -ENOMEM but I can't seem to trigger it with a manual edit to this file and the following args:

Quoted 6 lines

-p=kernel --pedantic --two-passes --assume-loops

For the patch

I'm re-working a bunch of Smatch internals right now. I've fixed the -1 vs -ENOMEM warning, but it's affected by the re-work so it's going to be a while before it hits mainline.

I can create a warning for returning -EINVAL or other error codes instead of -ENOMEM.

regards,
dan carpenter

#3 lore raw
Quoted 23 lines · Dan Carpenter
Quoted 22 lines · Konrad Dybcio
Quoted 7 lines · Vladimir Zapolskiy

If a dynamic memory allocation fails, the returned error code in clock controller driver probe functions on a few legacy platforms should be set to -ENOMEM instead of -EINVAL.

Fixes ee15faffef11 ("clk: qcom: common: Add API to register board clocks backwards compatibly")

---

Hm, I'dve assumed that static checkers would be able to find this pattern

+Dan do you still work on smatch nowadays? It doesn't seem to catch this one, but I think it'd be valuable to look for this pattern
- AFAICS it only flags returning -1 instead of -ENOMEM but I can't seem to trigger it with a manual edit to this file and the following args:

-p=kernel --pedantic --two-passes --assume-loops

For the patch

Quoted 8 lines
Quoted 1 line

I'm re-working a bunch of Smatch internals right now. I've fixed the -1 vs -ENOMEM warning, but it's affected by the re-work so it's going to be a while before it hits mainline.

I can create a warning for returning -EINVAL or other error codes instead of -ENOMEM.

Amazing, thank you!

Konrad

maintainer Applied
#4 lore raw
In reply to Vladimir Zapolskiy
Quoted 5 lines · Vladimir Zapolskiy

If a dynamic memory allocation fails, the returned error code in clock controller driver probe functions on a few legacy platforms should be set to -ENOMEM instead of -EINVAL.

Applied, thanks!

[1/1] clk: qcom: Return expected ENOMEM error on dynamic allocation failure

      commit: 22d9257f08913b6eec3e8ece4d13d9c41f14428b

Best regards,

Signature · 1 line
Bjorn Andersson <[email protected]>