Skip to contentSkip to conversation

Use IS_ERR() rather than a NULL check when necessary.

PATCH Applied Cyril Roelandt 8 participants 17 messages Dec 12, 2012 – Jan 12, 2013

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

cover Use IS_ERR() rather than a NULL check when necessary.

The following five patches replace NULL checks by calls to IS_ERR() when checking the return values of functions that return ERR_PTR() on error.

Regards,
Cyril Roelandt.
---

Cyril Roelandt (5):
staging: omap-thermal: fix error check in
omap_thermal_expose_sensor() and in omap_thermal_register_cpu_cooling().
media: davinci: fix return value check in vpbe_display_reqbufs().
c2port: fix return value check in duramar2150_c2port_init().
net: sfc: fix return value check in efx_ptp_probe_channel().
spi: fix return value check in hspi_probe().

 drivers/media/platform/davinci/vpbe_display.c      |    2 +-
 drivers/misc/c2port/c2port-duramar2150.c           |    2 +-
 drivers/net/ethernet/sfc/ptp.c                     |    2 +-
 drivers/spi/spi-sh-hspi.c                          |    2 +-
 drivers/staging/omap-thermal/omap-thermal-common.c |    4 ++--
 5 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/5 staging: omap-thermal: fix error check in omap_thermal_expose_sensor() and in omap_thermal_register_cpu_cooling().

The omap_bandgap_get_sensor_data() function returns ERR_PTR(), so we need to use IS_ERR() rather than a NULL check.

---
 drivers/staging/omap-thermal/omap-thermal-common.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/omap-thermal-common.c +2 -2
index 61f1070..79a55aa 100644
@@ -260,7 +260,7 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
 
 	data = omap_bandgap_get_sensor_data(bg_ptr, id);
 
-	if (!data)
+	if (IS_ERR(data))
 		data = omap_thermal_build_data(bg_ptr, id);
 
 	if (!data)
@@ -309,7 +309,7 @@ int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
 	struct omap_thermal_data *data;
 
 	data = omap_bandgap_get_sensor_data(bg_ptr, id);
-	if (!data)
+	if (IS_ERR(data))
 		data = omap_thermal_build_data(bg_ptr, id);
 
 	if (!data)
Signature · 1 line
1.7.10.4
Acked-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] staging: omap-thermal: fix error check in omap_thermal_expose_sensor() and in omap_thermal_register_cpu_cooling().

Quoted 5 lines · Cyril Roelandt

The omap_bandgap_get_sensor_data() function returns ERR_PTR(), so we need to use IS_ERR() rather than a NULL check.

Quoted 27 lines
---
  drivers/staging/omap-thermal/omap-thermal-common.c |    4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/omap-thermal/omap-thermal-common.c +2 -2
index 61f1070..79a55aa 100644
@@ -260,7 +260,7 @@ int omap_thermal_expose_sensor(struct omap_bandgap *bg_ptr, int id,
 
  	data = omap_bandgap_get_sensor_data(bg_ptr, id);
 
-	if (!data)
+	if (IS_ERR(data))
  		data = omap_thermal_build_data(bg_ptr, id);
 
  	if (!data)
@@ -309,7 +309,7 @@ int omap_thermal_register_cpu_cooling(struct omap_bandgap *bg_ptr, int id)
  	struct omap_thermal_data *data;
 
  	data = omap_bandgap_get_sensor_data(bg_ptr, id);
-	if (!data)
+	if (IS_ERR(data))
  		data = omap_thermal_build_data(bg_ptr, id);
 
  	if (!data)
#3 lore raw

PATCH 2/5 media: davinci: fix return value check in vpbe_display_reqbufs().

In reply to Cyril Roelandt

vb2_dma_contig_init_ctx() returns ERR_PTR and never returns NULL, so IS_ERR should be used instead of a NULL check.

---
 drivers/media/platform/davinci/vpbe_display.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/davinci/vpbe_display.c +1 -1
index 2bfde79..2db4eff 100644
@@ -1393,7 +1393,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
 	}
 	/* Initialize videobuf queue as per the buffer type */
 	layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev);
