Skip to contentSkip to conversation

trivial: Drop unlikely before IS_ERR(_OR_NULL)

PATCH Applied Viresh Kumar 18 participants 49 messages Jul 31, 2015 – Aug 11, 2015

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

cover trivial: Drop unlikely before IS_ERR(_OR_NULL)

Hi,

This cleans up the usage of IS_ERR(_OR_NULL)(), where the callers have added additional unlikely compiler flag to them. It also fixes the definition of IS_ERR_OR_NULL(), to use unlikely for all checks it does.

Viresh Kumar (15):
err.h: add (missing) unlikely() to IS_ERR_OR_NULL() PM / OPP: Drop unlikely before IS_ERR(_OR_NULL)
drivers: devfreq: Drop unlikely before IS_ERR(_OR_NULL)
drivers: gpu: Drop unlikely before IS_ERR(_OR_NULL)
drivers: input: Drop unlikely before IS_ERR(_OR_NULL)
drivers: md: Drop unlikely before IS_ERR(_OR_NULL)
drivers: misc: Drop unlikely before IS_ERR(_OR_NULL)
drivers: net: Drop unlikely before IS_ERR(_OR_NULL)
drivers: rtc: Drop unlikely before IS_ERR(_OR_NULL)
drivers: staging: Drop unlikely before IS_ERR(_OR_NULL)
drivers: target: Drop unlikely before IS_ERR(_OR_NULL)
fs: Drop unlikely before IS_ERR(_OR_NULL)
blk-cgroup: Drop unlikely before IS_ERR(_OR_NULL)
mm: Drop unlikely before IS_ERR(_OR_NULL)
net: Drop unlikely before IS_ERR(_OR_NULL)

 drivers/base/power/opp.c                             | 6 +++---
 drivers/devfreq/devfreq.c                            | 4 ++--
 drivers/gpu/drm/ttm/ttm_tt.c                         | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c              | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c                  | 2 +-
 drivers/input/mouse/alps.c                           | 2 +-
 drivers/md/dm-snap-persistent.c                      | 2 +-
 drivers/md/dm-verity.c                               | 2 +-
 drivers/md/persistent-data/dm-block-manager.c        | 8 ++++----
 drivers/misc/c2port/core.c                           | 2 +-
 drivers/net/ethernet/ti/netcp_core.c                 | 4 ++--
 drivers/rtc/interface.c                              | 2 +-
 drivers/rtc/rtc-bfin.c                               | 2 +-
 drivers/rtc/rtc-gemini.c                             | 2 +-
 drivers/staging/android/ashmem.c                     | 2 +-
 drivers/staging/lustre/include/linux/libcfs/libcfs.h | 2 +-
 drivers/staging/lustre/lustre/obdclass/lu_object.c   | 6 +++---
 drivers/target/tcm_fc/tfc_cmd.c                      | 2 +-
 fs/cifs/readdir.c                                    | 2 +-
 fs/ecryptfs/inode.c                                  | 2 +-
 fs/ext4/extents.c                                    | 6 +++---
 fs/ext4/namei.c                                      | 2 +-
 fs/namei.c                                           | 4 ++--
 fs/ncpfs/dir.c                                       | 2 +-
 fs/nfs/objlayout/objio_osd.c                         | 2 +-
 fs/proc/proc_sysctl.c                                | 2 +-
 include/linux/blk-cgroup.h                           | 2 +-
 include/linux/err.h                                  | 2 +-
 mm/huge_memory.c                                     | 2 +-
 net/openvswitch/datapath.c                           | 2 +-
 net/sctp/socket.c                                    | 2 +-
 net/socket.c                                         | 6 +++---
 32 files changed, 47 insertions(+), 47 deletions(-)
Signature · 1 line
2.4.0
#1 lore raw

PATCH 1/15 err.h: add (missing) unlikely() to IS_ERR_OR_NULL()

IS_ERR_VALUE() already contains it and so we need to add this only to the !ptr check. That will allow users of IS_ERR_OR_NULL(), to not add this compiler flag.

---
 include/linux/err.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/err.h +1 -1
