virtio-mmio: Cocci spatch "ptr_ret.spatch"
Subsystems (34)
PATCH 1/1 virtio-mmio: Cocci spatch "ptr_ret.spatch"
---
drivers/virtio/virtio_mmio.c +1 -4
@@ -567,10 +567,7 @@ static int vm_cmdline_set(const char *de pdev =platform_device_register_resndata (&vm_cmdline_parent,"virtio-mmio" , vm_cmdline_id++, resources,ARRAY_SIZE (resources),NULL ,0 ); -if (IS_ERR (pdev)) -return PTR_ERR (pdev); - -return 0 ; +return PTR_RET (pdev); }static int vm_cmdline_get_device (struct device *dev,void *data)
RFC 1/1 PTR_ERR: return 0 if ptr isn't an error value.
Back in 2011, Uwe Kleine-König added the nonsensically-named PTR_RET(), providing a means to avoid if() statements in code (commit fa9ee9c4b9).
Instead, just make PTR_ERR() return 0 if the pointer isn't an error value. This is harmless, since PTR_ERR() should have never been passed a non-error value. And GCC is usually smart enough to remove the extra test if IS_ERR() has already been called.
My vmlinux text increased by 300 bytes:
text data bss dec hex filename 6029452 491628 2576384 9097464 8ad0f8 vmlinux 6029721 491628 2576384 9097733 8ad205 vmlinux.PTR_ERR
include/linux/err.h +7 -12
@@ -24,14 +24,16 @@ static inline void * __must_check ERR_PTR(long error)return (void *) error; } -static inline long __must_check PTR_ERR (const void *ptr) +static inline long __must_check IS_ERR (const void *ptr) { -return (long ) ptr; +return IS_ERR_VALUE ((unsigned long )ptr); } -static inline long __must_check IS_ERR (const void *ptr) +static inline long __must_check PTR_ERR (const void *ptr) { -return IS_ERR_VALUE ((unsigned long )ptr); +if (IS_ERR (ptr)) +return (long ) ptr; +return 0 ; }static inline long __must_check IS_ERR_OR_NULL (const void *ptr)
@@ -52,14 +54,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)return (void *) ptr; } -static inline int __must_check PTR_RET (const void *ptr) -{ -if (IS_ERR (ptr)) -return PTR_ERR (ptr); -else -return 0 ; -} - +#define PTR_RET PTR_ERR#endif #endif /* _LINUX_ERR_H */
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Hello Rusty,
[added akpm to Cc: who took the patch back then and Julia for the coccinelle part below]
Quoted 9 lines · Rusty Russell
Back in 2011, Uwe Kleine-König added the nonsensically-named
PTR_RET(), providing a means to avoidif()statements in code (commitfa9ee9c4b9).Instead, just make
PTR_ERR()return 0 if the pointer isn't an error value. This is harmless, sincePTR_ERR()should have never been passed a non-error value. And GCC is usually smart enough to remove the extra test ifIS_ERR()has already been called.
I wonder in which situations gcc fails to be smart enough. Did you check this?
Quoted 38 lines
My vmlinux text increased by 300 bytes:
text data bss dec hex filename 6029452 491628 2576384 9097464 8ad0f8 vmlinux 6029721 491628 2576384 9097733 8ad205 vmlinux.PTR_ERRCc Uwe Kleine-König <[email protected]>Cc Thomas Meyer <[email protected]>Signed-off-by Rusty Russell <[email protected]>include/linux/err.h +6
-4@@ -24,14 +24,16 @@ static inline void * __must_check ERR_PTR(long error)return (void *) error; } -static inline long __must_check PTR_ERR (const void *ptr) +static inline long __must_check IS_ERR (const void *ptr) { -return (long ) ptr; +return IS_ERR_VALUE ((unsigned long )ptr); } -static inline long __must_check IS_ERR (const void *ptr) +static inline long __must_check PTR_ERR (const void *ptr) { -return IS_ERR_VALUE ((unsigned long )ptr); +if (IS_ERR (ptr)) +return (long ) ptr; +return 0 ; }static inline long __must_check IS_ERR_OR_NULL (const void *ptr)@@ -52,14 +54,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)return (void *) ptr; }
include/linux/err.h static inline void * __must_check ERR_CAST(const void *ptr) · line 57
Quoted 10 lines
include/linux/err.h +1
-8-static inline int __must_check PTR_RET (const void *ptr) -{ -if (IS_ERR (ptr)) -return PTR_ERR (ptr); -else -return 0 ; -} - +#define PTR_RET PTR_ERR
I'd add a comment here that PTR_RET shouldn't be used anymore.
include/linux/err.h static inline void * __must_check ERR_CAST(const void *ptr) · line 60
Quoted 4 lines
include/linux/err.h +0
-0#endif #endif /* _LINUX_ERR_H */
Is it worth to apply the same change to tools/virtio/linux/err.h to minimize the chance for later surprises?
Also scripts/coccinelle/api/ptr_ret.cocci starts giving false warnings.
Other than that I think the change is fine.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Quoted 70 lines · Uwe Kleine-König
Hello Rusty,
[added akpm to Cc: who took the patch back then and Julia for the coccinelle part below]
Quoted 9 lines · Rusty Russell
Back in 2011, Uwe Kleine-König added the nonsensically-named
PTR_RET(), providing a means to avoidif()statements in code (commitfa9ee9c4b9).Instead, just make
PTR_ERR()return 0 if the pointer isn't an error value. This is harmless, sincePTR_ERR()should have never been passed a non-error value. And GCC is usually smart enough to remove the extra test ifIS_ERR()has already been called.I wonder in which situations gcc fails to be smart enough. Did you check this?
Quoted 38 lines
My vmlinux text increased by 300 bytes:
text data bss dec hex filename 6029452 491628 2576384 9097464 8ad0f8 vmlinux 6029721 491628 2576384 9097733 8ad205 vmlinux.PTR_ERRCc Uwe Kleine-König <[email protected]>Cc Thomas Meyer <[email protected]>Signed-off-by Rusty Russell <[email protected]>include/linux/err.h +6
-4@@ -24,14 +24,16 @@ static inline void * __must_check ERR_PTR(long error)return (void *) error; } -static inline long __must_check PTR_ERR (const void *ptr) +static inline long __must_check IS_ERR (const void *ptr) { -return (long ) ptr; +return IS_ERR_VALUE ((unsigned long )ptr); } -static inline long __must_check IS_ERR (const void *ptr) +static inline long __must_check PTR_ERR (const void *ptr) { -return IS_ERR_VALUE ((unsigned long )ptr); +if (IS_ERR (ptr)) +return (long ) ptr; +return 0 ; }static inline long __must_check IS_ERR_OR_NULL (const void *ptr)@@ -52,14 +54,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)return (void *) ptr; }include/linux/err.h static inline void * __must_check ERR_CAST(const void *ptr) · line 57
Quoted 10 lines
include/linux/err.h +1
-8-static inline int __must_check PTR_RET (const void *ptr) -{ -if (IS_ERR (ptr)) -return PTR_ERR (ptr); -else -return 0 ; -} - +#define PTR_RET PTR_ERRI'd add a comment here that
PTR_RETshouldn't be used anymore.Quoted 2 lines
include/linux/err.h +0
-0#endif
Quoted 8 lines
include/linux/err.h static inline void * __must_check ERR_CAST(const void *ptr) · line 60
Quoted 2 lines
include/linux/err.h +0
-0#endif /* _LINUX_ERR_H */ Is it worth to apply the same change to
tools/virtio/linux/err.hto minimize the chance for later surprises?
Alsoscripts/coccinelle/api/ptr_ret.coccistarts giving false warnings.Other than that I think the change is fine.
For a random example, here is a function that currently uses PTR_RET:
static int __net_init iptable_raw_net_init(struct net *net)
{
struct ipt_replace *repl;
repl = ipt_alloc_initial_table(&packet_raw);
if (repl == NULL)
return -ENOMEM;
net->ipv4.iptable_raw =
ipt_register_table(net, &packet_raw, repl);
kfree(repl);
return PTR_RET(net->ipv4.iptable_raw);
}If it becomes return PTR_ERR(...); at the end, won't it look like the function always fails?
julia
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Quoted 2 lines · Julia Lawall
On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
For a random example, here is a function that currently usesPTR_RET:
Heheh, nice choice: I think I wrote that code originally :)
Quoted 13 lines
static int
__net_initiptable_raw_net_init(struct net *net){ struct ipt_replace *repl; repl = ipt_alloc_initial_table(&packet_raw); if (repl == NULL) return -ENOMEM; net->ipv4.iptable_raw = ipt_register_table(net, &packet_raw, repl); kfree(repl); return PTR_RET(net->ipv4.iptable_raw); }
Quoted 2 lines
If it becomes return
PTR_ERR(...); at the end, won't it look like the function always fails?
That is a valid point, though in this case the reader will know that can't be the case.
On the other hand, there's an incremental learning curve cost to every convenience function we add. There are only 50 places where we use PTR_RET(), so it's not saving us very much typing over the clearest
solution: open-coding the test.
I think using PTR_ERR() is a less bad solution than promoting PTR_RET, which has a non-obvious name.
Cheers,
Rusty.
Michael S. Tsirkin
maintainerRe: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Quoted 30 lines · Rusty Russell
Quoted 2 lines · Julia Lawall
On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
For a random example, here is a function that currently usesPTR_RET:Heheh, nice choice: I think I wrote that code originally :)
Quoted 13 lines
static int
__net_initiptable_raw_net_init(struct net *net){ struct ipt_replace *repl; repl = ipt_alloc_initial_table(&packet_raw); if (repl == NULL) return -ENOMEM; net->ipv4.iptable_raw = ipt_register_table(net, &packet_raw, repl); kfree(repl); return PTR_RET(net->ipv4.iptable_raw); }Quoted 2 lines
If it becomes return
PTR_ERR(...); at the end, won't it look like the function always fails?That is a valid point, though in this case the reader will know that can't be the case.
On the other hand, there's an incremental learning curve cost to every convenience function we add. There are only 50 places where we use
PTR_RET(), so it's not saving us very much typing over the clearest
solution: open-coding the test.
Quoted 5 lines
I think using
PTR_ERR()is a less bad solution than promotingPTR_RET, which has a non-obvious name.Cheers,
Rusty.
Will a longer name make the function more obvious?
PTR_ERR_OR_ZERO() ? PTR_ERR0() ?
PTR_ERR() can then stay simple for cases where we know we are on the error path.
Signature · 1 line
MST
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Rusty Russell
Quoted 2 lines · Julia Lawall
On Mon, 3 Jun 2013, Uwe Kleine-König wrote:
For a random example, here is a function that currently usesPTR_RET:Heheh, nice choice: I think I wrote that code originally :)
Quoted 13 lines
static int
__net_initiptable_raw_net_init(struct net *net){ struct ipt_replace *repl; repl = ipt_alloc_initial_table(&packet_raw); if (repl == NULL) return -ENOMEM; net->ipv4.iptable_raw = ipt_register_table(net, &packet_raw, repl); kfree(repl); return PTR_RET(net->ipv4.iptable_raw); }Quoted 2 lines
If it becomes return
PTR_ERR(...); at the end, won't it look like the function always fails?That is a valid point, though in this case the reader will know that can't be the case.
On the other hand, there's an incremental learning curve cost to every convenience function we add. There are only 50 places where we use
PTR_RET(), so it's not saving us very much typing over the clearest
solution: open-coding the test.I think using
PTR_ERR()is a less bad solution than promotingPTR_RET, which has a non-obvious name.
Quoted 8 lines
Quoted 2 lines
Cheers,
Rusty.Will a longer name make the function more obvious?
PTR_ERR_OR_ZERO() ? PTR_ERR0() ?
PTR_ERR()can then stay simple for cases where we know we are on the error path.
I was thinking of something along those lines. And in that case, PTR_ERR could stay without the additional test.
julia
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
Quoted 12 lines · Julia Lawall
Quoted 9 lines · Michael S. Tsirkin
Quoted 2 lines · Rusty Russell
I think using
PTR_ERR()is a less bad solution than promotingPTR_RET, which has a non-obvious name.Will a longer name make the function more obvious?
PTR_ERR_OR_ZERO() ? PTR_ERR0() ?
PTR_ERR()can then stay simple for cases where we know we are on the error path.
Quoted 3 lines
I was thinking of something along those lines. And in that case,
PTR_ERRcould stay without the additional test.
julia
OK, sold :)
Will send out a series now with PTR_ERR_OR_ZERO.
Thanks,
Rusty.
PATCH 1/9 PTR_RET is now PTR_ERR_OR_ZERO
True, it's often used in return statements, but after much bikeshedding it's probably better to have an explicit name.
(I tried just putting the IS_ERR check inside PTR_ERR itself and gcc usually generated no more code. But that clashes current expectations of how PTR_ERR behaves, so having a separate function is better).
--- include/linux/err.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
include/linux/err.h +4 -1
@@ -52,7 +52,7 @@ static inline void * __must_check ERR_CAST(const void *ptr)return (void *) ptr; } -static inline int __must_check PTR_RET (const void *ptr) +static inline int __must_check PTR_ERR_OR_ZERO (const void *ptr) {if (IS_ERR (ptr))return PTR_ERR (ptr);
@@ -60,6 +60,9 @@ static inline int __must_check PTR_RET(const void *ptr)return 0 ; } +/* Deprecated */ +#define PTR_RET (p) PTR_ERR_OR_ZERO(p) +#endif #endif /* _LINUX_ERR_H */
Signature · 1 line
1.8.1.2
PATCH 2/9 PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
Sweep of the simple cases.
--- arch/arm/mach-omap2/i2c.c | 2 +- arch/m68k/amiga/platform.c | 2 +- arch/m68k/kernel/time.c | 2 +- arch/m68k/q40/config.c | 2 +- arch/powerpc/kernel/iommu.c | 2 +- arch/powerpc/kernel/time.c | 2 +- arch/powerpc/platforms/ps3/time.c | 2 +- arch/powerpc/sysdev/rtc_cmos_setup.c | 2 +- arch/s390/hypfs/hypfs_dbfs.c | 2 +- drivers/char/tile-srom.c | 2 +- drivers/infiniband/core/cma.c | 2 +- drivers/net/appletalk/cops.c | 2 +- drivers/net/appletalk/ltpc.c | 2 +- drivers/net/ethernet/amd/atarilance.c | 2 +- drivers/net/ethernet/amd/mvme147.c | 2 +- drivers/net/ethernet/amd/ni65.c | 2 +- drivers/net/ethernet/amd/sun3lance.c | 2 +- drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c | 2 +- drivers/net/wireless/brcm80211/brcmsmac/debug.c | 2 +- drivers/platform/x86/samsung-q10.c | 2 +- drivers/regulator/fan53555.c | 2 +- drivers/spi/spi-fsl-spi.c | 2 +- drivers/spi/spidev.c | 2 +- drivers/video/omap2/dss/core.c | 2 +- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/inode.c | 2 +- net/bluetooth/hci_sysfs.c | 2 +- net/bridge/netfilter/ebtable_broute.c | 2 +- net/bridge/netfilter/ebtable_filter.c | 2 +- net/bridge/netfilter/ebtable_nat.c | 2 +- net/ipv4/netfilter/arptable_filter.c | 2 +- net/ipv4/netfilter/iptable_filter.c | 2 +- net/ipv4/netfilter/iptable_mangle.c | 2 +- net/ipv4/netfilter/iptable_nat.c | 2 +- net/ipv4/netfilter/iptable_raw.c | 2 +- net/ipv4/netfilter/iptable_security.c | 2 +- net/ipv6/netfilter/ip6table_filter.c | 2 +- net/ipv6/netfilter/ip6table_mangle.c | 2 +- net/ipv6/netfilter/ip6table_nat.c | 2 +- net/ipv6/netfilter/ip6table_raw.c | 2 +- net/ipv6/netfilter/ip6table_security.c | 2 +- scripts/coccinelle/api/ptr_ret.cocci | 10 +++++----- sound/soc/soc-io.c | 2 +- 43 files changed, 47 insertions(+), 47 deletions(-)
arch/arm/mach-omap2/i2c.c +1 -1
@@ -181,7 +181,7 @@ int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata, sizeof(struct omap_i2c_bus_platform_data));WARN (IS_ERR (pdev),"Could not build omap_device for %s\n" , name); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }static int __init omap_i2c_cmdline (void )
arch/m68k/amiga/platform.c +1 -1
@@ -56,7 +56,7 @@ static int __init amiga_init_bus(void) n =AMIGAHW_PRESENT (ZORRO3 ) ?4 :2 ; pdev =platform_device_register_simple ("amiga-zorro" ,-1 , zorro_resources, n); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }subsys_initcall (amiga_init_bus);
arch/m68k/kernel/time.c +1 -1
@@ -90,7 +90,7 @@ static int __init rtc_init(void)return -ENODEV ; pdev =platform_device_register_simple ("rtc-generic" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (rtc_init);
arch/m68k/q40/config.c +1 -1
@@ -338,6 +338,6 @@ static __init int q40_add_kbd_device(void)return -ENODEV ; pdev =platform_device_register_simple ("q40kbd" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }arch_initcall (q40_add_kbd_device);
arch/powerpc/kernel/iommu.c +1 -1
@@ -102,7 +102,7 @@ static int __init fail_iommu_debugfs(void)struct dentry *dir =fault_create_debugfs_attr ("fail_iommu" ,NULL , &fail_iommu); -return PTR_RET (dir); +return PTR_ERR_OR_ZERO (dir); }late_initcall (fail_iommu_debugfs);
arch/powerpc/kernel/time.c +1 -1
@@ -1050,7 +1050,7 @@ static int __init rtc_init(void) pdev =platform_device_register_simple ("rtc-generic" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (rtc_init);
arch/powerpc/platforms/ps3/time.c +1 -1
@@ -90,7 +90,7 @@ static int __init ps3_rtc_init(void) pdev =platform_device_register_simple ("rtc-ps3" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (ps3_rtc_init);
arch/powerpc/sysdev/rtc_cmos_setup.c +1 -1
@@ -62,7 +62,7 @@ static int __init add_rtc(void) pd =platform_device_register_simple ("rtc_cmos" ,-1 , &res[0 ], num_res); -return PTR_RET (pd); +return PTR_ERR_OR_ZERO (pd); }fs_initcall (add_rtc);
arch/s390/hypfs/hypfs_dbfs.c +1 -1
@@ -105,7 +105,7 @@ void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)int hypfs_dbfs_init (void ) { dbfs_dir =debugfs_create_dir ("s390_hypfs" ,NULL ); -return PTR_RET (dbfs_dir); +return PTR_ERR_OR_ZERO (dbfs_dir); }void hypfs_dbfs_exit (void )
drivers/char/tile-srom.c +1 -1
@@ -371,7 +371,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index) dev =device_create (srom_class, &platform_bus,MKDEV (srom_major, index), srom,"%d" , index); -return PTR_RET (dev); +return PTR_ERR_OR_ZERO (dev); }/** srom_init() - Initialize the driver's module. */
drivers/infiniband/core/cma.c +1 -1
@@ -3055,7 +3055,7 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv, id_priv->id.port_num, &rec, comp_mask,GFP_KERNEL , cma_ib_mc_handler, mc); -return PTR_RET (mc->multicast.ib); +return PTR_ERR_OR_ZERO (mc->multicast.ib); }static void iboe_mcast_work_handler (struct work_struct *work)
drivers/net/appletalk/cops.c +1 -1
@@ -996,7 +996,7 @@ static int __init cops_module_init(void)printk (KERN_WARNING "%s: You shouldn't autoprobe with insmod\n" , cardname); cops_dev =cops_probe (-1 ); -return PTR_RET (cops_dev); +return PTR_ERR_OR_ZERO (cops_dev); } static void __exit cops_module_exit(void)
drivers/net/appletalk/ltpc.c +1 -1
@@ -1243,7 +1243,7 @@ static int __init ltpc_module_init(void) "ltpc: Autoprobing is not recommended for modules\n"); dev_ltpc =ltpc_probe (); - return PTR_RET(dev_ltpc); + return PTR_ERR_OR_ZERO(dev_ltpc); }module_init (ltpc_module_init);#endif
drivers/net/ethernet/amd/atarilance.c +1 -1
@@ -1147,7 +1147,7 @@ static struct net_device *atarilance_dev;static int __init atarilance_module_init (void ) { atarilance_dev =atarilance_probe (-1 ); -return PTR_RET (atarilance_dev); +return PTR_ERR_OR_ZERO (atarilance_dev); } static void __exit atarilance_module_exit(void)
drivers/net/ethernet/amd/mvme147.c +1 -1
@@ -188,7 +188,7 @@ static struct net_device *dev_mvme147_lance;int __init init_module (void ) { dev_mvme147_lance =mvme147lance_probe (-1 ); -return PTR_RET (dev_mvme147_lance); +return PTR_ERR_OR_ZERO (dev_mvme147_lance); } void __exit cleanup_module(void)
drivers/net/ethernet/amd/ni65.c +1 -1
@@ -1238,7 +1238,7 @@ MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");int __init init_module (void ) { dev_ni65 =ni65_probe (-1 ); -return PTR_RET (dev_ni65); +return PTR_ERR_OR_ZERO (dev_ni65); } void __exit cleanup_module(void)
drivers/net/ethernet/amd/sun3lance.c +1 -1
@@ -940,7 +940,7 @@ static struct net_device *sun3lance_dev;int __init init_module (void ) { sun3lance_dev =sun3lance_probe (-1 ); -return PTR_RET (sun3lance_dev); +return PTR_ERR_OR_ZERO (sun3lance_dev); } void __exit cleanup_module(void)
drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c +1 -1
@@ -50,7 +50,7 @@ int brcmf_debugfs_attach(struct brcmf_pub *drvr)return -ENODEV ; drvr->dbgfs_dir =debugfs_create_dir (dev_name (dev), root_folder); -return PTR_RET (drvr->dbgfs_dir); +return PTR_ERR_OR_ZERO (drvr->dbgfs_dir); }void brcmf_debugfs_detach (struct brcmf_pub *drvr)
drivers/net/wireless/brcm80211/brcmsmac/debug.c +1 -1
@@ -56,7 +56,7 @@ int brcms_debugfs_attach(struct brcms_pub *drvr) drvr->dbgfs_dir =debugfs_create_dir (dev_name (&drvr->wlc->hw->d11core->dev), root_folder); -return PTR_RET (drvr->dbgfs_dir); +return PTR_ERR_OR_ZERO (drvr->dbgfs_dir); }void brcms_debugfs_detach (struct brcms_pub *drvr)
drivers/platform/x86/samsung-q10.c +1 -1
@@ -176,7 +176,7 @@ static int __init samsungq10_init(void) samsungq10_probe, NULL, 0, NULL, 0); -return PTR_RET (samsungq10_device); +return PTR_ERR_OR_ZERO (samsungq10_device); } static void __exit samsungq10_exit(void)
drivers/regulator/fan53555.c +1 -1
@@ -219,7 +219,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di, rdesc->owner =THIS_MODULE ; di->rdev =regulator_register (&di->desc, config); -return PTR_RET (di->rdev); +return PTR_ERR_OR_ZERO (di->rdev); }
drivers/spi/spi-fsl-spi.c +1 -1
@@ -901,7 +901,7 @@ static int plat_mpc8xxx_spi_probe(struct platform_device *pdev)return -EINVAL ; master =fsl_spi_probe (&pdev->dev, mem, irq); -return PTR_RET (master); +return PTR_ERR_OR_ZERO (master); }static int plat_mpc8xxx_spi_remove (struct platform_device *pdev)
drivers/spi/spidev.c +1 -1
@@ -603,7 +603,7 @@ static int spidev_probe(struct spi_device *spi) dev =device_create (spidev_class, &spi->dev, spidev->devt, spidev,"spidev%d.%d" , spi->master->bus_num, spi->chip_select); - status =PTR_RET (dev); + status =PTR_ERR_OR_ZERO (dev); }else {dev_dbg (&spi->dev,"no minor number available!\n" ); status = -ENODEV ;
drivers/video/omap2/dss/core.c +1 -1
@@ -189,7 +189,7 @@ int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *)) d =debugfs_create_file (name,S_IRUGO , dss_debugfs_dir, write, &dss_debug_fops); - return PTR_RET(d); + return PTR_ERR_OR_ZERO(d); }#else /* CONFIG_OMAP2_DSS_DEBUGFS */ static inline int dss_initialize_debugfs (void )
fs/btrfs/dev-replace.c +1 -1
@@ -747,7 +747,7 @@ int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info)WARN_ON (atomic_xchg ( &fs_info->mutually_exclusive_operation_running,1 )); task =kthread_run (btrfs_dev_replace_kthread, fs_info,"btrfs-devrepl" ); -return PTR_RET (task); +return PTR_ERR_OR_ZERO (task); }static int btrfs_dev_replace_kthread (void *data)
fs/btrfs/inode.c +1 -1
@@ -3140,7 +3140,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) found_key.type =BTRFS_INODE_ITEM_KEY ; found_key.offset =0 ; inode =btrfs_iget (root->fs_info->sb, &found_key, root,NULL ); - ret =PTR_RET (inode); + ret =PTR_ERR_OR_ZERO (inode);if (ret && ret != -ESTALE ) goto out;
net/bluetooth/hci_sysfs.c +1 -1
@@ -590,7 +590,7 @@ int __init bt_sysfs_init(void) bt_class =class_create (THIS_MODULE ,"bluetooth" ); -return PTR_RET (bt_class); +return PTR_ERR_OR_ZERO (bt_class); }void bt_sysfs_cleanup (void )
net/bridge/netfilter/ebtable_broute.c +1 -1
@@ -64,7 +64,7 @@ static int ebt_broute(struct sk_buff *skb)static int __net_init broute_net_init (struct net *net) { net->xt.broute_table =ebt_register_table (net, &broute_table); -return PTR_RET (net->xt.broute_table); +return PTR_ERR_OR_ZERO (net->xt.broute_table); } static void __net_exit broute_net_exit(struct net *net)
net/bridge/netfilter/ebtable_filter.c +1 -1
@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {static int __net_init frame_filter_net_init (struct net *net) { net->xt.frame_filter =ebt_register_table (net, &frame_filter); -return PTR_RET (net->xt.frame_filter); +return PTR_ERR_OR_ZERO (net->xt.frame_filter); } static void __net_exit frame_filter_net_exit(struct net *net)
net/bridge/netfilter/ebtable_nat.c +1 -1
@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {static int __net_init frame_nat_net_init (struct net *net) { net->xt.frame_nat =ebt_register_table (net, &frame_nat); -return PTR_RET (net->xt.frame_nat); +return PTR_ERR_OR_ZERO (net->xt.frame_nat); } static void __net_exit frame_nat_net_exit(struct net *net)
net/ipv4/netfilter/arptable_filter.c +1 -1
@@ -48,7 +48,7 @@ static int __net_init arptable_filter_net_init(struct net *net) net->ipv4.arptable_filter =arpt_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv4.arptable_filter); +return PTR_ERR_OR_ZERO (net->ipv4.arptable_filter); } static void __net_exit arptable_filter_net_exit(struct net *net)
net/ipv4/netfilter/iptable_filter.c +1 -1
@@ -69,7 +69,7 @@ static int __net_init iptable_filter_net_init(struct net *net) net->ipv4.iptable_filter =ipt_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_filter); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_filter); } static void __net_exit iptable_filter_net_exit(struct net *net)
net/ipv4/netfilter/iptable_mangle.c +1 -1
@@ -107,7 +107,7 @@ static int __net_init iptable_mangle_net_init(struct net *net) net->ipv4.iptable_mangle =ipt_register_table (net, &packet_mangler, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_mangle); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_mangle); } static void __net_exit iptable_mangle_net_exit(struct net *net)
net/ipv4/netfilter/iptable_nat.c +1 -1
@@ -292,7 +292,7 @@ static int __net_init iptable_nat_net_init(struct net *net)return -ENOMEM ; net->ipv4.nat_table =ipt_register_table (net, &nf_nat_ipv4_table, repl);kfree (repl); -return PTR_RET (net->ipv4.nat_table); +return PTR_ERR_OR_ZERO (net->ipv4.nat_table); } static void __net_exit iptable_nat_net_exit(struct net *net)
net/ipv4/netfilter/iptable_raw.c +1 -1
@@ -48,7 +48,7 @@ static int __net_init iptable_raw_net_init(struct net *net) net->ipv4.iptable_raw =ipt_register_table (net, &packet_raw, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_raw); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_raw); } static void __net_exit iptable_raw_net_exit(struct net *net)
net/ipv4/netfilter/iptable_security.c +1 -1
@@ -66,7 +66,7 @@ static int __net_init iptable_security_net_init(struct net *net) net->ipv4.iptable_security =ipt_register_table (net, &security_table, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_security); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_security); } static void __net_exit iptable_security_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_filter.c +1 -1
@@ -61,7 +61,7 @@ static int __net_init ip6table_filter_net_init(struct net *net) net->ipv6.ip6table_filter =ip6t_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_filter); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_filter); } static void __net_exit ip6table_filter_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_mangle.c +1 -1
@@ -101,7 +101,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net) net->ipv6.ip6table_mangle =ip6t_register_table (net, &packet_mangler, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_mangle); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_mangle); } static void __net_exit ip6table_mangle_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_nat.c +1 -1
@@ -293,7 +293,7 @@ static int __net_init ip6table_nat_net_init(struct net *net)return -ENOMEM ; net->ipv6.ip6table_nat =ip6t_register_table (net, &nf_nat_ipv6_table, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_nat); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_nat); } static void __net_exit ip6table_nat_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_raw.c +1 -1
@@ -40,7 +40,7 @@ static int __net_init ip6table_raw_net_init(struct net *net) net->ipv6.ip6table_raw =ip6t_register_table (net, &packet_raw, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_raw); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_raw); } static void __net_exit ip6table_raw_net_exit(struct net *net)
net/ipv6/netfilter/ip6table_security.c +1 -1
@@ -58,7 +58,7 @@ static int __net_init ip6table_security_net_init(struct net *net) net->ipv6.ip6table_security =ip6t_register_table (net, &security_table, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_security); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_security); } static void __net_exit ip6table_security_net_exit(struct net *net)
scripts/coccinelle/api/ptr_ret.cocci +5 -5
@@ -1,5 +1,5 @@ /// -/// Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR +/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR /// // Confidence: High // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
@@ -7,7 +7,7 @@ // URL: http://coccinelle.lip6.fr/ // Options: -no_includes -include_headers // -// Keywords: ERR_PTR, PTR_ERR, PTR_RET +// Keywords: ERR_PTR, PTR_ERR, PTR_RET, PTR_ERR_OR_ZERO // Version min: 2.6.39 //
@@ -21,21 +21,21 @@ expression ptr; @@ - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; -+ return PTR_RET(ptr); ++ return PTR_ERR_OR_ZERO(ptr); @depends on patch@ expression ptr; @@ - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; -+ return PTR_RET(ptr); ++ return PTR_ERR_OR_ZERO(ptr); @depends on patch@ expression ptr; @@ - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) -+ PTR_RET(ptr) ++ PTR_ERR_OR_ZERO(ptr) @r1 depends on !patch@ expression ptr;
sound/soc/soc-io.c +1 -1
@@ -158,7 +158,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, return -EINVAL; } -return PTR_RET (codec->control_data); +return PTR_ERR_OR_ZERO (codec->control_data); }EXPORT_SYMBOL_GPL (snd_soc_codec_set_cache_io);#else
Signature · 1 line
1.8.1.2
Re: [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
From: Rusty Russell <[email protected]>
Date: Sun, 16 Jun 2013 14:12:41 +0930
Quoted 7 lines
Sweep of the simple cases.
Cc netdev at vger.kernel.orgCc linuxppc-dev at lists.ozlabs.orgCc linux-arm-kernel at lists.infradead.orgCc Julia Lawall <[email protected]>Signed-off-by Rusty Russell <[email protected]>
Re: [PATCH 2/9] PTR_RET is now PTR_ERR_OR_ZERO(): Replace most.
In reply to Rusty RussellQuoted 7 lines · Rusty Russell
Sweep of the simple cases.
Cc netdev at vger.kernel.orgCc linuxppc-dev at lists.ozlabs.orgCc linux-arm-kernel at lists.infradead.orgCc Julia Lawall <[email protected]>Signed-off-by Rusty Russell <[email protected]>
Quoted 636 lines
--- arch/arm/mach-omap2/i2c.c | 2 +- arch/m68k/amiga/platform.c | 2 +- arch/m68k/kernel/time.c | 2 +- arch/m68k/q40/config.c | 2 +- arch/powerpc/kernel/iommu.c | 2 +- arch/powerpc/kernel/time.c | 2 +- arch/powerpc/platforms/ps3/time.c | 2 +- arch/powerpc/sysdev/rtc_cmos_setup.c | 2 +- arch/s390/hypfs/hypfs_dbfs.c | 2 +- drivers/char/tile-srom.c | 2 +- drivers/infiniband/core/cma.c | 2 +- drivers/net/appletalk/cops.c | 2 +- drivers/net/appletalk/ltpc.c | 2 +- drivers/net/ethernet/amd/atarilance.c | 2 +- drivers/net/ethernet/amd/mvme147.c | 2 +- drivers/net/ethernet/amd/ni65.c | 2 +- drivers/net/ethernet/amd/sun3lance.c | 2 +- drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c | 2 +- drivers/net/wireless/brcm80211/brcmsmac/debug.c | 2 +- drivers/platform/x86/samsung-q10.c | 2 +- drivers/regulator/fan53555.c | 2 +- drivers/spi/spi-fsl-spi.c | 2 +- drivers/spi/spidev.c | 2 +- drivers/video/omap2/dss/core.c | 2 +- fs/btrfs/dev-replace.c | 2 +- fs/btrfs/inode.c | 2 +- net/bluetooth/hci_sysfs.c | 2 +- net/bridge/netfilter/ebtable_broute.c | 2 +- net/bridge/netfilter/ebtable_filter.c | 2 +- net/bridge/netfilter/ebtable_nat.c | 2 +- net/ipv4/netfilter/arptable_filter.c | 2 +- net/ipv4/netfilter/iptable_filter.c | 2 +- net/ipv4/netfilter/iptable_mangle.c | 2 +- net/ipv4/netfilter/iptable_nat.c | 2 +- net/ipv4/netfilter/iptable_raw.c | 2 +- net/ipv4/netfilter/iptable_security.c | 2 +- net/ipv6/netfilter/ip6table_filter.c | 2 +- net/ipv6/netfilter/ip6table_mangle.c | 2 +- net/ipv6/netfilter/ip6table_nat.c | 2 +- net/ipv6/netfilter/ip6table_raw.c | 2 +- net/ipv6/netfilter/ip6table_security.c | 2 +- scripts/coccinelle/api/ptr_ret.cocci | 10 +++++----- sound/soc/soc-io.c | 2 +- 43 files changed, 47 insertions(+), 47 deletions(-)arch/arm/mach-omap2/i2c.c +1
-1@@ -181,7 +181,7 @@ int __init omap_i2c_add_bus(struct omap_i2c_bus_platform_data *i2c_pdata, sizeof(struct omap_i2c_bus_platform_data));WARN (IS_ERR (pdev),"Could not build omap_device for %s\n" , name); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }static int __init omap_i2c_cmdline (void )arch/m68k/amiga/platform.c +1
-1@@ -56,7 +56,7 @@ static int __init amiga_init_bus(void) n =AMIGAHW_PRESENT (ZORRO3 ) ?4 :2 ; pdev =platform_device_register_simple ("amiga-zorro" ,-1 , zorro_resources, n); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }subsys_initcall (amiga_init_bus);arch/m68k/kernel/time.c +1
-1@@ -90,7 +90,7 @@ static int __init rtc_init(void)return -ENODEV ; pdev =platform_device_register_simple ("rtc-generic" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (rtc_init);arch/m68k/q40/config.c +1
-1@@ -338,6 +338,6 @@ static __init int q40_add_kbd_device(void)return -ENODEV ; pdev =platform_device_register_simple ("q40kbd" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }arch_initcall (q40_add_kbd_device);arch/powerpc/kernel/iommu.c +1
-1@@ -102,7 +102,7 @@ static int __init fail_iommu_debugfs(void)struct dentry *dir =fault_create_debugfs_attr ("fail_iommu" ,NULL , &fail_iommu); -return PTR_RET (dir); +return PTR_ERR_OR_ZERO (dir); }late_initcall (fail_iommu_debugfs);arch/powerpc/kernel/time.c +1
-1@@ -1050,7 +1050,7 @@ static int __init rtc_init(void) pdev =platform_device_register_simple ("rtc-generic" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (rtc_init);arch/powerpc/platforms/ps3/time.c +1
-1@@ -90,7 +90,7 @@ static int __init ps3_rtc_init(void) pdev =platform_device_register_simple ("rtc-ps3" ,-1 ,NULL ,0 ); -return PTR_RET (pdev); +return PTR_ERR_OR_ZERO (pdev); }module_init (ps3_rtc_init);arch/powerpc/sysdev/rtc_cmos_setup.c +1
-1@@ -62,7 +62,7 @@ static int __init add_rtc(void) pd =platform_device_register_simple ("rtc_cmos" ,-1 , &res[0 ], num_res); -return PTR_RET (pd); +return PTR_ERR_OR_ZERO (pd); }fs_initcall (add_rtc);arch/s390/hypfs/hypfs_dbfs.c +1
-1@@ -105,7 +105,7 @@ void hypfs_dbfs_remove_file(struct hypfs_dbfs_file *df)int hypfs_dbfs_init (void ) { dbfs_dir =debugfs_create_dir ("s390_hypfs" ,NULL ); -return PTR_RET (dbfs_dir); +return PTR_ERR_OR_ZERO (dbfs_dir); }void hypfs_dbfs_exit (void )drivers/char/tile-srom.c +1
-1@@ -371,7 +371,7 @@ static int srom_setup_minor(struct srom_dev *srom, int index) dev =device_create (srom_class, &platform_bus,MKDEV (srom_major, index), srom,"%d" , index); -return PTR_RET (dev); +return PTR_ERR_OR_ZERO (dev); }/** srom_init() - Initialize the driver's module. */ drivers/infiniband/core/cma.c +1
-1@@ -3055,7 +3055,7 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv, id_priv->id.port_num, &rec, comp_mask,GFP_KERNEL , cma_ib_mc_handler, mc); -return PTR_RET (mc->multicast.ib); +return PTR_ERR_OR_ZERO (mc->multicast.ib); }static void iboe_mcast_work_handler (struct work_struct *work)drivers/net/appletalk/cops.c +1
-1@@ -996,7 +996,7 @@ static int __init cops_module_init(void)printk (KERN_WARNING "%s: You shouldn't autoprobe with insmod\n" , cardname); cops_dev =cops_probe (-1 ); -return PTR_RET (cops_dev); +return PTR_ERR_OR_ZERO (cops_dev); } static void __exit cops_module_exit(void)drivers/net/appletalk/ltpc.c +1
-1@@ -1243,7 +1243,7 @@ static int __init ltpc_module_init(void) "ltpc: Autoprobing is not recommended for modules\n"); dev_ltpc =ltpc_probe (); - return PTR_RET(dev_ltpc); + return PTR_ERR_OR_ZERO(dev_ltpc); }module_init (ltpc_module_init);#endif drivers/net/ethernet/amd/atarilance.c +1
-1@@ -1147,7 +1147,7 @@ static struct net_device *atarilance_dev;static int __init atarilance_module_init (void ) { atarilance_dev =atarilance_probe (-1 ); -return PTR_RET (atarilance_dev); +return PTR_ERR_OR_ZERO (atarilance_dev); } static void __exit atarilance_module_exit(void)drivers/net/ethernet/amd/mvme147.c +1
-1@@ -188,7 +188,7 @@ static struct net_device *dev_mvme147_lance;int __init init_module (void ) { dev_mvme147_lance =mvme147lance_probe (-1 ); -return PTR_RET (dev_mvme147_lance); +return PTR_ERR_OR_ZERO (dev_mvme147_lance); } void __exit cleanup_module(void)drivers/net/ethernet/amd/ni65.c +1
-1@@ -1238,7 +1238,7 @@ MODULE_PARM_DESC(dma, "ni6510 ISA DMA channel (ignored for some cards)");int __init init_module (void ) { dev_ni65 =ni65_probe (-1 ); -return PTR_RET (dev_ni65); +return PTR_ERR_OR_ZERO (dev_ni65); } void __exit cleanup_module(void)drivers/net/ethernet/amd/sun3lance.c +1
-1@@ -940,7 +940,7 @@ static struct net_device *sun3lance_dev;int __init init_module (void ) { sun3lance_dev =sun3lance_probe (-1 ); -return PTR_RET (sun3lance_dev); +return PTR_ERR_OR_ZERO (sun3lance_dev); } void __exit cleanup_module(void)drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c +1
-1@@ -50,7 +50,7 @@ int brcmf_debugfs_attach(struct brcmf_pub *drvr)return -ENODEV ; drvr->dbgfs_dir =debugfs_create_dir (dev_name (dev), root_folder); -return PTR_RET (drvr->dbgfs_dir); +return PTR_ERR_OR_ZERO (drvr->dbgfs_dir); }void brcmf_debugfs_detach (struct brcmf_pub *drvr)drivers/net/wireless/brcm80211/brcmsmac/debug.c +1
-1@@ -56,7 +56,7 @@ int brcms_debugfs_attach(struct brcms_pub *drvr) drvr->dbgfs_dir =debugfs_create_dir (dev_name (&drvr->wlc->hw->d11core->dev), root_folder); -return PTR_RET (drvr->dbgfs_dir); +return PTR_ERR_OR_ZERO (drvr->dbgfs_dir); }void brcms_debugfs_detach (struct brcms_pub *drvr)drivers/platform/x86/samsung-q10.c +1
-1@@ -176,7 +176,7 @@ static int __init samsungq10_init(void) samsungq10_probe, NULL, 0, NULL, 0); -return PTR_RET (samsungq10_device); +return PTR_ERR_OR_ZERO (samsungq10_device); } static void __exit samsungq10_exit(void)drivers/regulator/fan53555.c +1
-1@@ -219,7 +219,7 @@ static int fan53555_regulator_register(struct fan53555_device_info *di, rdesc->owner =THIS_MODULE ; di->rdev =regulator_register (&di->desc, config); -return PTR_RET (di->rdev); +return PTR_ERR_OR_ZERO (di->rdev); }drivers/spi/spi-fsl-spi.c +1
-1@@ -901,7 +901,7 @@ static int plat_mpc8xxx_spi_probe(struct platform_device *pdev)return -EINVAL ; master =fsl_spi_probe (&pdev->dev, mem, irq); -return PTR_RET (master); +return PTR_ERR_OR_ZERO (master); }static int plat_mpc8xxx_spi_remove (struct platform_device *pdev)drivers/spi/spidev.c +1
-1@@ -603,7 +603,7 @@ static int spidev_probe(struct spi_device *spi) dev =device_create (spidev_class, &spi->dev, spidev->devt, spidev,"spidev%d.%d" , spi->master->bus_num, spi->chip_select); - status =PTR_RET (dev); + status =PTR_ERR_OR_ZERO (dev); }else {dev_dbg (&spi->dev,"no minor number available!\n" ); status = -ENODEV ;drivers/video/omap2/dss/core.c +1
-1@@ -189,7 +189,7 @@ int dss_debugfs_create_file(const char *name, void (*write)(struct seq_file *)) d =debugfs_create_file (name,S_IRUGO , dss_debugfs_dir, write, &dss_debug_fops); - return PTR_RET(d); + return PTR_ERR_OR_ZERO(d); }#else /* CONFIG_OMAP2_DSS_DEBUGFS */ static inline int dss_initialize_debugfs (void )fs/btrfs/dev-replace.c +1
-1@@ -747,7 +747,7 @@ int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info)WARN_ON (atomic_xchg ( &fs_info->mutually_exclusive_operation_running,1 )); task =kthread_run (btrfs_dev_replace_kthread, fs_info,"btrfs-devrepl" ); -return PTR_RET (task); +return PTR_ERR_OR_ZERO (task); }static int btrfs_dev_replace_kthread (void *data)fs/btrfs/inode.c +1
-1@@ -3140,7 +3140,7 @@ int btrfs_orphan_cleanup(struct btrfs_root *root) found_key.type =BTRFS_INODE_ITEM_KEY ; found_key.offset =0 ; inode =btrfs_iget (root->fs_info->sb, &found_key, root,NULL ); - ret =PTR_RET (inode); + ret =PTR_ERR_OR_ZERO (inode);if (ret && ret != -ESTALE ) goto out;net/bluetooth/hci_sysfs.c +1
-1@@ -590,7 +590,7 @@ int __init bt_sysfs_init(void) bt_class =class_create (THIS_MODULE ,"bluetooth" ); -return PTR_RET (bt_class); +return PTR_ERR_OR_ZERO (bt_class); }void bt_sysfs_cleanup (void )net/bridge/netfilter/ebtable_broute.c +1
-1@@ -64,7 +64,7 @@ static int ebt_broute(struct sk_buff *skb)static int __net_init broute_net_init (struct net *net) { net->xt.broute_table =ebt_register_table (net, &broute_table); -return PTR_RET (net->xt.broute_table); +return PTR_ERR_OR_ZERO (net->xt.broute_table); } static void __net_exit broute_net_exit(struct net *net)net/bridge/netfilter/ebtable_filter.c +1
-1@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {static int __net_init frame_filter_net_init (struct net *net) { net->xt.frame_filter =ebt_register_table (net, &frame_filter); -return PTR_RET (net->xt.frame_filter); +return PTR_ERR_OR_ZERO (net->xt.frame_filter); } static void __net_exit frame_filter_net_exit(struct net *net)net/bridge/netfilter/ebtable_nat.c +1
-1@@ -100,7 +100,7 @@ static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {static int __net_init frame_nat_net_init (struct net *net) { net->xt.frame_nat =ebt_register_table (net, &frame_nat); -return PTR_RET (net->xt.frame_nat); +return PTR_ERR_OR_ZERO (net->xt.frame_nat); } static void __net_exit frame_nat_net_exit(struct net *net)net/ipv4/netfilter/arptable_filter.c +1
-1@@ -48,7 +48,7 @@ static int __net_init arptable_filter_net_init(struct net *net) net->ipv4.arptable_filter =arpt_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv4.arptable_filter); +return PTR_ERR_OR_ZERO (net->ipv4.arptable_filter); } static void __net_exit arptable_filter_net_exit(struct net *net)net/ipv4/netfilter/iptable_filter.c +1
-1@@ -69,7 +69,7 @@ static int __net_init iptable_filter_net_init(struct net *net) net->ipv4.iptable_filter =ipt_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_filter); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_filter); } static void __net_exit iptable_filter_net_exit(struct net *net)net/ipv4/netfilter/iptable_mangle.c +1
-1@@ -107,7 +107,7 @@ static int __net_init iptable_mangle_net_init(struct net *net) net->ipv4.iptable_mangle =ipt_register_table (net, &packet_mangler, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_mangle); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_mangle); } static void __net_exit iptable_mangle_net_exit(struct net *net)net/ipv4/netfilter/iptable_nat.c +1
-1@@ -292,7 +292,7 @@ static int __net_init iptable_nat_net_init(struct net *net)return -ENOMEM ; net->ipv4.nat_table =ipt_register_table (net, &nf_nat_ipv4_table, repl);kfree (repl); -return PTR_RET (net->ipv4.nat_table); +return PTR_ERR_OR_ZERO (net->ipv4.nat_table); } static void __net_exit iptable_nat_net_exit(struct net *net)net/ipv4/netfilter/iptable_raw.c +1
-1@@ -48,7 +48,7 @@ static int __net_init iptable_raw_net_init(struct net *net) net->ipv4.iptable_raw =ipt_register_table (net, &packet_raw, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_raw); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_raw); } static void __net_exit iptable_raw_net_exit(struct net *net)net/ipv4/netfilter/iptable_security.c +1
-1@@ -66,7 +66,7 @@ static int __net_init iptable_security_net_init(struct net *net) net->ipv4.iptable_security =ipt_register_table (net, &security_table, repl);kfree (repl); -return PTR_RET (net->ipv4.iptable_security); +return PTR_ERR_OR_ZERO (net->ipv4.iptable_security); } static void __net_exit iptable_security_net_exit(struct net *net)net/ipv6/netfilter/ip6table_filter.c +1
-1@@ -61,7 +61,7 @@ static int __net_init ip6table_filter_net_init(struct net *net) net->ipv6.ip6table_filter =ip6t_register_table (net, &packet_filter, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_filter); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_filter); } static void __net_exit ip6table_filter_net_exit(struct net *net)net/ipv6/netfilter/ip6table_mangle.c +1
-1@@ -101,7 +101,7 @@ static int __net_init ip6table_mangle_net_init(struct net *net) net->ipv6.ip6table_mangle =ip6t_register_table (net, &packet_mangler, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_mangle); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_mangle); } static void __net_exit ip6table_mangle_net_exit(struct net *net)net/ipv6/netfilter/ip6table_nat.c +1
-1@@ -293,7 +293,7 @@ static int __net_init ip6table_nat_net_init(struct net *net)return -ENOMEM ; net->ipv6.ip6table_nat =ip6t_register_table (net, &nf_nat_ipv6_table, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_nat); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_nat); } static void __net_exit ip6table_nat_net_exit(struct net *net)net/ipv6/netfilter/ip6table_raw.c +1
-1@@ -40,7 +40,7 @@ static int __net_init ip6table_raw_net_init(struct net *net) net->ipv6.ip6table_raw =ip6t_register_table (net, &packet_raw, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_raw); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_raw); } static void __net_exit ip6table_raw_net_exit(struct net *net)net/ipv6/netfilter/ip6table_security.c +1
-1@@ -58,7 +58,7 @@ static int __net_init ip6table_security_net_init(struct net *net) net->ipv6.ip6table_security =ip6t_register_table (net, &security_table, repl);kfree (repl); -return PTR_RET (net->ipv6.ip6table_security); +return PTR_ERR_OR_ZERO (net->ipv6.ip6table_security); } static void __net_exit ip6table_security_net_exit(struct net *net)scripts/coccinelle/api/ptr_ret.cocci +5
-5@@ -1,5 +1,5 @@ /// -/// Use PTR_RET rather than if(IS_ERR(...)) + PTR_ERR +/// Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR /// // Confidence: High // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.@@ -7,7 +7,7 @@ // URL: http://coccinelle.lip6.fr/ // Options: -no_includes -include_headers // -// Keywords: ERR_PTR, PTR_ERR, PTR_RET +// Keywords: ERR_PTR, PTR_ERR, PTR_RET, PTR_ERR_OR_ZERO // Version min: 2.6.39 //@@ -21,21 +21,21 @@ expression ptr; @@ - if (IS_ERR(ptr)) return PTR_ERR(ptr); else return 0; -+ return PTR_RET(ptr); ++ return PTR_ERR_OR_ZERO(ptr); @depends on patch@ expression ptr; @@ - if (IS_ERR(ptr)) return PTR_ERR(ptr); return 0; -+ return PTR_RET(ptr); ++ return PTR_ERR_OR_ZERO(ptr); @depends on patch@ expression ptr; @@ - (IS_ERR(ptr) ? PTR_ERR(ptr) : 0) -+ PTR_RET(ptr) ++ PTR_ERR_OR_ZERO(ptr) @r1 depends on !patch@ expression ptr;sound/soc/soc-io.c +1
-1@@ -158,7 +158,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, return -EINVAL; } -return PTR_RET (codec->control_data); +return PTR_ERR_OR_ZERO (codec->control_data); }EXPORT_SYMBOL_GPL (snd_soc_codec_set_cache_io);#else
PATCH 3/9 s390: Replace weird use of PTR_RET.
In reply to Rusty RussellSaves repeating "(void __force *)__uptr" but it's less clear. Using the output of PTR_RET() to determine the error rather than just testing IS_ERR() is odd.
For example, I *assume* __gptr_to_uptr() never returns NULL? Because the __ret would be 0 for the old code. The new version is clearer, IMHO:
it would try to get_user() on that address.
If you hate this variant, I can just s/PTR_RET/PTR_ERR_OR_ZERO/ instead.
--- arch/s390/kvm/gaccess.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/s390/kvm/gaccess.h +8 -4
@@ -42,9 +42,11 @@ static inline void __user *__gptr_to_uptr(struct kvm_vcpu *vcpu, ({ \ __typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\ int __mask = sizeof(__typeof__(*(gptr))) - 1; \ - int __ret = PTR_RET((void __force *)__uptr); \ + int __ret; \ \ - if (!__ret) { \ + if (IS_ERR((void __force *)__uptr)) { \ + __ret = PTR_ERR((void __force *)__uptr); \ + } else { \ BUG_ON((unsigned long)__uptr & __mask); \ __ret = get_user(x, __uptr); \ } \
@@ -55,9 +57,11 @@ static inline void __user *__gptr_to_uptr(struct kvm_vcpu *vcpu, ({ \ __typeof__(gptr) __uptr = __gptr_to_uptr(vcpu, gptr, 1);\ int __mask = sizeof(__typeof__(*(gptr))) - 1; \ - int __ret = PTR_RET((void __force *)__uptr); \ + int __ret; \ \ - if (!__ret) { \ + if (IS_ERR((void __force *)__uptr)) { \ + __ret = PTR_ERR((void __force *)__uptr); \ + } else { \ BUG_ON((unsigned long)__uptr & __mask); \ __ret = put_user(x, __uptr); \ } \
Signature · 1 line
1.8.1.2
Re: [PATCH 3/9] s390: Replace weird use of PTR_RET.
Quoted 3 lines · Rusty Russell
Saves repeating "(void
__force*)__uptr" but it's less clear. Using the output ofPTR_RET()to determine the error rather than just testingIS_ERR()is odd.
Ok, if it's confusing I won't mind if it gets changed. I intended to keep the code as short as possible, but.. ;)
Quoted 3 lines
For example, I *assume*
__gptr_to_uptr()never returns NULL? Because the__retwould be 0 for the old code. The new version is clearer, IMHO:
it would try toget_user()on that address.
__gptr_to_uptr() could return 0 and it's not an error case. In that case it should indeed try a to get_user() on that address.
Quoted 1 line
If you hate this variant, I can just s/PTR_RET/PTR_ERR_OR_ZERO/ instead.
Your patch is fine.
Quoted 7 lines
Cc Heiko Carstens <[email protected]>Cc Christian Borntraeger <[email protected]>Cc Martin Schwidefsky <[email protected]>Signed-off-by Rusty Russell <[email protected]>--- arch/s390/kvm/gaccess.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
PATCH 4/9 acpi: Replace weird use of PTR_RET.
In reply to Rusty RussellThis functions is really weird. It sets rc to -ENOMEM, then overrides it. It was converted to PTR_RET in a1458187 when it should have simply been rewritten.
This version makes it more explicit, with a single IS_ERR() test.
--- drivers/acpi/acpi_pad.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/acpi/acpi_pad.c +8 -5
@@ -231,16 +231,19 @@ static struct task_struct *ps_tsks[NR_CPUS];static unsigned int ps_tsk_num;static int create_power_saving_task (void ) { -int rc = -ENOMEM ; +int rc; ps_tsks[ps_tsk_num] =kthread_run (power_saving_thread, (void *)(unsigned long )ps_tsk_num,"acpi_pad/%d" , ps_tsk_num); - rc =PTR_RET (ps_tsks[ps_tsk_num]); -if (!rc) - ps_tsk_num++; -else + +if (IS_ERR (ps_tsks[ps_tsk_num])) { + rc =PTR_ERR (ps_tsks[ps_tsk_num]); ps_tsks[ps_tsk_num] =NULL ; + }else { + rc =0 ; + ps_tsk_num++; + }return rc; }
Signature · 1 line
1.8.1.2
Re: [PATCH 4/9] acpi: Replace weird use of PTR_RET.
Quoted 9 lines · Rusty Russell
This functions is really weird. It sets rc to
-ENOMEM, then overrides it. It was converted toPTR_RETina1458187when it should have simply been rewritten.This version makes it more explicit, with a single
IS_ERR()test.Cc Rafael J. Wysocki <[email protected]>Cc Alexandru Gheorghiu <[email protected]>Signed-off-by Rusty Russell <[email protected]>
Quoted 34 lines
--- drivers/acpi/acpi_pad.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/acpi/acpi_pad.c +8
-5@@ -231,16 +231,19 @@ static struct task_struct *ps_tsks[NR_CPUS];static unsigned int ps_tsk_num;static int create_power_saving_task (void ) { -int rc = -ENOMEM ; +int rc; ps_tsks[ps_tsk_num] =kthread_run (power_saving_thread, (void *)(unsigned long )ps_tsk_num,"acpi_pad/%d" , ps_tsk_num); - rc =PTR_RET (ps_tsks[ps_tsk_num]); -if (!rc) - ps_tsk_num++; -else + +if (IS_ERR (ps_tsks[ps_tsk_num])) { + rc =PTR_ERR (ps_tsks[ps_tsk_num]); ps_tsks[ps_tsk_num] =NULL ; + }else { + rc =0 ; + ps_tsk_num++; + }return rc; }
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.
PATCH 5/9 pinctrl: don't use PTR_RET().
In reply to Rusty RussellWe've already tested that it's an error.
--- drivers/pinctrl/mvebu/pinctrl-dove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/mvebu/pinctrl-dove.c +1 -1
@@ -597,7 +597,7 @@ static int dove_pinctrl_probe(struct platform_device *pdev) clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (clk)) {dev_err (&pdev->dev,"Unable to get pdma clock" ); -return PTR_RET (clk); +return PTR_ERR (clk); }clk_prepare_enable (clk);
Signature · 1 line
1.8.1.2
PATCH 6/9 remoteproc: don't use PTR_RET().
In reply to Rusty RussellWe've already tested that it's an error.
--- drivers/remoteproc/da8xx_remoteproc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/remoteproc/da8xx_remoteproc.c +1 -1
@@ -165,7 +165,7 @@ static int reset_assert(struct device *dev) dsp_clk =clk_get (dev,NULL );if (IS_ERR (dsp_clk)) {dev_err (dev,"clk_get error: %ld\n" ,PTR_ERR (dsp_clk)); -return PTR_RET (dsp_clk); +return PTR_ERR (dsp_clk); }davinci_clk_reset_assert (dsp_clk);
Signature · 1 line
1.8.1.2
Re: [PATCH 6/9] remoteproc: don't use PTR_RET().
Quoted 6 lines · Rusty Russell
We've already tested that it's an error.
Cc Ohad Ben-Cohen <[email protected]>Cc Robert Tivy <[email protected]>Signed-off-by Rusty Russell <[email protected]>
Thanks Rusty, feel free to take it via your tree together with the rest of the PTR_RET patches.
Re: [PATCH 6/9] remoteproc: don't use PTR_RET().
Quoted 4 lines · Ohad Ben-Cohen
Quoted 3 lines · Rusty Russell
We've already tested that it's an error.
Quoted 8 lines
Quoted 3 lines
Cc Ohad Ben-Cohen <[email protected]>Cc Robert Tivy <[email protected]>Signed-off-by Rusty Russell <[email protected]>Acked-by Ohad Ben-Cohen <[email protected]>Thanks Rusty, feel free to take it via your tree together with the rest of the
PTR_RETpatches.
Thanks, done.
Cheers,
Rusty.
PATCH 7/9 staging/zcache: don't use PTR_RET().
In reply to Rusty RussellWe've already tested that it's an error.
--- drivers/staging/zcache/zcache-main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/zcache/zcache-main.c +1 -1
@@ -1908,7 +1908,7 @@ static int zcache_init(void)#endif if (IS_ERR (old_ops) || old_ops) {if (IS_ERR (old_ops)) -return PTR_RET (old_ops); +return PTR_ERR (old_ops);pr_warn ("%s: frontswap_ops overridden\n" , namestr); } }
Signature · 1 line
1.8.1.2
PATCH 8/9 x86: remove weird PTR_ERR() in do_debug
In reply to Rusty Russell62edab905 changed the argument to notify_die() from dr6 to &dr6, but weirdly, used PTR_ERR() to cast it to a long. Since dr6 is on the stack, this is an abuse of PTR_ERR(). Cast to long, as per kernel standard.
--- arch/x86/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/traps.c +1 -1
@@ -437,7 +437,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)/* Store the virtualized DR6 value */ tsk->thread.debugreg6 = dr6; -if (notify_die (DIE_DEBUG ,"debug" , regs,PTR_ERR (&dr6), error_code, +if (notify_die (DIE_DEBUG ,"debug" , regs, (long )&dr6, error_code,SIGTRAP ) ==NOTIFY_STOP ) goto exit;
Signature · 1 line
1.8.1.2
tip-bot for Rusty Russell
merge bot[tip:x86/debug] x86: Remove weird PTR_ERR() in do_debug
x86: Remove weird PTR_ERR() in do_debug
Commit-ID: 5a802e15308f152247433d87050d1bfbf9613483 Gitweb: http://git.kernel.org/tip/5a802e15308f152247433d87050d1bfbf9613483 Author: Rusty Russell <[email protected]> AuthorDate: Sun, 16 Jun 2013 14:12:47 +0930 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 19 Jun 2013 15:01:36 +0200
x86: Remove weird PTR_ERR() in do_debug
62edab905 changed the argument to notify_die() from dr6 to &dr6, but weirdly, used PTR_ERR() to cast it to a long. Since dr6 is on the stack, this is an abuse of PTR_ERR(). Cast to long, as per kernel standard.
--- arch/x86/kernel/traps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/traps.c +1 -1
@@ -437,7 +437,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)/* Store the virtualized DR6 value */ tsk->thread.debugreg6 = dr6; -if (notify_die (DIE_DEBUG ,"debug" , regs,PTR_ERR (&dr6), error_code, +if (notify_die (DIE_DEBUG ,"debug" , regs, (long )&dr6, error_code,SIGTRAP ) ==NOTIFY_STOP ) goto exit;
PATCH 9/9 mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
In reply to Rusty RussellThe normal expectation for ERR_PTR() is to put a negative errno into a pointer. oom_kill puts the magic -1 in the result (and has since pre-git), which is probably clearer with an explicit cast.
--- mm/oom_kill.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
mm/oom_kill.c +3 -3
@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,/* * Simple selection loop. We chose the process with the highest -* number of 'points'. +* number of 'points'. Returns -1 on scan abort. * * (not docbooked, we don't want this one cluttering up the manual) */
@@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,continue ;case OOM_SCAN_ABORT :rcu_read_unlock (); -return ERR_PTR (-1UL ); +return (void *)(-1UL );case OOM_SCAN_OK :break ; };
@@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,dump_header (NULL , gfp_mask, order,NULL , mpol_mask);panic ("Out of memory and no killable processes...\n" ); } -if (PTR_ERR (p) !=-1UL ) { +if (p != (void *)-1UL ) {oom_kill_process (p, gfp_mask, order, points, totalpages,NULL , nodemask,"Out of memory" ); killed =1 ;
Signature · 1 line
1.8.1.2
David Rientjes
reviewerRe: [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
Quoted 14 lines · Rusty Russell
mm/oom_kill.c +1
-1@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,/* * Simple selection loop. We chose the process with the highest -* number of 'points'. +* number of 'points'. Returns -1 on scan abort. * * (not docbooked, we don't want this one cluttering up the manual) */
mm/oom_kill.c static struct task_struct *select_bad_process(unsigned int *ppoints, · line 320
Quoted 8 lines
mm/oom_kill.c +1
-1@@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,continue ;case OOM_SCAN_ABORT :rcu_read_unlock (); -return ERR_PTR (-1UL ); +return (void *)(-1UL );case OOM_SCAN_OK :break ; };
Any reason it's not struct task_struct *?
Quoted 9 lines
mm/oom_kill.c +1
-1@@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,dump_header (NULL , gfp_mask, order,NULL , mpol_mask);panic ("Out of memory and no killable processes...\n" ); } -if (PTR_ERR (p) !=-1UL ) { +if (p != (void *)-1UL ) {oom_kill_process (p, gfp_mask, order, points, totalpages,NULL , nodemask,"Out of memory" ); killed =1 ;
Re: [PATCH 9/9] mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
Quoted 18 lines · David Rientjes
Quoted 16 lines · Rusty Russell
mm/oom_kill.c +1
-1@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,/* * Simple selection loop. We chose the process with the highest -* number of 'points'. +* number of 'points'. Returns -1 on scan abort. * * (not docbooked, we don't want this one cluttering up the manual) */ @@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,continue ;case OOM_SCAN_ABORT :
Quoted 8 lines
mm/oom_kill.c static struct task_struct *select_bad_process(unsigned int *ppoints, · line 320
Quoted 6 lines
mm/oom_kill.c +1
-1rcu_read_unlock (); -return ERR_PTR (-1UL ); +return (void *)(-1UL );case OOM_SCAN_OK :break ; };Any reason it's not struct
task_struct*?
No good one. Changed.
Cheers,
Rusty.
Subject: mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().
The normal expectation for ERR_PTR() is to put a negative errno into a pointer. oom_kill puts the magic -1 in the result (and has since pre-git), which is probably clearer with an explicit cast.
mm/oom_kill.c +3 -3
@@ -288,7 +288,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task,/* * Simple selection loop. We chose the process with the highest -* number of 'points'. +* number of 'points'. Returns -1 on scan abort. * * (not docbooked, we don't want this one cluttering up the manual) */
@@ -314,7 +314,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,continue ;case OOM_SCAN_ABORT :rcu_read_unlock (); -return ERR_PTR (-1UL ); +return (struct task_struct *)(-1UL );case OOM_SCAN_OK :break ; };
@@ -657,7 +657,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,dump_header (NULL , gfp_mask, order,NULL , mpol_mask);panic ("Out of memory and no killable processes...\n" ); } -if (PTR_ERR (p) !=-1UL ) { +if (p != (void *)-1UL ) {oom_kill_process (p, gfp_mask, order, points, totalpages,NULL , nodemask,"Out of memory" ); killed =1 ;
Re: [RFC] PTR_ERR: return 0 if ptr isn't an error value.
In reply to Uwe Kleine-KönigQuoted 11 lines · Uwe Kleine-König
Hello Rusty,
[added akpm to Cc: who took the patch back then and Julia for the coccinelle part below]
Quoted 5 lines · Rusty Russell
Back in 2011, Uwe Kleine-König added the nonsensically-named
PTR_RET(), providing a means to avoidif()statements in code (commitfa9ee9c4b9).
Quoted 6 lines
Quoted 4 lines
Instead, just make
PTR_ERR()return 0 if the pointer isn't an error value. This is harmless, sincePTR_ERR()should have never been passed a non-error value. And GCC is usually smart enough to remove the extra test ifIS_ERR()has already been called.I wonder in which situations gcc fails to be smart enough. Did you check this?
Good q. I just wrote a simple test to confirm that GCC usually did, then compared the text sizes. Since it was bigger, I assume GCC isn't doing it all the time.
Hmm, first change is in do_debug. Ah, no surprise here:
if (notify_die(DIE_DEBUG, "debug", regs, PTR_ERR(&dr6), error_code, SIGTRAP) == NOTIFY_STOP) goto exit;
Huh? dr6 is on the stack? Ancient, fixed.
I'll wade through the other differences after the weekend...
Cheers,
Rusty.