-	if (!layer->alloc_ctx) {
+	if (IS_ERR(layer->alloc_ctx)) {
 		v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n");
 		return -EINVAL;
 	}
Signature · 1 line
1.7.10.4
#4 lore raw

Re: [PATCH 2/5] media: davinci: fix return value check in vpbe_display_reqbufs().

Hi Cyril,

Quoted 3 lines · Cyril Roelandt

vb2_dma_contig_init_ctx() returns ERR_PTR and never returns NULL, so IS_ERR should be used instead of a NULL check.

patch fixing this issue has been already posted with a better fix
https://patchwork.kernel.org/patch/1830231/

Regards,
--Prabhakar Lad

Quoted 25 lines
---
 drivers/media/platform/davinci/vpbe_display.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/davinci/vpbe_display.c +1 -2
index 2bfde79..2db4eff 100644
@@ -1393,7 +1393,7 @@ static int vpbe_display_reqbufs(struct file *file, void *priv,
        }
        /* Initialize videobuf queue as per the buffer type */
        layer->alloc_ctx = vb2_dma_contig_init_ctx(vpbe_dev->pdev);
-       if (!layer->alloc_ctx) {
+       if (IS_ERR(layer->alloc_ctx)) {
                v4l2_err(&vpbe_dev->v4l2_dev, "Failed to get the context\n");
                return -EINVAL;
        }
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw

PATCH 3/5 c2port: fix return value check in duramar2150_c2port_init().

In reply to Cyril Roelandt

The c2port_device_register() function returns ERR_PTR() and never returns NULL, so the NULL check should be replaced by a call to IS_ERR().

---
 drivers/misc/c2port/c2port-duramar2150.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/c2port/c2port-duramar2150.c +1 -1
index 5484301..2742e60 100644
@@ -129,7 +129,7 @@ static int __init duramar2150_c2port_init(void)
 
 	duramar2150_c2port_dev = c2port_device_register("uc",
 					&duramar2150_c2port_ops, NULL);
-	if (!duramar2150_c2port_dev) {
+	if (IS_ERR(duramar2150_c2port_dev)) {
 		ret = -ENODEV;
 		goto free_region;
 	}
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 4/5 net: sfc: fix return value check in efx_ptp_probe_channel().

In reply to Cyril Roelandt

The ptp_clock_register() returns ERR_PTR() and never returns NULL. Replace the NULL check by a call to IS_ERR().

---
 drivers/net/ethernet/sfc/ptp.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/sfc/ptp.c +1 -1
index 0767043f..9bcc38c 100644
@@ -930,7 +930,7 @@ static int efx_ptp_probe_channel(struct efx_channel *channel)
 
 	ptp->phc_clock = ptp_clock_register(&ptp->phc_clock_info,
 					    &efx->pci_dev->dev);
-	if (!ptp->phc_clock)
+	if (IS_ERR(ptp->phc_clock))
 		goto fail3;
 
 	INIT_WORK(&ptp->pps_work, efx_ptp_pps_worker);
Signature · 1 line
1.7.10.4
maintainer
#7 lore raw

Re: [PATCH 4/5] net: sfc: fix return value check in efx_ptp_probe_channel().

From: Cyril Roelandt <[email protected]>
Date: Wed, 12 Dec 2012 01:24:53 +0100

Quoted 4 lines

The ptp_clock_register() returns ERR_PTR() and never returns NULL. Replace the NULL check by a call to IS_ERR().

I'll let Ben queue this up.

Probably he'll want to avoid potentially leaving an ERR_PTR in ptp->phc_clock even if, with this fix, that would be harmless.

Acked-by
#8 lore raw

Re: [PATCH 4/5] net: sfc: fix return value check in efx_ptp_probe_channel().

Quoted 6 lines · David Miller

From: Cyril Roelandt <[email protected]>
Date: Wed, 12 Dec 2012 01:24:53 +0100

Quoted 3 lines

The ptp_clock_register() returns ERR_PTR() and never returns NULL. Replace the NULL check by a call to IS_ERR().

Quoted 7 lines
Quoted 1 line

I'll let Ben queue this up.

Probably he'll want to avoid potentially leaving an ERR_PTR in ptp->phc_clock even if, with this fix, that would be harmless.

Sorry for the delay in looking at this. This change is fine, as the entire structure *ptp will be freed on the failure path.

I'm now on vacation until the new year. Cyril, please re-send your patch with the addition of:

so it will show up on 'patchwork' again and David can apply it from there.

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#9 lore raw

PATCH 5/5 spi: fix return value check in hspi_probe().

In reply to Cyril Roelandt

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

---
 drivers/spi/spi-sh-hspi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-sh-hspi.c +1 -1
index 32f7b55..60cfae5 100644
@@ -290,7 +290,7 @@ static int hspi_probe(struct platform_device *pdev)
 	}
 
 	clk = clk_get(NULL, "shyway_clk");
-	if (!clk) {
+	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "shyway_clk is required\n");
 		ret = -EINVAL;
 		goto error0;
Signature · 1 line
1.7.10.4
Acked-by on v1 5/5
#10 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Hi

Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Quoted 31 lines
---
 drivers/spi/spi-sh-hspi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-sh-hspi.c +1 -1
index 32f7b55..60cfae5 100644
@@ -290,7 +290,7 @@ static int hspi_probe(struct platform_device *pdev)
 	}
 
 	clk = clk_get(NULL, "shyway_clk");
-	if (!clk) {
+	if (IS_ERR(clk)) {
 		dev_err(&pdev->dev, "shyway_clk is required\n");
 		ret = -EINVAL;
 		goto error0;
Signature · 13 lines
1.7.10.4


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
spi-devel-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spi-devel-general

Best regards
---
Kuninori Morimoto

#12 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Quoted 4 lines · Grant Likely
Quoted 3 lines · Kuninori Morimoto

Hi

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Applied, thanks.

In another thread, we were just talking about who clk_get() can return a NULL if !CONFIG_HAVE_CLK. That might change to match the documentation later... Not sure.

regards,
dan carpenter

#13 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Quoted 10 lines · Dan Carpenter
Quoted 9 lines · Grant Likely
Quoted 8 lines · Kuninori Morimoto

Hi

Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Applied, thanks.

In another thread, we were just talking about who clk_get() can return a NULL if !CONFIG_HAVE_CLK. That might change to match the documentation later... Not sure.

So what is the solution here? Will the dummy clk_get() be changed, or is there more work needed on the drivers?

/me stifles a rant about the PTR_ERR pattern

g.

#14 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Quoted 13 lines · Grant Likely
Quoted 12 lines · Dan Carpenter
Quoted 11 lines · Grant Likely
Quoted 9 lines · Kuninori Morimoto

Hi

Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Applied, thanks.

In another thread, we were just talking about who clk_get() can return a NULL if !CONFIG_HAVE_CLK. That might change to match the documentation later... Not sure.

So what is the solution here? Will the dummy clk_get() be changed, or is there more work needed on the drivers?

This driver can't function without a clk. It should select that at build time instead of testing for it at probe. Just checking for IS_ERR() will NOT cause a NULL dereference so the patch is ok in that respect. I'm not sure if this can be build without CONFIG_HAVE_CLK.

regards,
dan carpenter

#15 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Quoted 24 lines · Dan Carpenter
Quoted 13 lines · Grant Likely
Quoted 12 lines · Dan Carpenter
Quoted 11 lines · Grant Likely
Quoted 9 lines · Kuninori Morimoto

Hi

Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Applied, thanks.

In another thread, we were just talking about who clk_get() can return a NULL if !CONFIG_HAVE_CLK. That might change to match the documentation later... Not sure.

So what is the solution here? Will the dummy clk_get() be changed, or is there more work needed on the drivers?

Quoted 5 lines

This driver can't function without a clk. It should select that at build time instead of testing for it at probe. Just checking for IS_ERR() will NOT cause a NULL dereference so the patch is ok in that respect. I'm not sure if this can be build without CONFIG_HAVE_CLK.

Your suggestion is to make this driver depend on CONFIG_HAVE_CLK? I'm fine with that, but it doesn't sort out the core infrastructure question about whether it is valid for the empty clk_get() to return NULL. Nor is it a particularly sustainable solution (ie. if a large number of drivers want to do the same thing).

g.

#16 lore raw

Re: [PATCH 5/5] spi: fix return value check in hspi_probe().

Quoted 31 lines · Grant Likely
Quoted 24 lines · Dan Carpenter
Quoted 13 lines · Grant Likely
Quoted 12 lines · Dan Carpenter
Quoted 11 lines · Grant Likely
Quoted 9 lines · Kuninori Morimoto

Hi

Quoted 4 lines

According to its documentation, clk_get() returns a "valid IS_ERR() condition containing errno", so we should call IS_ERR() rather than a NULL check.

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

Applied, thanks.

In another thread, we were just talking about who clk_get() can return a NULL if !CONFIG_HAVE_CLK. That might change to match the documentation later... Not sure.

So what is the solution here? Will the dummy clk_get() be changed, or is there more work needed on the drivers?

Quoted 5 lines

This driver can't function without a clk. It should select that at build time instead of testing for it at probe. Just checking for IS_ERR() will NOT cause a NULL dereference so the patch is ok in that respect. I'm not sure if this can be build without CONFIG_HAVE_CLK.

Quoted 6 lines

Your suggestion is to make this driver depend on CONFIG_HAVE_CLK? I'm fine with that, but it doesn't sort out the core infrastructure question about whether it is valid for the empty clk_get() to return NULL. Nor is it a particularly sustainable solution (ie. if a large number of drivers want to do the same thing).

We've spread this conversation out across several different threads.

http://lists.infradead.org/pipermail/linux-arm-kernel/2013-January/139186.html

Basically, drivers should use accessor functions which handle NULL pointers instead of dereferencing the pointer directly.

regards,
dan carpenter