index a729120644d5..56762ab41713 100644
@@ -37,7 +37,7 @@ static inline bool __must_check IS_ERR(__force const void *ptr)
 
 static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
 {
-	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+	return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
 }
 
 /**
Signature · 1 line
2.4.0
#2 lore raw

PATCH 2/15 PM / OPP: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/base/power/opp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/base/power/opp.c +3 -3
index 677fb2843553..f60bdd5cbb71 100644
@@ -134,7 +134,7 @@ static struct device_opp *_find_device_opp(struct device *dev)
 {
 	struct device_opp *tmp_dev_opp, *dev_opp = ERR_PTR(-ENODEV);
 
-	if (unlikely(IS_ERR_OR_NULL(dev))) {
+	if (IS_ERR_OR_NULL(dev)) {
 		pr_err("%s: Invalid parameters\n", __func__);
 		return ERR_PTR(-EINVAL);
 	}
@@ -172,7 +172,7 @@ unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
 	opp_rcu_lockdep_assert();
 
 	tmp_opp = rcu_dereference(opp);
-	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
+	if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available)
 		pr_err("%s: Invalid parameters\n", __func__);
 	else
 		v = tmp_opp->u_volt;
@@ -204,7 +204,7 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 	opp_rcu_lockdep_assert();
 
 	tmp_opp = rcu_dereference(opp);
-	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
+	if (IS_ERR_OR_NULL(tmp_opp) || !tmp_opp->available)
 		pr_err("%s: Invalid parameters\n", __func__);
 	else
 		f = tmp_opp->rate;
Signature · 1 line
2.4.0
#3 lore raw

PATCH 3/15 drivers: devfreq: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/devfreq/devfreq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/devfreq/devfreq.c +2 -2
index ca1b362d77e2..f28a1fae5691 100644
@@ -53,7 +53,7 @@ static struct devfreq *find_device_devfreq(struct device *dev)
 {
 	struct devfreq *tmp_devfreq;
 
-	if (unlikely(IS_ERR_OR_NULL(dev))) {
+	if (IS_ERR_OR_NULL(dev)) {
 		pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
 		return ERR_PTR(-EINVAL);
 	}
@@ -133,7 +133,7 @@ static struct devfreq_governor *find_devfreq_governor(const char *name)
 {
 	struct devfreq_governor *tmp_governor;
 
-	if (unlikely(IS_ERR_OR_NULL(name))) {
+	if (IS_ERR_OR_NULL(name)) {
 		pr_err("DEVFREQ: %s: Invalid parameters\n", __func__);
 		return ERR_PTR(-EINVAL);
 	}
Signature · 1 line
2.4.0
#4 lore raw

PATCH 4/15 drivers: gpu: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/gpu/drm/ttm/ttm_tt.c            | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -2
index bf080abc86d1..4e19d0f9cc30 100644
@@ -340,7 +340,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		swap_storage = shmem_file_setup("ttm swap",
 						ttm->num_pages << PAGE_SHIFT,
 						0);
-		if (unlikely(IS_ERR(swap_storage))) {
+		if (IS_ERR(swap_storage)) {
 			pr_err("Failed allocating swap storage\n");
 			return PTR_ERR(swap_storage);
 		}
@@ -354,7 +354,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		if (unlikely(from_page == NULL))
 			continue;
 		to_page = shmem_read_mapping_page(swap_space, i);
-		if (unlikely(IS_ERR(to_page))) {
+		if (IS_ERR(to_page)) {
 			ret = PTR_ERR(to_page);
 			goto out_err;
 		}
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +1 -1
index 5ac92874404d..44e6ecba3de7 100644
@@ -159,7 +159,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
 
 	if (dev_priv->has_mob) {
 		uctx->man = vmw_cmdbuf_res_man_create(dev_priv);
-		if (unlikely(IS_ERR(uctx->man))) {
+		if (IS_ERR(uctx->man)) {
 			ret = PTR_ERR(uctx->man);
 			uctx->man = NULL;
 			goto out_err;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
index 620bb5cf617c..6218a36cf01a 100644
@@ -1054,7 +1054,7 @@ static long vmw_generic_ioctl(struct file *filp, unsigned int cmd,
 		return -EINVAL;
 
 	vmaster = vmw_master_check(dev, file_priv, flags);
-	if (unlikely(IS_ERR(vmaster))) {
+	if (IS_ERR(vmaster)) {
 		ret = PTR_ERR(vmaster);
 
 		if (ret != -ERESTARTSYS)
Signature · 1 line
2.4.0
#5 lore raw

Re: [PATCH 04/15] drivers: gpu: Drop unlikely before IS_ERR(_OR_NULL)

This patch: Reviewed-by: Sinclair Yeh <[email protected]>

Quoted 61 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/gpu/drm/ttm/ttm_tt.c            | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -2
index bf080abc86d1..4e19d0f9cc30 100644
@@ -340,7 +340,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		swap_storage = shmem_file_setup("ttm swap",
 						ttm->num_pages << PAGE_SHIFT,
 						0);
-		if (unlikely(IS_ERR(swap_storage))) {
+		if (IS_ERR(swap_storage)) {
 			pr_err("Failed allocating swap storage\n");
 			return PTR_ERR(swap_storage);
 		}
@@ -354,7 +354,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		if (unlikely(from_page == NULL))
 			continue;
 		to_page = shmem_read_mapping_page(swap_space, i);
-		if (unlikely(IS_ERR(to_page))) {
+		if (IS_ERR(to_page)) {
 			ret = PTR_ERR(to_page);
 			goto out_err;
 		}
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +1 -1
index 5ac92874404d..44e6ecba3de7 100644
@@ -159,7 +159,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
 
 	if (dev_priv->has_mob) {
 		uctx->man = vmw_cmdbuf_res_man_create(dev_priv);
-		if (unlikely(IS_ERR(uctx->man))) {
+		if (IS_ERR(uctx->man)) {
 			ret = PTR_ERR(uctx->man);
 			uctx->man = NULL;
 			goto out_err;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
index 620bb5cf617c..6218a36cf01a 100644
@@ -1054,7 +1054,7 @@ static long vmw_generic_ioctl(struct file *filp, unsigned int cmd,
 		return -EINVAL;
 
 	vmaster = vmw_master_check(dev, file_priv, flags);
-	if (unlikely(IS_ERR(vmaster))) {
+	if (IS_ERR(vmaster)) {
 		ret = PTR_ERR(vmaster);
 
 		if (ret != -ERESTARTSYS)
Signature · 1 line
2.4.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [PATCH 04/15] drivers: gpu: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 7 lines · Sinclair Yeh

This patch: Reviewed-by: Sinclair Yeh <[email protected]>

Quoted 4 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

Applied to drm-misc, thanks.
-Daniel

Quoted 61 lines
Quoted 57 lines
---
 drivers/gpu/drm/ttm/ttm_tt.c            | 4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_tt.c +2 -2
index bf080abc86d1..4e19d0f9cc30 100644
@@ -340,7 +340,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		swap_storage = shmem_file_setup("ttm swap",
 						ttm->num_pages << PAGE_SHIFT,
 						0);
-		if (unlikely(IS_ERR(swap_storage))) {
+		if (IS_ERR(swap_storage)) {
 			pr_err("Failed allocating swap storage\n");
 			return PTR_ERR(swap_storage);
 		}
@@ -354,7 +354,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		if (unlikely(from_page == NULL))
 			continue;
 		to_page = shmem_read_mapping_page(swap_space, i);
-		if (unlikely(IS_ERR(to_page))) {
+		if (IS_ERR(to_page)) {
 			ret = PTR_ERR(to_page);
 			goto out_err;
 		}
drivers/gpu/drm/vmwgfx/vmwgfx_context.c +1 -1
index 5ac92874404d..44e6ecba3de7 100644
@@ -159,7 +159,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
 
 	if (dev_priv->has_mob) {
 		uctx->man = vmw_cmdbuf_res_man_create(dev_priv);
-		if (unlikely(IS_ERR(uctx->man))) {
+		if (IS_ERR(uctx->man)) {
 			ret = PTR_ERR(uctx->man);
 			uctx->man = NULL;
 			goto out_err;
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +1 -1
index 620bb5cf617c..6218a36cf01a 100644
@@ -1054,7 +1054,7 @@ static long vmw_generic_ioctl(struct file *filp, unsigned int cmd,
 		return -EINVAL;
 
 	vmaster = vmw_master_check(dev, file_priv, flags);
-	if (unlikely(IS_ERR(vmaster))) {
+	if (IS_ERR(vmaster)) {
 		ret = PTR_ERR(vmaster);
 
 		if (ret != -ERESTARTSYS)
Signature · 1 line
2.4.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

PATCH 5/15 drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/input/mouse/alps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/mouse/alps.c +1 -1
index 113d6f1516a5..cef3611a4ccd 100644
@@ -1365,7 +1365,7 @@ static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
 		/* On V2 devices the DualPoint Stick reports bare packets */
 		dev = priv->dev2;
 		dev2 = psmouse->dev;
