Skip to contentSkip to conversation

ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

PATCH In review zhong jiang 2 participants 5 messages Oct 31, 2019 – Nov 2, 2019

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

PATCH 1/1 ASoC: sun4i: Use PTR_ERR_OR_ZERO to simplify the code

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

---
 sound/soc/sunxi/sun4i-i2s.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +1 -3
index d0a8d58..72012a6 100644
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
 	i2s->field_fmt_sr =
 			devm_regmap_field_alloc(dev, i2s->regmap,
 						i2s->variant->field_fmt_sr);
-	if (IS_ERR(i2s->field_fmt_sr))
-		return PTR_ERR(i2s->field_fmt_sr);
 
-	return 0;
+	return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);
 }
 
 static int sun4i_i2s_probe(struct platform_device *pdev)
Signature · 1 line
1.7.12.4
#1 lore raw
Quoted 12 lines · zhong jiang

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

---
 sound/soc/sunxi/sun4i-i2s.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +0 -0
index d0a8d58..72012a6 100644

sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_init_regmap_fields(struct device *dev, · line 1178

Quoted 8 lines
sound/soc/sunxi/sun4i-i2s.c +1 -3
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
 	i2s->field_fmt_sr =
 			devm_regmap_field_alloc(dev, i2s->regmap,
 						i2s->variant->field_fmt_sr);
-	if (IS_ERR(i2s->field_fmt_sr))
-		return PTR_ERR(i2s->field_fmt_sr);
 
-	return 0;
+	return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);

I don't find it "better". This couples the error handling and the success case, and it makes it harder to extend in the future.

Maxime

#2 lore raw
Quoted 19 lines · Maxime Ripard
Quoted 18 lines · zhong jiang

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

---
 sound/soc/sunxi/sun4i-i2s.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +0 -2
index d0a8d58..72012a6 100644
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
 	i2s->field_fmt_sr =
 			devm_regmap_field_alloc(dev, i2s->regmap,
 						i2s->variant->field_fmt_sr);
-	if (IS_ERR(i2s->field_fmt_sr))
-		return PTR_ERR(i2s->field_fmt_sr);
 
Quoted 4 lines

sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_init_regmap_fields(struct device *dev, · line 1178

Quoted 2 lines
sound/soc/sunxi/sun4i-i2s.c +1 -1
-	return 0;
+	return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);

I don't find it "better". This couples the error handling and the success case, and it makes it harder to extend in the future.

PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is feasible to replace it and more readable at least now.

As you said, PTR_ERR_OR_ZERO should be removed ? :-(

Thanks,
zhong jiang

Quoted 1 line

Maxime

#3 lore raw
Quoted 25 lines · zhong jiang
Quoted 19 lines · Maxime Ripard
Quoted 18 lines · zhong jiang

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

---
 sound/soc/sunxi/sun4i-i2s.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +0 -2
index d0a8d58..72012a6 100644
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
 	i2s->field_fmt_sr =
 			devm_regmap_field_alloc(dev, i2s->regmap,
 						i2s->variant->field_fmt_sr);
-	if (IS_ERR(i2s->field_fmt_sr))
-		return PTR_ERR(i2s->field_fmt_sr);
 
Quoted 4 lines

sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_init_regmap_fields(struct device *dev, · line 1178

Quoted 2 lines
sound/soc/sunxi/sun4i-i2s.c +1 -1
-	return 0;
+	return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);

I don't find it "better". This couples the error handling and the success case, and it makes it harder to extend in the future.

Quoted 4 lines

PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is feasible to replace it and more readable at least now.

As you said, PTR_ERR_OR_ZERO should be removed ? :-(

No, I'm saying that in this context, this change isn't necessary.

Maxime

#4 lore raw
Quoted 25 lines · Maxime Ripard
Quoted 24 lines · zhong jiang
Quoted 23 lines · Maxime Ripard
Quoted 12 lines · zhong jiang

It is better to use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR.

---
 sound/soc/sunxi/sun4i-i2s.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/sunxi/sun4i-i2s.c +0 -0
index d0a8d58..72012a6 100644

sound/soc/sunxi/sun4i-i2s.c static int sun4i_i2s_init_regmap_fields(struct device *dev, · line 1178

Quoted 8 lines
sound/soc/sunxi/sun4i-i2s.c +1 -3
@@ -1174,10 +1174,8 @@ static int sun4i_i2s_init_regmap_fields(struct device *dev,
 	i2s->field_fmt_sr =
 			devm_regmap_field_alloc(dev, i2s->regmap,
 						i2s->variant->field_fmt_sr);
-	if (IS_ERR(i2s->field_fmt_sr))
-		return PTR_ERR(i2s->field_fmt_sr);
 
-	return 0;
+	return PTR_ERR_OR_ZERO(i2s->field_fmt_sr);

I don't find it "better". This couples the error handling and the success case, and it makes it harder to extend in the future.

Quoted 5 lines
Quoted 4 lines

PTR_ERR_OR_ZERO has implemented the if(IS_ERR(...)) + PTR_ERR. It is feasible to replace it and more readable at least now.

As you said, PTR_ERR_OR_ZERO should be removed ? :-(

No, I'm saying that in this context, this change isn't necessary.

I am not an expert in the field. It depends on you.

Quoted 1 line

Maxime