Use IS_ERR() rather than a NULL check when necessary.
Subsystems (8)
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
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
@@ -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
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 returnsERR_PTR(), so we need to useIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>
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@@ -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)
PATCH 2/5 media: davinci: fix return value check in vpbe_display_reqbufs().
In reply to Cyril Roelandtvb2_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
@@ -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
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()returnsERR_PTRand never returns NULL, soIS_ERRshould 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
Signed-off-by Cyril Roelandt <[email protected]>--- drivers/media/platform/davinci/vpbe_display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/davinci/vpbe_display.c +1
-2@@ -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
PATCH 3/5 c2port: fix return value check in duramar2150_c2port_init().
In reply to Cyril RoelandtThe 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
@@ -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
PATCH 4/5 net: sfc: fix return value check in efx_ptp_probe_channel().
In reply to Cyril RoelandtThe 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
@@ -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
David Miller
maintainerRe: [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()returnsERR_PTR()and never returns NULL. Replace the NULL check by a call toIS_ERR().Signed-off-by Cyril Roelandt <[email protected]>
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.
Ben Hutchings
Acked-byRe: [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 +0100Quoted 3 lines
The
ptp_clock_register()returnsERR_PTR()and never returns NULL. Replace the NULL check by a call toIS_ERR().
Quoted 7 lines
Quoted 1 line
Signed-off-by Cyril Roelandt <[email protected]>I'll let Ben queue this up.
Probably he'll want to avoid potentially leaving an
ERR_PTRinptp->phc_clockeven 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.
PATCH 5/5 spi: fix return value check in hspi_probe().
In reply to Cyril RoelandtAccording 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
@@ -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
Re: [PATCH 5/5] spi: fix return value check in hspi_probe().
Hi
Quoted 4 lines
According to its documentation,
clk_get()returns a "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>
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@@ -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
Grant Likely
AppliedRe: [PATCH 5/5] spi: fix return value check in hspi_probe().
Quoted 9 lines · Kuninori Morimoto
Hi
Quoted 4 lines
According to its documentation,
clk_get()returns a "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>
Applied, thanks.
g.
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 "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>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
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 "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>
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.
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 "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>
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
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 "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>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 withoutCONFIG_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.
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 "validIS_ERR()condition containing errno", so we should callIS_ERR()rather than a NULL check.Signed-off-by Cyril Roelandt <[email protected]>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 withoutCONFIG_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 emptyclk_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