-	} else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
+	} else if (IS_ERR_OR_NULL(priv->dev3)) {
 		/* Register dev3 mouse if we received PS/2 packet first time */
 		if (!IS_ERR(priv->dev3))
 			psmouse_queue_work(psmouse, &priv->dev3_register_work,
Signature · 1 line
2.4.0
maintainer
#8 lore raw

Re: [PATCH 05/15] drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 2 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

I'd rather keep it as it documents the expected behavior and double unlikely should work just fine.

Quoted 22 lines
---
 drivers/input/mouse/alps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/mouse/alps.c +1 -1
index 113d6f1516a5..cef3611a4ccd 100644
@@ -1365,7 +1365,7 @@ static void alps_report_bare_ps2_packet(struct psmouse *psmouse,
 		/* On V2 devices the DualPoint Stick reports bare packets */
 		dev = priv->dev2;
 		dev2 = psmouse->dev;
-	} else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
+	} else if (IS_ERR_OR_NULL(priv->dev3)) {
 		/* Register dev3 mouse if we received PS/2 packet first time */
 		if (!IS_ERR(priv->dev3))
 			psmouse_queue_work(psmouse, &priv->dev3_register_work,
Signature · 1 line
2.4.0

Thanks.

Signature · 1 line
Dmitry
#9 lore raw

Re: [PATCH 05/15] drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 6 lines · Dmitry Torokhov
Quoted 2 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

I'd rather keep it as it documents the expected behavior and double unlikely should work just fine.

TBH, I don't really agree that it is there for documentation. The only purpose of such compiler flags is to try make code more efficient.

Anyway, I got to this series as someone asked me to fix this for one of my patches which used unlikely(IS_ERR_OR_NULL()). And so I thought about fixing all sites that are doing double unlikely (that shouldn't hurt for sure).

I will leave it to you.

Signature · 1 line
viresh
#10 lore raw

Re: [PATCH 05/15] drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 12 lines · On Saturday 01 August 2015 13:22:51 Viresh Kumar wrote:
Quoted 6 lines · Dmitry Torokhov
Quoted 2 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

I'd rather keep it as it documents the expected behavior and double unlikely should work just fine.

TBH, I don't really agree that it is there for documentation. The only purpose of such compiler flags is to try make code more efficient.

Quoted 6 lines

Anyway, I got to this series as someone asked me to fix this for one of my patches which used unlikely(IS_ERR_OR_NULL()). And so I thought about fixing all sites that are doing double unlikely (that shouldn't hurt for sure).

I will leave it to you.

I think that unlikely() macro here make code more readable. Yes, it is also for compiler optimization, but also for me it looks like Clean Code pattern <https://de.wikipedia.org/wiki/Clean_Code> -- is not it?

Signature · 2 lines
Pali Rohár
[email protected]
#11 lore raw

Re: [PATCH 05/15] drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 18 lines · Pali Rohár
Quoted 17 lines · On Saturday 01 August 2015 13:22:51 Viresh Kumar wrote:
Quoted 6 lines · Dmitry Torokhov
Quoted 2 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

I'd rather keep it as it documents the expected behavior and double unlikely should work just fine.

TBH, I don't really agree that it is there for documentation. The only purpose of such compiler flags is to try make code more efficient.

Anyway, I got to this series as someone asked me to fix this for one of my patches which used unlikely(IS_ERR_OR_NULL()). And so I thought about fixing all sites that are doing double unlikely (that shouldn't hurt for sure).

Quoted 5 lines
Quoted 1 line

I will leave it to you.

I think that unlikely() macro here make code more readable. Yes, it is also for compiler optimization, but also for me it looks like Clean Code pattern <https://de.wikipedia.org/wiki/Clean_Code> -- is not it?

People know that errors are unlikely, no need to tell them. I'd remove it.
Pavel

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

Re: [PATCH 05/15] drivers: input: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 22 lines · On Sunday 02 August 2015 17:43:52 Pavel Machek wrote:
Quoted 21 lines · Pali Rohár
Quoted 19 lines · On Saturday 01 August 2015 13:22:51 Viresh Kumar wrote:
Quoted 7 lines · Dmitry Torokhov
Quoted 3 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

I'd rather keep it as it documents the expected behavior and double unlikely should work just fine.

TBH, I don't really agree that it is there for documentation. The only purpose of such compiler flags is to try make code more efficient.

Anyway, I got to this series as someone asked me to fix this for one of my patches which used unlikely(IS_ERR_OR_NULL()). And so I thought about fixing all sites that are doing double unlikely (that shouldn't hurt for sure).

I will leave it to you.

Quoted 8 lines
Quoted 4 lines

I think that unlikely() macro here make code more readable. Yes, it is also for compiler optimization, but also for me it looks like Clean Code pattern <https://de.wikipedia.org/wiki/Clean_Code> -- is not it?

People know that errors are unlikely, no need to tell them. I'd remove it.
Pavel

Errors and bugs are always unlikely ;-)

Signature · 2 lines
Pali Rohár
[email protected]
#13 lore raw

PATCH 6/15 drivers: md: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/md/dm-snap-persistent.c               | 2 +-
 drivers/md/dm-verity.c                        | 2 +-
 drivers/md/persistent-data/dm-block-manager.c | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/md/dm-snap-persistent.c +1 -1
index 808b8419bc48..bf71583296f7 100644
@@ -533,7 +533,7 @@ static int read_exceptions(struct pstore *ps,
 		chunk = area_location(ps, ps->current_area);
 
 		area = dm_bufio_read(client, chunk, &bp);
-		if (unlikely(IS_ERR(area))) {
+		if (IS_ERR(area)) {
 			r = PTR_ERR(area);
 			goto ret_destroy_bufio;
 		}
drivers/md/dm-verity.c +1 -1
index bb9c6a00e4b0..1d131519ed21 100644
@@ -271,7 +271,7 @@ static int verity_verify_level(struct dm_verity_io *io, sector_t block,
 	verity_hash_at_level(v, block, level, &hash_block, &offset);
 
 	data = dm_bufio_read(v->bufio, hash_block, &buf);
-	if (unlikely(IS_ERR(data)))
+	if (IS_ERR(data))
 		return PTR_ERR(data);
 
 	aux = dm_bufio_get_aux_data(buf);
drivers/md/persistent-data/dm-block-manager.c +4 -4
index 4d6c9b689eaa..88dbe7b97c2c 100644
@@ -454,7 +454,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
 	int r;
 
 	p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
-	if (unlikely(IS_ERR(p)))
+	if (IS_ERR(p))
 		return PTR_ERR(p);
 
 	aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -490,7 +490,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
 		return -EPERM;
 
 	p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
-	if (unlikely(IS_ERR(p)))
+	if (IS_ERR(p))
 		return PTR_ERR(p);
 
 	aux = dm_bufio_get_aux_data(to_buffer(*result));
@@ -523,7 +523,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
 	int r;
 
 	p = dm_bufio_get(bm->bufio, b, (struct dm_buffer **) result);
-	if (unlikely(IS_ERR(p)))
+	if (IS_ERR(p))
 		return PTR_ERR(p);
 	if (unlikely(!p))
 		return -EWOULDBLOCK;
@@ -559,7 +559,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
 		return -EPERM;
 
 	p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
-	if (unlikely(IS_ERR(p)))
+	if (IS_ERR(p))
 		return PTR_ERR(p);
 
 	memset(p, 0, dm_bm_block_size(bm));
Signature · 1 line
2.4.0
#14 lore raw

PATCH 7/15 drivers: misc: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/misc/c2port/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/c2port/core.c +1 -1
index 464419b36440..cc8645b5369d 100644
@@ -926,7 +926,7 @@ struct c2port_device *c2port_device_register(char *name,
 
 	c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
 				   "c2port%d", c2dev->id);
-	if (unlikely(IS_ERR(c2dev->dev))) {
+	if (IS_ERR(c2dev->dev)) {
 		ret = PTR_ERR(c2dev->dev);
 		goto error_device_create;
 	}
Signature · 1 line
2.4.0
#15 lore raw

PATCH 8/15 drivers: net: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/net/ethernet/ti/netcp_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/netcp_core.c +2 -2
index ec8ed30196f3..f685a19a3703 100644
@@ -1016,7 +1016,7 @@ netcp_tx_map_skb(struct sk_buff *skb, struct netcp_intf *netcp)
 	}
 
 	desc = knav_pool_desc_get(netcp->tx_pool);
-	if (unlikely(IS_ERR_OR_NULL(desc))) {
+	if (IS_ERR_OR_NULL(desc)) {
 		dev_err(netcp->ndev_dev, "out of TX desc\n");
 		dma_unmap_single(dev, dma_addr, pkt_len, DMA_TO_DEVICE);
 		return NULL;
@@ -1049,7 +1049,7 @@ netcp_tx_map_skb(struct sk_buff *skb, struct netcp_intf *netcp)
 		}
 
 		ndesc = knav_pool_desc_get(netcp->tx_pool);
-		if (unlikely(IS_ERR_OR_NULL(ndesc))) {
+		if (IS_ERR_OR_NULL(ndesc)) {
 			dev_err(netcp->ndev_dev, "out of TX desc for frags\n");
 			dma_unmap_page(dev, dma_addr, buf_len, DMA_TO_DEVICE);
 			goto free_descs;
Signature · 1 line
2.4.0
#16 lore raw

Re: [PATCH 08/15] drivers: net: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 3 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

IS_ERR_OR_NULL() is defined as

static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)

{
        return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}

So the unlikely() applies only to second part. Wouldn't that be a problem for optimization?

Murali

Quoted 28 lines
---
  drivers/net/ethernet/ti/netcp_core.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/ti/netcp_core.c +2 -2
index ec8ed30196f3..f685a19a3703 100644
@@ -1016,7 +1016,7 @@ netcp_tx_map_skb(struct sk_buff *skb, struct netcp_intf *netcp)
  	}
 
  	desc = knav_pool_desc_get(netcp->tx_pool);
-	if (unlikely(IS_ERR_OR_NULL(desc))) {
+	if (IS_ERR_OR_NULL(desc)) {
  		dev_err(netcp->ndev_dev, "out of TX desc\n");
  		dma_unmap_single(dev, dma_addr, pkt_len, DMA_TO_DEVICE);
  		return NULL;
@@ -1049,7 +1049,7 @@ netcp_tx_map_skb(struct sk_buff *skb, struct netcp_intf *netcp)
  		}
 
  		ndesc = knav_pool_desc_get(netcp->tx_pool);
-		if (unlikely(IS_ERR_OR_NULL(ndesc))) {
+		if (IS_ERR_OR_NULL(ndesc)) {
  			dev_err(netcp->ndev_dev, "out of TX desc for frags\n");
  			dma_unmap_page(dev, dma_addr, buf_len, DMA_TO_DEVICE);
  			goto free_descs;
Signature · 2 lines
Murali Karicheri
Linux Kernel, Keystone
#17 lore raw

RE: [PATCH 08/15] drivers: net: Drop unlikely before IS_ERR(_OR_NULL)

From: Murali Karicheri

Quoted 8 lines

Sent: 31 July 2015 16:04

Quoted 3 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

IS_ERR_OR_NULL() is defined as

Quoted 7 lines

static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)

{
         return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}

So the unlikely() applies only to second part. Wouldn't that be a problem for optimization?

Ugg...

The unlikely() in IS_ERR_VALUE() is likely to stop the compiler doing a single 'window' comparison for the range [-MAX_ERROR .. 0]. So you are likely to end up with 2 comparisons.
I suspect that:

	return IS_ERR_VALUE((unsigned long)ptr - 1);

would be a much better test.
(Ignoring the off-by-one for the highest error.)

David

#18 lore raw

Re: [PATCH 08/15] drivers: net: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Murali Karicheri
Quoted 7 lines · Murali Karicheri
Quoted 3 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

IS_ERR_OR_NULL() is defined as

Quoted 7 lines

static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)

{
        return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}

So the unlikely() applies only to second part. Wouldn't that be a problem for optimization?

This is what the first patch of the series does:

http://permalink.gmane.org/gmane.linux.kernel/2009151

Signature · 1 line
viresh
#19 lore raw

Re: [PATCH 08/15] drivers: net: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 13 lines · Viresh Kumar
Quoted 12 lines · Murali Karicheri
Quoted 3 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

IS_ERR_OR_NULL() is defined as

static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)

{
         return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}
Quoted 7 lines
Quoted 2 lines

So the unlikely() applies only to second part. Wouldn't that be a problem for optimization?

This is what the first patch of the series does:

http://permalink.gmane.org/gmane.linux.kernel/2009151

Assuming the above change is merged, this patch looks good.

Signature · 2 lines
Murali Karicheri
Linux Kernel, Keystone
#20 lore raw

PATCH 9/15 drivers: rtc: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/rtc/interface.c  | 2 +-
 drivers/rtc/rtc-bfin.c   | 2 +-
 drivers/rtc/rtc-gemini.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/interface.c +1 -1
index 11b639067312..5836751b8203 100644
@@ -564,7 +564,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
 void rtc_update_irq(struct rtc_device *rtc,
 		unsigned long num, unsigned long events)
 {
-	if (unlikely(IS_ERR_OR_NULL(rtc)))
+	if (IS_ERR_OR_NULL(rtc))
 		return;
 
 	pm_stay_awake(rtc->dev.parent);
drivers/rtc/rtc-bfin.c +1 -1
index 3d44b11721ea..535a5f9338d0 100644
@@ -361,7 +361,7 @@ static int bfin_rtc_probe(struct platform_device *pdev)
 	/* Register our RTC with the RTC framework */
 	rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
 						THIS_MODULE);
-	if (unlikely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	/* Grab the IRQ and init the hardware */
drivers/rtc/rtc-gemini.c +1 -1
index 35f4486738fc..2fed93e1114a 100644
@@ -148,7 +148,7 @@ static int gemini_rtc_probe(struct platform_device *pdev)
 
 	rtc->rtc_dev = rtc_device_register(pdev->name, dev,
 					   &gemini_rtc_ops, THIS_MODULE);
-	if (likely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	return 0;
Signature · 1 line
2.4.0
#21 lore raw

PATCH 1/1 drivers: rtc: fix ptr_ret.cocci warnings

From: kbuild test robot <[email protected]>

drivers/rtc/rtc-gemini.c:151:1-3: WARNING: PTR_ERR_OR_ZERO can be used

Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR

Generated by: scripts/coccinelle/api/ptr_ret.cocci

---
Got a cleanup patch from Fengguang, maybe we can apply this too.

 rtc-gemini.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/rtc/rtc-gemini.c +1 -4
@@ -148,10 +148,7 @@ static int gemini_rtc_probe(struct platf
 
 	rtc->rtc_dev = rtc_device_register(pdev->name, dev,
 					   &gemini_rtc_ops, THIS_MODULE);
-	if (IS_ERR(rtc->rtc_dev))
-		return PTR_ERR(rtc->rtc_dev);
-
-	return 0;
+	return PTR_ERR_OR_ZERO(rtc->rtc_dev);
 }
 
 static int gemini_rtc_remove(struct platform_device *pdev)
#22 lore raw

Re: [PATCH] drivers: rtc: fix ptr_ret.cocci warnings

Quoted 9 lines · Viresh Kumar

From: kbuild test robot <[email protected]>

drivers/rtc/rtc-gemini.c:151:1-3: WARNING: PTR_ERR_OR_ZERO can be used

Use PTR_ERR_OR_ZERO rather than if(IS_ERR(...)) + PTR_ERR

Generated by: scripts/coccinelle/api/ptr_ret.cocci

Quoted 8 lines

---
Got a cleanup patch from Fengguang, maybe we can apply this too.

 rtc-gemini.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Applied, thanks.

Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#23 lore raw

PATCH v2 9/15 drivers: rtc: Drop (un)likely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

gemini driver was using likely() for a failure case while the rtc driver is getting registered. That looks wrong and it should really be unlikely. But because we are killing all the unlikely() flags, lets kill that too.

---
V1->V2:
- Removed the likely() part from gemini driver and the changelog wasn't updated to match that. Fixed the changelog now.

 drivers/rtc/interface.c  | 2 +-
 drivers/rtc/rtc-bfin.c   | 2 +-
 drivers/rtc/rtc-gemini.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/interface.c +1 -1
index 11b639067312..5836751b8203 100644
@@ -564,7 +564,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
 void rtc_update_irq(struct rtc_device *rtc,
 		unsigned long num, unsigned long events)
 {
-	if (unlikely(IS_ERR_OR_NULL(rtc)))
+	if (IS_ERR_OR_NULL(rtc))
 		return;
 
 	pm_stay_awake(rtc->dev.parent);
drivers/rtc/rtc-bfin.c +1 -1
index 3d44b11721ea..535a5f9338d0 100644
@@ -361,7 +361,7 @@ static int bfin_rtc_probe(struct platform_device *pdev)
 	/* Register our RTC with the RTC framework */
 	rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
 						THIS_MODULE);
-	if (unlikely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	/* Grab the IRQ and init the hardware */
drivers/rtc/rtc-gemini.c +1 -1
index 35f4486738fc..2fed93e1114a 100644
@@ -148,7 +148,7 @@ static int gemini_rtc_probe(struct platform_device *pdev)
 
 	rtc->rtc_dev = rtc_device_register(pdev->name, dev,
 					   &gemini_rtc_ops, THIS_MODULE);
-	if (likely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	return 0;
Signature · 1 line
2.4.0
Acked-by on v2 9/15
#24 lore raw

Re: [PATCH 9/15 V2] drivers: rtc: Drop (un)likely before IS_ERR(_OR_NULL)

Hi

Quoted 62 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

gemini driver was using likely() for a failure case while the rtc driver is getting registered. That looks wrong and it should really be unlikely. But because we are killing all the unlikely() flags, lets kill that too.

---
V1->V2:
- Removed the likely() part from gemini driver and the changelog wasn't updated to match that. Fixed the changelog now.

 drivers/rtc/interface.c  | 2 +-
 drivers/rtc/rtc-bfin.c   | 2 +-
 drivers/rtc/rtc-gemini.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/rtc/interface.c +1 -1
index 11b639067312..5836751b8203 100644
@@ -564,7 +564,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
 void rtc_update_irq(struct rtc_device *rtc,
 		unsigned long num, unsigned long events)
 {
-	if (unlikely(IS_ERR_OR_NULL(rtc)))
+	if (IS_ERR_OR_NULL(rtc))
 		return;
 
 	pm_stay_awake(rtc->dev.parent);
drivers/rtc/rtc-bfin.c +1 -1
index 3d44b11721ea..535a5f9338d0 100644
@@ -361,7 +361,7 @@ static int bfin_rtc_probe(struct platform_device *pdev)
 	/* Register our RTC with the RTC framework */
 	rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
 						THIS_MODULE);
-	if (unlikely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	/* Grab the IRQ and init the hardware */
drivers/rtc/rtc-gemini.c +1 -1
index 35f4486738fc..2fed93e1114a 100644
@@ -148,7 +148,7 @@ static int gemini_rtc_probe(struct platform_device *pdev)
 
 	rtc->rtc_dev = rtc_device_register(pdev->name, dev,
 					   &gemini_rtc_ops, THIS_MODULE);
-	if (likely(IS_ERR(rtc->rtc_dev)))
+	if (IS_ERR(rtc->rtc_dev))
 		return PTR_ERR(rtc->rtc_dev);
 
 	return 0;
Signature · 1 line
2.4.0

For the mach-gemini part

#25 lore raw

Re: [PATCH 9/15 V2] drivers: rtc: Drop (un)likely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar
Quoted 14 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

gemini driver was using likely() for a failure case while the rtc driver is getting registered. That looks wrong and it should really be unlikely. But because we are killing all the unlikely() flags, lets kill that too.

---
V1->V2:
- Removed the likely() part from gemini driver and the changelog wasn't updated to match that. Fixed the changelog now.

Quoted 5 lines
 drivers/rtc/interface.c  | 2 +-
 drivers/rtc/rtc-bfin.c   | 2 +-
 drivers/rtc/rtc-gemini.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#26 lore raw

PATCH 10/15 drivers: staging: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

This also replaces an IS_ERR(x) + (x == NULL) check to IS_ERR_OR_NULL check.

---
 drivers/staging/android/ashmem.c                     | 2 +-
 drivers/staging/lustre/include/linux/libcfs/libcfs.h | 2 +-
 drivers/staging/lustre/lustre/obdclass/lu_object.c   | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/android/ashmem.c +1 -1
index c5c037ccf32c..9db321c63e79 100644
@@ -388,7 +388,7 @@ static int ashmem_mmap(struct file *file, struct vm_area_struct *vma)
 
 		/* ... and allocate the backing shmem file */
 		vmfile = shmem_file_setup(name, asma->size, vma->vm_flags);
-		if (unlikely(IS_ERR(vmfile))) {
+		if (IS_ERR(vmfile)) {
 			ret = PTR_ERR(vmfile);
 			goto out;
 		}
drivers/staging/lustre/include/linux/libcfs/libcfs.h +1 -1
index 5dd9cdfae30c..d585041041c7 100644
@@ -134,7 +134,7 @@ void cfs_get_random_bytes(void *buf, int size);
 /* container_of depends on "likely" which is defined in libcfs_private.h */
 static inline void *__container_of(void *ptr, unsigned long shift)
 {
-	if (unlikely(IS_ERR(ptr) || ptr == NULL))
+	if (IS_ERR_OR_NULL(ptr))
 		return ptr;
 	return (char *)ptr - shift;
 }
drivers/staging/lustre/lustre/obdclass/lu_object.c +3 -3
index 4d9b6333eeae..6cd3af8c6237 100644
@@ -602,7 +602,7 @@ static struct lu_object *lu_object_new(const struct lu_env *env,
 	struct lu_site_bkt_data *bkt;
 
 	o = lu_object_alloc(env, dev, f, conf);
-	if (unlikely(IS_ERR(o)))
+	if (IS_ERR(o))
 		return o;
 
 	hs = dev->ld_site->ls_obj_hash;
@@ -666,7 +666,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env,
 	 * operations, including fld queries, inode loading, etc.
 	 */
 	o = lu_object_alloc(env, dev, f, conf);
-	if (unlikely(IS_ERR(o)))
+	if (IS_ERR(o))
 		return o;
 
 	LASSERT(lu_fid_eq(lu_object_fid(o), f));
@@ -1558,7 +1558,7 @@ static int keys_fill(struct lu_context *ctx)
 			LINVRNT(key->lct_index == i);
 
 			value = key->lct_init(ctx, key);
-			if (unlikely(IS_ERR(value)))
+			if (IS_ERR(value))
 				return PTR_ERR(value);
 
 			if (!(ctx->lc_tags & LCT_NOREF))
Signature · 1 line
2.4.0
#27 lore raw

PATCH 11/15 drivers: target: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/target/tcm_fc/tfc_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/tcm_fc/tfc_cmd.c +1 -1
index 68031723e5be..aa3caca8bace 100644
@@ -255,7 +255,7 @@ static void ft_recv_seq(struct fc_seq *sp, struct fc_frame *fp, void *arg)
 	struct ft_cmd *cmd = arg;
 	struct fc_frame_header *fh;
 
-	if (unlikely(IS_ERR(fp))) {
+	if (IS_ERR(fp)) {
 		/* XXX need to find cmd if queued */
 		cmd->seq = NULL;
 		cmd->aborted = true;
Signature · 1 line
2.4.0
#28 lore raw

Re: [PATCH 11/15] drivers: target: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 13 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 drivers/target/tcm_fc/tfc_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/tcm_fc/tfc_cmd.c +0 -0
index 68031723e5be..aa3caca8bace 100644

drivers/target/tcm_fc/tfc_cmd.c static void ft_recv_seq(struct fc_seq *sp, struct fc_frame *fp, void *arg) · line 261

Quoted 8 lines
drivers/target/tcm_fc/tfc_cmd.c +1 -1
@@ -255,7 +255,7 @@ static void ft_recv_seq(struct fc_seq *sp, struct fc_frame *fp, void *arg)
 	struct ft_cmd *cmd = arg;
 	struct fc_frame_header *fh;
 
-	if (unlikely(IS_ERR(fp))) {
+	if (IS_ERR(fp)) {
 		/* XXX need to find cmd if queued */
 		cmd->seq = NULL;
 		cmd->aborted = true;

Looks fine. Applied to target-pending/for-next.

Thanks Viresh!

#29 lore raw

PATCH 12/15 fs: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 fs/cifs/readdir.c            | 2 +-
 fs/ecryptfs/inode.c          | 2 +-
 fs/ext4/extents.c            | 6 +++---
 fs/ext4/namei.c              | 2 +-
 fs/namei.c                   | 4 ++--
 fs/ncpfs/dir.c               | 2 +-
 fs/nfs/objlayout/objio_osd.c | 2 +-
 fs/proc/proc_sysctl.c        | 2 +-
 8 files changed, 11 insertions(+), 11 deletions(-)
fs/cifs/readdir.c +1 -1
index b1eede3678a9..0557c45e9c33 100644
@@ -84,7 +84,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
 	cifs_dbg(FYI, "%s: for %s\n", __func__, name->name);
 
 	dentry = d_hash_and_lookup(parent, name);
-	if (unlikely(IS_ERR(dentry)))
+	if (IS_ERR(dentry))
 		return;
 
 	if (dentry) {
fs/ecryptfs/inode.c +1 -1
index 3c4db1172d22..e2e47ba5d313 100644
@@ -270,7 +270,7 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
 
 	ecryptfs_inode = ecryptfs_do_create(directory_inode, ecryptfs_dentry,
 					    mode);
-	if (unlikely(IS_ERR(ecryptfs_inode))) {
+	if (IS_ERR(ecryptfs_inode)) {
 		ecryptfs_printk(KERN_WARNING, "Failed to create file in"
 				"lower filesystem\n");
 		rc = PTR_ERR(ecryptfs_inode);
fs/ext4/extents.c +3 -3
index 2553aa8b608d..799f01714767 100644
@@ -899,7 +899,7 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
 
 		bh = read_extent_tree_block(inode, path[ppos].p_block, --i,
 					    flags);
-		if (unlikely(IS_ERR(bh))) {
+		if (IS_ERR(bh)) {
 			ret = PTR_ERR(bh);
 			goto err;
 		}
@@ -5792,7 +5792,7 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1,
 		int split = 0;
 
 		path1 = ext4_find_extent(inode1, lblk1, NULL, EXT4_EX_NOCACHE);
-		if (unlikely(IS_ERR(path1))) {
+		if (IS_ERR(path1)) {
 			*erp = PTR_ERR(path1);
 			path1 = NULL;
 		finish:
@@ -5800,7 +5800,7 @@ ext4_swap_extents(handle_t *handle, struct inode *inode1,
 			goto repeat;
 		}
 		path2 = ext4_find_extent(inode2, lblk2, NULL, EXT4_EX_NOCACHE);
-		if (unlikely(IS_ERR(path2))) {
+		if (IS_ERR(path2)) {
 			*erp = PTR_ERR(path2);
 			path2 = NULL;
 			goto finish;
fs/ext4/namei.c +1 -1
index 011dcfb5cce3..0554e4be1fb8 100644
@@ -1429,7 +1429,7 @@ static struct buffer_head * ext4_find_entry (struct inode *dir,
 				}
 				num++;
 				bh = ext4_getblk(NULL, dir, b++, 0);
-				if (unlikely(IS_ERR(bh))) {
+				if (IS_ERR(bh)) {
 					if (ra_max == 0) {
 						ret = bh;
 						goto cleanup_and_exit;
fs/namei.c +2 -2
index ae4e4c18b2ac..04fdec230c45 100644
@@ -1942,7 +1942,7 @@ static int link_path_walk(const char *name, struct nameidata *nd)
 		if (err) {
 			const char *s = get_link(nd);
 
-			if (unlikely(IS_ERR(s)))
+			if (IS_ERR(s))
 				return PTR_ERR(s);
 			err = 0;
 			if (unlikely(!s)) {
@@ -3351,7 +3351,7 @@ struct file *do_file_open_root(struct dentry *dentry, struct vfsmount *mnt,
 		return ERR_PTR(-ELOOP);
 
 	filename = getname_kernel(name);
-	if (unlikely(IS_ERR(filename)))
+	if (IS_ERR(filename))
 		return ERR_CAST(filename);
 
 	set_nameidata(&nd, -1, filename);
fs/ncpfs/dir.c +1 -1
index 93575e91a7aa..356816e7bc90 100644
@@ -597,7 +597,7 @@ ncp_fill_cache(struct file *file, struct dir_context *ctx,
 	qname.name = __name;
 
 	newdent = d_hash_and_lookup(dentry, &qname);
-	if (unlikely(IS_ERR(newdent)))
+	if (IS_ERR(newdent))
 		goto end_advance;
 	if (!newdent) {
 		newdent = d_alloc(dentry, &qname);
fs/nfs/objlayout/objio_osd.c +1 -1
index 5aaed363556a..5c0c6b58157f 100644
@@ -124,7 +124,7 @@ objio_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
 
 retry_lookup:
 	od = osduld_info_lookup(&odi);
-	if (unlikely(IS_ERR(od))) {
+	if (IS_ERR(od)) {
 		err = PTR_ERR(od);
 		dprintk("%s: osduld_info_lookup => %d\n", __func__, err);
 		if (err == -ENODEV && retry_flag) {
fs/proc/proc_sysctl.c +1 -1
index fdda62e6115e..fe5b6e6c4671 100644
@@ -948,7 +948,7 @@ static struct ctl_dir *get_subdir(struct ctl_dir *dir,
 found:
 	subdir->header.nreg++;
 failed:
-	if (unlikely(IS_ERR(subdir))) {
+	if (IS_ERR(subdir)) {
 		pr_err("sysctl could not get directory: ");
 		sysctl_print_dir(dir);
 		pr_cont("/%*.*s %ld\n",
Signature · 1 line
2.4.0
#31 lore raw

PATCH 13/15 blk-cgroup: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 include/linux/blk-cgroup.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blk-cgroup.h +1 -1
index 1b62d768c7df..a4cd1641e9e2 100644
@@ -374,7 +374,7 @@ static inline struct request_list *blk_get_rl(struct request_queue *q,
 	 * root_rl in such cases.
 	 */
 	blkg = blkg_lookup_create(blkcg, q);
-	if (unlikely(IS_ERR(blkg)))
+	if (IS_ERR(blkg))
 		goto root_rl;
 
 	blkg_get(blkg);
Signature · 1 line
2.4.0
maintainer Acked-by on v1 13/15
#32 lore raw

Re: [PATCH 13/15] blk-cgroup: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 4 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

Thanks.

Signature · 1 line
tejun
#33 lore raw

PATCH 14/15 mm: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 mm/huge_memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/huge_memory.c +1 -1
index c107094f79ba..e14652480c59 100644
@@ -149,7 +149,7 @@ static int start_stop_khugepaged(void)
 		if (!khugepaged_thread)
 			khugepaged_thread = kthread_run(khugepaged, NULL,
 							"khugepaged");
-		if (unlikely(IS_ERR(khugepaged_thread))) {
+		if (IS_ERR(khugepaged_thread)) {
 			pr_err("khugepaged: kthread_run(khugepaged) failed\n");
 			err = PTR_ERR(khugepaged_thread);
 			khugepaged_thread = NULL;
Signature · 7 lines
2.4.0

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 14/15
#34 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 4 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

Signature · 7 lines
 Kirill A. Shutemov

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#35 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 18 lines · Kirill A. Shutemov
Quoted 4 lines · Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

Signature · 6 lines
Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

search in code, there are lots of using like this , does need add this check into checkpatch ?

# grep -r 'likely.*IS_ERR'  .
./include/linux/blk-cgroup.h:	if (unlikely(IS_ERR(blkg)))
./fs/nfs/objlayout/objio_osd.c:	if (unlikely(IS_ERR(od))) {
./fs/cifs/readdir.c:	if (unlikely(IS_ERR(dentry)))
./fs/ext4/extents.c:		if (unlikely(IS_ERR(bh))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path1))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path2))) {
./fs/ext4/namei.c:				if (unlikely(IS_ERR(bh))) {
./fs/ntfs/lcnalloc.c:	if (likely(page && !IS_ERR(page))) {
./fs/ntfs/runlist.c:	if (likely(!IS_ERR(old_rl)))
./fs/ntfs/mft.c:	if (likely(!IS_ERR(page))) {
./fs/ntfs/mft.c:	if (likely(!IS_ERR(m)))
./fs/ntfs/mft.c:		if (likely(!IS_ERR(m))) {
./fs/ntfs/mft.c:	if (unlikely(IS_ERR(rl) || !rl->length || rl->lcn < 0)) {
./fs/ntfs/mft.c:	if (unlikely(IS_ERR(rl) || !rl->length || rl->lcn < 0)) {
./fs/ntfs/mft.c:		if (likely(!IS_ERR(rl2)))
./fs/ntfs/inode.c:	if (unlikely(err || IS_ERR(m))) {
./fs/ntfs/namei.c:		if (likely(!IS_ERR(dent_inode))) {
./fs/ntfs/super.c:	if (unlikely(IS_ERR(tmp_ino) || is_bad_inode(tmp_ino))) {
./fs/namei.c:			if (unlikely(IS_ERR(s)))
./fs/namei.c:	if (unlikely(IS_ERR(filename)))
./fs/gfs2/dir.c:	if (unlikely(dent == NULL || IS_ERR(dent))) {
./fs/ecryptfs/inode.c:	if (unlikely(IS_ERR(ecryptfs_inode))) {
./fs/ncpfs/dir.c:	if (unlikely(IS_ERR(newdent)))
./fs/proc/proc_sysctl.c:	if (unlikely(IS_ERR(subdir))) {
Binary file ./.git/objects/pack/pack-4a5df920db8b8d9df9a91893c9567b4b2f15b782.pack matches
./drivers/target/tcm_fc/tfc_cmd.c:	if (unlikely(IS_ERR(fp))) {
./drivers/thermal/intel_powerclamp.c:		if (likely(!IS_ERR(thread))) {
./drivers/thermal/intel_powerclamp.c:		if (likely(!IS_ERR(thread))) {
./drivers/gpu/drm/vmwgfx/vmwgfx_drv.c:	if (unlikely(IS_ERR(vmaster))) {
./drivers/gpu/drm/vmwgfx/vmwgfx_context.c:		if (unlikely(IS_ERR(uctx->man))) {
./drivers/gpu/drm/ttm/ttm_tt.c:		if (unlikely(IS_ERR(swap_storage))) {
./drivers/gpu/drm/ttm/ttm_tt.c:		if (unlikely(IS_ERR(to_page))) {
./drivers/scsi/bnx2fc/bnx2fc_fcoe.c:	if (likely(!IS_ERR(thread))) {
./drivers/scsi/bnx2i/bnx2i_init.c:	if (likely(!IS_ERR(thread))) {
./drivers/scsi/fcoe/fcoe.c:	if (likely(!IS_ERR(thread))) {
./drivers/base/power/opp.c:	if (unlikely(IS_ERR_OR_NULL(dev))) {
./drivers/base/power/opp.c:	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
./drivers/base/power/opp.c:	if (unlikely(IS_ERR_OR_NULL(tmp_opp)) || !tmp_opp->available)
./drivers/tty/serial/serial_core.c:	if (likely(!IS_ERR(tty_dev))) {
./drivers/rtc/rtc-bfin.c:	if (unlikely(IS_ERR(rtc->rtc_dev)))
./drivers/rtc/rtc-gemini.c:	if (likely(IS_ERR(rtc->rtc_dev)))
./drivers/rtc/interface.c:	if (unlikely(IS_ERR_OR_NULL(rtc)))
./drivers/md/dm-snap-persistent.c:		if (unlikely(IS_ERR(area))) {
./drivers/md/dm-verity.c:	if (unlikely(IS_ERR(data)))
./drivers/md/persistent-data/dm-block-manager.c:	if (unlikely(IS_ERR(p)))
./drivers/md/persistent-data/dm-block-manager.c:	if (unlikely(IS_ERR(p)))
./drivers/md/persistent-data/dm-block-manager.c:	if (unlikely(IS_ERR(p)))
./drivers/md/persistent-data/dm-block-manager.c:	if (unlikely(IS_ERR(p)))
./drivers/staging/lustre/include/linux/libcfs/libcfs.h:	if (unlikely(IS_ERR(ptr) || ptr == NULL))
./drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c:		if (likely(!IS_ERR(pfmr))) {
./drivers/staging/lustre/lustre/obdclass/lu_object.c:	if (unlikely(IS_ERR(o)))
./drivers/staging/lustre/lustre/obdclass/lu_object.c:	if (unlikely(IS_ERR(o)))
./drivers/staging/lustre/lustre/obdclass/lu_object.c:	if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {
./drivers/staging/lustre/lustre/obdclass/lu_object.c:			if (unlikely(IS_ERR(value)))
./drivers/staging/android/ashmem.c:		if (unlikely(IS_ERR(vmfile))) {
./drivers/input/mouse/alps.c:	} else if (unlikely(IS_ERR_OR_NULL(priv->dev3))) {
./drivers/net/ethernet/marvell/sky2.c:	if (unlikely(status & Y2_IS_ERROR))
./drivers/net/ethernet/ti/netcp_core.c:	if (unlikely(IS_ERR_OR_NULL(desc))) {
./drivers/net/ethernet/ti/netcp_core.c:		if (unlikely(IS_ERR_OR_NULL(ndesc))) {
./drivers/devfreq/devfreq.c:	if (unlikely(IS_ERR_OR_NULL(dev))) {
./drivers/devfreq/devfreq.c:	if (unlikely(IS_ERR_OR_NULL(name))) {
./drivers/misc/c2port/core.c:	if (unlikely(IS_ERR(c2dev->dev))) {
./net/socket.c:	if (unlikely(IS_ERR(file))) {
./net/socket.c:	if (likely(!IS_ERR(newfile))) {
./net/socket.c:	if (unlikely(IS_ERR(newfile1))) {
./net/socket.c:	if (unlikely(IS_ERR(newfile))) {
./net/openvswitch/datapath.c:		if (unlikely(IS_ERR(reply))) {
./net/openvswitch/datapath.c:		if (likely(!IS_ERR(reply))) {
./net/sctp/socket.c:	if (unlikely(IS_ERR(newfile))) {
./mm/huge_memory.c:		if (unlikely(IS_ERR(khugepaged_thread))) {

Thanks

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#36 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 4 lines · yalin wang
Quoted 4 lines · Kirill A. Shutemov

On Fri, Jul 31, 2015 at 02:08:34PM +0530, Viresh Kumar wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

search in code, there are lots of using like this , does need add this check into checkpatch ?

cc'd Joe for that. :)

Quoted 7 lines
# grep -r 'likely.*IS_ERR'  .
./include/linux/blk-cgroup.h:	if (unlikely(IS_ERR(blkg)))
./fs/nfs/objlayout/objio_osd.c:	if (unlikely(IS_ERR(od))) {
./fs/cifs/readdir.c:	if (unlikely(IS_ERR(dentry)))
./fs/ext4/extents.c:		if (unlikely(IS_ERR(bh))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path1))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path2))) {

Btw, my series has fixed all of them :)

Signature · 7 lines
viresh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#37 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 24 lines · Viresh Kumar
Quoted 4 lines · yalin wang
Quoted 4 lines · Kirill A. Shutemov

On Fri, Jul 31, 2015 at 02:08:34PM +0530, Viresh Kumar wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

search in code, there are lots of using like this , does need add this check into checkpatch ?

cc'd Joe for that. :)

Quoted 7 lines
# grep -r 'likely.*IS_ERR'  .
./include/linux/blk-cgroup.h:	if (unlikely(IS_ERR(blkg)))
./fs/nfs/objlayout/objio_osd.c:	if (unlikely(IS_ERR(od))) {
./fs/cifs/readdir.c:	if (unlikely(IS_ERR(dentry)))
./fs/ext4/extents.c:		if (unlikely(IS_ERR(bh))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path1))) {
./fs/ext4/extents.c:		if (unlikely(IS_ERR(path2))) {
Quoted 1 line

Btw, my series has fixed all of them :)

If it's all fixed, then it's unlikely to be needed in checkpatch.

But given the unlikely was added when using gcc3.4, I wonder if it's still appropriate to use unlikely in IS_ERR at all.

---

commit b5acea523151452c37cd428437e7576a291dd146

Author: Andrew Morton <[email protected]>
Date:   Sun Aug 22 23:04:49 2004 -0700

[PATCH] mark IS_ERR as unlikely()

It seems fair to assume that it is always unlikely that IS_ERR will return true.

This patch changes the gcc-3.4-generated kernel text by ~500 bytes (less) so it's fair to assume that the compiler is indeed propagating unlikeliness out of inline functions.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#38 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 1 line · Joe Perches

If it's all fixed, then it's unlikely to be needed in checkpatch.

I thought checkpatch is more about not committing new mistakes, rather than finding them in old code.

Signature · 7 lines
viresh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#39 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 5 lines · Viresh Kumar
Quoted 1 line · Joe Perches

If it's all fixed, then it's unlikely to be needed in checkpatch.

I thought checkpatch is more about not committing new mistakes, rather than finding them in old code.

True, but checkpatch is more about style than substance.

There are a lot of things that _could_ be added to the script but don't have to be because of relative rarity.

The unanswered fundamental though is whether the unlikely use in #define IS_ERR_VALUE is useful.

include/linux/err.h:21:#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)

How often does using unlikely here make the code smaller/faster with more recent compilers than gcc 3.4? Or even using gcc 3.4.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#40 lore raw

Re: [PATCH 14/15] mm: Drop unlikely before IS_ERR(_OR_NULL)

Quoted 12 lines · Joe Perches
Quoted 5 lines · Viresh Kumar
Quoted 1 line · Joe Perches

If it's all fixed, then it's unlikely to be needed in checkpatch.

I thought checkpatch is more about not committing new mistakes, rather than finding them in old code.

True, but checkpatch is more about style than substance.

There are a lot of things that _could_ be added to the script but don't have to be because of relative rarity.

Quoted 7 lines

The unanswered fundamental though is whether the unlikely use in #define IS_ERR_VALUE is useful.

include/linux/err.h:21:#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)

How often does using unlikely here make the code smaller/faster with more recent compilers than gcc 3.4? Or even using gcc 3.4.

No idea :)

Signature · 7 lines
viresh

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#41 lore raw

PATCH 15/15 net: Drop unlikely before IS_ERR(_OR_NULL)

In reply to Viresh Kumar

IS_ERR(_OR_NULL) already contain an 'unlikely' compiler flag and there is no need to do that again from its callers. Drop it.

---
 net/openvswitch/datapath.c | 2 +-
 net/sctp/socket.c          | 2 +-
 net/socket.c               | 6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
net/openvswitch/datapath.c +1 -1
index ff8c4a4c1609..01d69680ba5d 100644
@@ -1143,7 +1143,7 @@ static int ovs_flow_cmd_set(struct sk_buff *skb, struct genl_info *info)
 						info, OVS_FLOW_CMD_NEW, false,
 						ufid_flags);
 
-		if (unlikely(IS_ERR(reply))) {
+		if (IS_ERR(reply)) {
 			error = PTR_ERR(reply);
 			goto err_unlock_ovs;
 		}
net/sctp/socket.c +1 -1
index 1425ec2bbd5a..c1569432235e 100644
@@ -4481,7 +4481,7 @@ static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval
 	}
 
 	newfile = sock_alloc_file(newsock, 0, NULL);
-	if (unlikely(IS_ERR(newfile))) {
+	if (IS_ERR(newfile)) {
 		put_unused_fd(retval);
 		sock_release(newsock);
 		return PTR_ERR(newfile);
net/socket.c +3 -3
index 9963a0b53a64..dd2c247c99e3 100644
@@ -373,7 +373,7 @@ struct file *sock_alloc_file(struct socket *sock, int flags, const char *dname)
 
 	file = alloc_file(&path, FMODE_READ | FMODE_WRITE,
 		  &socket_file_ops);
-	if (unlikely(IS_ERR(file))) {
+	if (IS_ERR(file)) {
 		/* drop dentry, keep inode */
 		ihold(d_inode(path.dentry));
 		path_put(&path);
@@ -1303,7 +1303,7 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
 	}
 
 	newfile1 = sock_alloc_file(sock1, flags, NULL);
-	if (unlikely(IS_ERR(newfile1))) {
+	if (IS_ERR(newfile1)) {
 		err = PTR_ERR(newfile1);
 		goto out_put_unused_both;
 	}
@@ -1467,7 +1467,7 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
 		goto out_put;
 	}
 	newfile = sock_alloc_file(newsock, flags, sock->sk->sk_prot_creator->name);
-	if (unlikely(IS_ERR(newfile))) {
+	if (IS_ERR(newfile)) {
 		err = PTR_ERR(newfile);
 		put_unused_fd(newfd);
 		sock_release(newsock);
Signature · 6 lines
2.4.0

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
#42 lore raw
In reply to Viresh Kumar
Quoted 5 lines · Viresh Kumar

Hi,

This cleans up the usage of IS_ERR(_OR_NULL)(), where the callers have added additional unlikely compiler flag to them. It also fixes the definition of IS_ERR_OR_NULL(), to use unlikely for all checks it does.

[+CC Steven Rostedt]

Any idea what the compiler does in the case of
"if (likely(IS_ERR(...)))"? There are apparently such cases in the source.

does the "likely" somehow override the "unlikely" of IS_ERR, or is the resulting code a mess?

Vlastimil

Quoted 51 lines

Viresh Kumar (15):
err.h: add (missing) unlikely() to IS_ERR_OR_NULL() PM / OPP: Drop unlikely before IS_ERR(_OR_NULL)
drivers: devfreq: Drop unlikely before IS_ERR(_OR_NULL)
drivers: gpu: Drop unlikely before IS_ERR(_OR_NULL)
drivers: input: Drop unlikely before IS_ERR(_OR_NULL)
drivers: md: Drop unlikely before IS_ERR(_OR_NULL)
drivers: misc: Drop unlikely before IS_ERR(_OR_NULL)
drivers: net: Drop unlikely before IS_ERR(_OR_NULL)
drivers: rtc: Drop unlikely before IS_ERR(_OR_NULL)
drivers: staging: Drop unlikely before IS_ERR(_OR_NULL)
drivers: target: Drop unlikely before IS_ERR(_OR_NULL)
fs: Drop unlikely before IS_ERR(_OR_NULL)
blk-cgroup: Drop unlikely before IS_ERR(_OR_NULL)
mm: Drop unlikely before IS_ERR(_OR_NULL)
net: Drop unlikely before IS_ERR(_OR_NULL)

  drivers/base/power/opp.c                             | 6 +++---
  drivers/devfreq/devfreq.c                            | 4 ++--
  drivers/gpu/drm/ttm/ttm_tt.c                         | 4 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_context.c              | 2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c                  | 2 +-
  drivers/input/mouse/alps.c                           | 2 +-
  drivers/md/dm-snap-persistent.c                      | 2 +-
  drivers/md/dm-verity.c                               | 2 +-
  drivers/md/persistent-data/dm-block-manager.c        | 8 ++++----
  drivers/misc/c2port/core.c                           | 2 +-
  drivers/net/ethernet/ti/netcp_core.c                 | 4 ++--
  drivers/rtc/interface.c                              | 2 +-
  drivers/rtc/rtc-bfin.c                               | 2 +-
  drivers/rtc/rtc-gemini.c                             | 2 +-
  drivers/staging/android/ashmem.c                     | 2 +-
  drivers/staging/lustre/include/linux/libcfs/libcfs.h | 2 +-
  drivers/staging/lustre/lustre/obdclass/lu_object.c   | 6 +++---
  drivers/target/tcm_fc/tfc_cmd.c                      | 2 +-
  fs/cifs/readdir.c                                    | 2 +-
  fs/ecryptfs/inode.c                                  | 2 +-
  fs/ext4/extents.c                                    | 6 +++---
  fs/ext4/namei.c                                      | 2 +-
  fs/namei.c                                           | 4 ++--
  fs/ncpfs/dir.c                                       | 2 +-
  fs/nfs/objlayout/objio_osd.c                         | 2 +-
  fs/proc/proc_sysctl.c                                | 2 +-
  include/linux/blk-cgroup.h                           | 2 +-
  include/linux/err.h                                  | 2 +-
  mm/huge_memory.c                                     | 2 +-
  net/openvswitch/datapath.c                           | 2 +-
  net/sctp/socket.c                                    | 2 +-
  net/socket.c                                         | 6 +++---
  32 files changed, 47 insertions(+), 47 deletions(-)
#43 lore raw
Quoted 7 lines · Vlastimil Babka

[+CC Steven Rostedt]

Any idea what the compiler does in the case of
"if (likely(IS_ERR(...)))"? There are apparently such cases in the source.

does the "likely" somehow override the "unlikely" of IS_ERR, or is the resulting code a mess?

Good point. While fixing all the sites, I saw some code like that. Then before posting the series, I tried to look at what compilers do to such codes and they generated exactly same code for:

likely(unlikely(x)) and unlikely(x).

So, either those call sites should drop the likely bits or we supply them with another raw version of the macro :)

Or if my tests were wrong, then please lemme know.

Signature · 1 line
viresh
#44 lore raw
In reply to Vlastimil Babka
Quoted 11 lines · Vlastimil Babka
Quoted 5 lines · Viresh Kumar

Hi,

This cleans up the usage of IS_ERR(_OR_NULL)(), where the callers have added additional unlikely compiler flag to them. It also fixes the definition of IS_ERR_OR_NULL(), to use unlikely for all checks it does.

[+CC Steven Rostedt]

Any idea what the compiler does in the case of
"if (likely(IS_ERR(...)))"? There are apparently such cases in the source.

We have two cases in code:

drivers/rtc/rtc-gemini.c: if (likely(IS_ERR(rtc->rtc_dev)))
drivers/staging/lustre/lustre/obdclass/lu_object.c: if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {

The first one is mistake, I think. Or do we expect rtc_device_register() to fail?

The second is redundant. "if (PTR_ERR(shadow) == -ENOENT)" should do the job.

Signature · 1 line
 Kirill A. Shutemov
#45 lore raw

PATCH 1/1 staging: lustre: drop redundant check

There is no need to verify that its an error, as we are anyway going to match the error value to -ENOENT. Drop the redundant check.

---
 drivers/staging/lustre/lustre/obdclass/lu_object.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/lustre/obdclass/lu_object.c +1 -1
index 6cd3af8c6237..8e472327c880 100644
@@ -674,7 +674,7 @@ static struct lu_object *lu_object_find_try(const struct lu_env *env,
 	cfs_hash_bd_lock(hs, &bd, 1);
 
 	shadow = htable_lookup(s, &bd, f, waiter, &version);
-	if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {
+	if (likely(PTR_ERR(shadow) == -ENOENT)) {
 		struct lu_site_bkt_data *bkt;
 
 		bkt = cfs_hash_bd_extra_get(hs, &bd);
Signature · 1 line
2.4.0
#46 lore raw
In reply to Kirill A. Shutemov
Quoted 8 lines · Kirill A. Shutemov
Quoted 7 lines · Vlastimil Babka
Quoted 5 lines · Viresh Kumar

Hi,

This cleans up the usage of IS_ERR(_OR_NULL)(), where the callers have added additional unlikely compiler flag to them. It also fixes the definition of IS_ERR_OR_NULL(), to use unlikely for all checks it does.

Quoted 8 lines
Quoted 4 lines

[+CC Steven Rostedt]

Any idea what the compiler does in the case of
"if (likely(IS_ERR(...)))"? There are apparently such cases in the source.

We have two cases in code:

drivers/rtc/rtc-gemini.c: if (likely(IS_ERR(rtc->rtc_dev)))

This one is already fixed in my series (sent a v2 to fix changelog as well)

Quoted 1 line

drivers/staging/lustre/lustre/obdclass/lu_object.c: if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {

And I have sent a patch for this (in reply the your mail).

Signature · 1 line
viresh
#47 lore raw
In reply to Kirill A. Shutemov
Quoted 15 lines · On Fri, 31 Jul 2015 13:23:10 +0300 "Kirill A. Shutemov" <[email protected]>…
Quoted 11 lines · Vlastimil Babka
Quoted 5 lines · Viresh Kumar

Hi,

This cleans up the usage of IS_ERR(_OR_NULL)(), where the callers have added additional unlikely compiler flag to them. It also fixes the definition of IS_ERR_OR_NULL(), to use unlikely for all checks it does.

[+CC Steven Rostedt]

Any idea what the compiler does in the case of
"if (likely(IS_ERR(...)))"? There are apparently such cases in the source.

We have two cases in code:

Quoted 9 lines

drivers/rtc/rtc-gemini.c: if (likely(IS_ERR(rtc->rtc_dev)))
drivers/staging/lustre/lustre/obdclass/lu_object.c: if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {

The first one is mistake, I think. Or do we expect rtc_device_register() to fail?

The second is redundant. "if (PTR_ERR(shadow) == -ENOENT)" should do the job.

Yep, those look like bugs to me.

-- Steve

#48 lore raw
Quoted 7 lines · Steven Rostedt
Quoted 5 lines · On Fri, 31 Jul 2015 13:23:10 +0300 "Kirill A. Shutemov" <[email protected]>…

We have two cases in code:

drivers/rtc/rtc-gemini.c: if (likely(IS_ERR(rtc->rtc_dev)))
drivers/staging/lustre/lustre/obdclass/lu_object.c: if (likely(IS_ERR(shadow) && PTR_ERR(shadow) == -ENOENT)) {

Quoted 8 lines
Quoted 6 lines

The first one is mistake, I think. Or do we expect rtc_device_register() to fail?

The second is redundant. "if (PTR_ERR(shadow) == -ENOENT)" should do the job.

Yep, those look like bugs to me.

Yeah, I have fixed both of them :)

Signature · 1 line
viresh