Skip to contentSkip to conversation

infiniband: nes: add unlikely() to assert()

PATCH In review Igor Stoppa 9 participants 35 messages Aug 30, 2018 – Sep 2, 2018 1 message not in the archive

Subsystems (27)
lore
Share & tools
lore
#1 lore raw

PATCH 1/23 infiniband: nes: add unlikely() to assert()

In reply to a message not in the archive

Typically the assert is expected to not fail.

Cc Chien Tung <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Faisal Latif <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Jason Gunthorpe <[email protected]>
---
 drivers/infiniband/hw/nes/nes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/nes/nes.h +1 -1
index bedaa02749fb..d2d0098f38e0 100644
@@ -151,7 +151,7 @@ do { \
 
 #define assert(expr) \
 do { \
-	if (!(expr)) { \
+	if (unlikely(!(expr))) { \
 		printk(KERN_ERR PFX "Assertion failed! %s, %s, %s, line %d\n", \
 			   #expr, __FILE__, __func__, __LINE__); \
 	} \
Signature · 1 line
2.17.1
#3 lore raw

PATCH 2/23 ethernet: hnae: add unlikely() to assert()

In reply to a message not in the archive

The assert() condition is likely to be true.

Cc huangdaode <[email protected]>
Cc Yisen Zhuang <[email protected]>
Cc Salil Mehta <[email protected]>
---
 drivers/net/ethernet/hisilicon/hns/hnae.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/hisilicon/hns/hnae.h +1 -1
index cad52bd331f7..431a3cf8cd2f 100644
@@ -47,7 +47,7 @@
 #ifndef assert
 #define assert(expr) \
 do { \
-	if (!(expr)) { \
+	if (unlikely(!(expr))) { \
 		pr_err("Assertion failed! %s, %s, %s, line %d\n", \
 			   #expr, __FILE__, __func__, __LINE__); \
 	} \
Signature · 1 line
2.17.1
#4 lore raw

PATCH 3/23 asm-generic: bug: add unlikely() to BUG_ON()

In reply to a message not in the archive

Add a hint to the compiler.
If BUG_ON() is used instead of BUG(), it means that probably the preferred outcome is to not BUG().

---
 include/asm-generic/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/bug.h +1 -1
index 20561a60db9c..34c48444c942 100644
@@ -183,7 +183,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint,
 #endif
 
 #ifndef HAVE_ARCH_BUG_ON
-#define BUG_ON(condition) do { if (condition) BUG(); } while (0)
+#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)
 #endif
 
 #ifndef HAVE_ARCH_WARN_ON
Signature · 1 line
2.17.1
#5 lore raw

PATCH 4/23 mips: bug: add unlikely() to BUG_ON()

In reply to a message not in the archive

Add a hint to the compiler that probably it won't be necessary to BUG()

Cc David Daney <[email protected]>
Cc Ralf Baechle <[email protected]>
Cc Paul Burton <[email protected]>
Cc James Hogan <[email protected]>
---
 arch/mips/include/asm/bug.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/include/asm/bug.h +1 -1
index 745dc160a069..02101b54aec2 100644
@@ -31,7 +31,7 @@ static inline void  __BUG_ON(unsigned long condition)
 			     : : "r" (condition), "i" (BRK_BUG));
 }
 
-#define BUG_ON(C) __BUG_ON((unsigned long)(C))
+#define BUG_ON(C) __BUG_ON(unlikely((unsigned long)(C)))
 
 #define HAVE_ARCH_BUG_ON
 
Signature · 1 line
2.17.1
#6 lore raw

PATCH 5/23 selftest: vm: add unlikely() to BUG_ON()

In reply to a message not in the archive

BUG_ON() is unlikely() to BUG()

Cc Dmitry Safonov <[email protected]>
Cc Shuah Khan <[email protected]>
---
 tools/testing/selftests/vm/map_populate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/map_populate.c +1 -1
index 6b8aeaa0bf7a..ca3f54765897 100644
@@ -23,7 +23,7 @@
 
 #define BUG_ON(condition, description)					\
 	do {								\
-		if (condition) {					\
+		if (unlikely(condition)) {				\
 			fprintf(stderr, "[FAIL]\t%s:%d\t%s:%s\n", __func__, \
 				__LINE__, (description), strerror(errno)); \
 			exit(1);					\
Signature · 1 line
2.17.1
#10 lore raw

PATCH 6/23 virtio: add unlikely() to WARN_ON_ONCE()

In reply to a message not in the archive

The condition to test is unlikely() to be true. Add the hint.

Cc "Michael S. Tsirkin" <[email protected]>
---
 tools/virtio/linux/kernel.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/virtio/linux/kernel.h +1 -1
index fb22bccfbc8a..2b5e417ea2f0 100644
@@ -123,7 +123,7 @@ static inline void free_page(unsigned long addr)
 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 
-#define WARN_ON_ONCE(cond) ((cond) ? fprintf (stderr, "WARNING\n") : 0)
+#define WARN_ON_ONCE(cond) (unlikely(cond) ? fprintf (stderr, "WARNING\n") : 0)
 
 #define min(x, y) ({				\
 	typeof(x) _min1 = (x);			\
Signature · 1 line
2.17.1
#11 lore raw

PATCH 7/23 seccomp: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

---
 kernel/seccomp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/seccomp.c +2 -2
index fd023ac24e10..5a2a9af4663e 100644
@@ -195,7 +195,7 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd,
 			READ_ONCE(current->seccomp.filter);
 
 	/* Ensure unexpected behavior doesn't result in failing open. */
-	if (unlikely(WARN_ON(f == NULL)))
+	if (WARN_ON(f == NULL))
 		return SECCOMP_RET_KILL_PROCESS;
 
 	if (!sd) {
@@ -297,7 +297,7 @@ static inline pid_t seccomp_can_sync_threads(void)
 		/* Return the first thread that cannot be synchronized. */
 		failed = task_pid_vnr(thread);
 		/* If the pid cannot be resolved, then return -ESRCH */
-		if (unlikely(WARN_ON(failed == 0)))
+		if (WARN_ON(failed == 0))
 			failed = -ESRCH;
 		return failed;
 	}
Signature · 1 line
2.17.1
#13 lore raw

PATCH 8/23 drm: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Rob Clark <[email protected]>
Cc David Airlie <[email protected]>
Cc Archit Taneja <[email protected]>
Cc Stephane Viau <[email protected]>
---
 drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c | 4 ++--
 drivers/gpu/drm/msm/disp/mdp_format.c    | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/mdp5/mdp5_ctl.c +2 -2
index f93d5681267c..9e0b3730536d 100644
@@ -261,7 +261,7 @@ int mdp5_ctl_set_cursor(struct mdp5_ctl *ctl, struct mdp5_pipeline *pipeline,
 	u32 blend_cfg;
 	struct mdp5_hw_mixer *mixer = pipeline->mixer;
 
-	if (unlikely(WARN_ON(!mixer))) {
+	if (WARN_ON(!mixer)) {
 		dev_err(ctl_mgr->dev->dev, "CTL %d cannot find LM",
 			ctl->id);
 		return -EINVAL;
@@ -703,7 +703,7 @@ struct mdp5_ctl_manager *mdp5_ctlm_init(struct drm_device *dev,
 		goto fail;
 	}
 
-	if (unlikely(WARN_ON(ctl_cfg->count > MAX_CTL))) {
+	if (WARN_ON(ctl_cfg->count > MAX_CTL)) {
 		dev_err(dev->dev, "Increase static pool size to at least %d\n",
 				ctl_cfg->count);
 		ret = -ENOSPC;
drivers/gpu/drm/msm/disp/mdp_format.c +1 -1
index 005760bee708..005f24dcfbdd 100644
@@ -185,7 +185,7 @@ const struct msm_format *mdp_get_format(struct msm_kms *kms, uint32_t format,
 
 struct csc_cfg *mdp_get_default_csc_cfg(enum csc_type type)
 {
-	if (unlikely(WARN_ON(type >= CSC_MAX)))
+	if (WARN_ON(type >= CSC_MAX))
 		return NULL;
 
 	return &csc_convert[type];
Signature · 1 line
2.17.1
#14 lore raw

PATCH 9/23 cpufreq: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Srivatsa S. Bhat <[email protected]>
---
 drivers/cpufreq/cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/cpufreq.c +1 -1
index f53fb41efb7b..7aa3dcad2175 100644
@@ -403,7 +403,7 @@ EXPORT_SYMBOL_GPL(cpufreq_freq_transition_begin);
 void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
 		struct cpufreq_freqs *freqs, int transition_failed)
 {
-	if (unlikely(WARN_ON(!policy->transition_ongoing)))
+	if (WARN_ON(!policy->transition_ongoing))
 		return;
 
 	cpufreq_notify_post_transition(policy, freqs, transition_failed);
Signature · 1 line
2.17.1
#15 lore raw

PATCH 10/23 wireless: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON_ONCE() already contains an unlikely(), and the logical or of two of them is still unlikely(), so it's not necessary to wrap them into another.

Cc Christian Lamparter <[email protected]>
Cc Kalle Valo <[email protected]>
---
 drivers/net/wireless/ath/carl9170/tx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/carl9170/tx.c +2 -2
index 0cb5b58925dc..8c75651ede6c 100644
@@ -246,8 +246,8 @@ static void carl9170_release_dev_space(struct ar9170 *ar, struct sk_buff *skb)
 	 *    of available memory blocks, so the number can
 	 *    never execeed the mem_blocks count.
 	 */
-	if (unlikely(WARN_ON_ONCE(cookie == 0) ||
-	    WARN_ON_ONCE(cookie > ar->fw.mem_blocks)))
+	if (WARN_ON_ONCE(cookie == 0) ||
+	    WARN_ON_ONCE(cookie > ar->fw.mem_blocks))
 		return;
 
 	atomic_add(DIV_ROUND_UP(skb->len, ar->fw.mem_block_size),
Signature · 1 line
2.17.1
#18 lore raw

PATCH 11/23 wireless: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON_ONCE() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Kalle Valo <[email protected]>
Cc Michal Kazior <[email protected]>
---
 drivers/net/wireless/ath/ath10k/htt_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath10k/htt_rx.c +2 -2
index 4d1cd90d6d27..1455007f3eb8 100644
@@ -1176,11 +1176,11 @@ static void ath10k_htt_rx_h_undecap_raw(struct ath10k *ar,
 	 */
 
 	/* This probably shouldn't happen but warn just in case */
-	if (unlikely(WARN_ON_ONCE(!is_first)))
+	if (WARN_ON_ONCE(!is_first))
 		return;
 
 	/* This probably shouldn't happen but warn just in case */
-	if (unlikely(WARN_ON_ONCE(!(is_first && is_last))))
+	if (WARN_ON_ONCE(!(is_first && is_last)))
 		return;
 
 	skb_trim(msdu, msdu->len - FCS_LEN);
Signature · 1 line
2.17.1
#19 lore raw

PATCH 12/23 wireless: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Larry Finger <[email protected]>
Cc Kalle Valo <[email protected]>
---
 drivers/net/wireless/broadcom/b43/dma.c       | 2 +-
 drivers/net/wireless/broadcom/b43legacy/dma.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/wireless/broadcom/b43/dma.c +1 -1
index 6b0e1ec346cb..d113bd997f4b 100644
@@ -1432,7 +1432,7 @@ int b43_dma_tx(struct b43_wldev *dev, struct sk_buff *skb)
 		goto out;
 	}
 
-	if (unlikely(WARN_ON(free_slots(ring) < TX_SLOTS_PER_FRAME))) {
+	if (WARN_ON(free_slots(ring) < TX_SLOTS_PER_FRAME)) {
 		/* If we get here, we have a real error with the queue
 		 * full, but queues not stopped. */
 		b43err(dev->wl, "DMA queue overflow\n");
drivers/net/wireless/broadcom/b43legacy/dma.c +1 -1
index 2f0c64cef65f..1b1da7d83652 100644
@@ -1149,7 +1149,7 @@ int b43legacy_dma_tx(struct b43legacy_wldev *dev,
 		return -ENOSPC;
 	}
 
-	if (unlikely(WARN_ON(free_slots(ring) < SLOTS_PER_PACKET))) {
+	if (WARN_ON(free_slots(ring) < SLOTS_PER_PACKET)) {
 		/* If we get here, we have a real error with the queue
 		 * full, but queues not stopped. */
 		b43legacyerr(dev->wl, "DMA queue overflow\n");
Signature · 1 line
2.17.1
#20 lore raw

PATCH 13/23 freescale: ethernet: remove unnecessary unlikely()

In reply to a message not in the archive

Both WARN_ON() and WARN_ONCE() already contain an unlikely(), so it's not necessary to wrap it into another.

---
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +3 -5
index 65a22cd9aef2..783134f1b779 100644
@@ -1280,7 +1280,7 @@ static int dpaa_bman_release(const struct dpaa_bp *dpaa_bp,
 
 	err = bman_release(dpaa_bp->pool, bmb, cnt);
 	/* Should never occur, address anyway to avoid leaking the buffers */
-	if (unlikely(WARN_ON(err)) && dpaa_bp->free_buf_cb)
+	if (WARN_ON(err) && dpaa_bp->free_buf_cb)
 		while (cnt-- > 0)
 			dpaa_bp->free_buf_cb(dpaa_bp, &bmb[cnt]);
 
@@ -1704,10 +1704,8 @@ static struct sk_buff *contig_fd_to_skb(const struct dpaa_priv *priv,
 
 	skb = build_skb(vaddr, dpaa_bp->size +
 			SKB_DATA_ALIGN(sizeof(struct skb_shared_info)));
-	if (unlikely(!skb)) {
-		WARN_ONCE(1, "Build skb failure on Rx\n");
+	if (WARN_ONCE(!skb, "Build skb failure on Rx\n"))
 		goto free_buffer;
-	}
 	WARN_ON(fd_off != priv->rx_headroom);
 	skb_reserve(skb, fd_off);
 	skb_put(skb, qm_fd_get_length(fd));
@@ -1770,7 +1768,7 @@ static struct sk_buff *sg_fd_to_skb(const struct dpaa_priv *priv,
 			sz = dpaa_bp->size +
 				SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 			skb = build_skb(sg_vaddr, sz);
-			if (WARN_ON(unlikely(!skb)))
+			if (WARN_ON(!skb))
 				goto free_buffers;
 
 			skb->ip_summed = rx_csum_offload(priv, fd);
Signature · 1 line
2.17.1
#21 lore raw

PATCH 14/23 wimax: i2400m: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Inaky Perez-Gonzalez <[email protected]>
---
 drivers/net/wimax/i2400m/tx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wimax/i2400m/tx.c +1 -2
index f20886ade1cc..59c70d928249 100644
@@ -655,8 +655,7 @@ void i2400m_tx_close(struct i2400m *i2400m)
 	padding = aligned_size - tx_msg_moved->size;
 	if (padding > 0) {
 		pad_buf = i2400m_tx_fifo_push(i2400m, padding, 0, 0);
-		if (unlikely(WARN_ON(pad_buf == NULL
-				     || pad_buf == TAIL_FULL))) {
+		if (WARN_ON(!pad_buf || pad_buf == TAIL_FULL)) {
 			/* This should not happen -- append should verify
 			 * there is always space left at least to append
 			 * tx_block_size */
Signature · 1 line
2.17.1
#22 lore raw

PATCH 15/23 lvm: device mapper: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Mike Snitzer <[email protected]>
Cc Alasdair Kergon <[email protected]>
---
 drivers/md/dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm.c +1 -1
index 20f7e4ef5342..0f0f8547106d 100644
@@ -1653,7 +1653,7 @@ static blk_qc_t __process_bio(struct mapped_device *md,
 		 * Defend against IO still getting in during teardown
 		 * - as was seen for a time with nvme-fcloop
 		 */
-		if (unlikely(WARN_ON_ONCE(!ti || !dm_target_is_valid(ti)))) {
+		if (WARN_ON_ONCE(!ti || !dm_target_is_valid(ti))) {
 			error = -EIO;
 			goto out;
 		}
Signature · 1 line
2.17.1
#23 lore raw

PATCH 16/23 lvm: device mapper: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Joe Thornber <[email protected]>
Cc Alasdair Kergon <[email protected]>
---
 drivers/md/dm-cache-policy-smq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm-cache-policy-smq.c +1 -1
index 1b5b9ad9e492..b61aac00ff40 100644
@@ -1200,7 +1200,7 @@ static void queue_demotion(struct smq_policy *mq)
 	struct policy_work work;
 	struct entry *e;
 
-	if (unlikely(WARN_ON_ONCE(!mq->migrations_allowed)))
+	if (WARN_ON_ONCE(!mq->migrations_allowed))
 		return;
 
 	e = q_peek(&mq->clean, mq->clean.nr_levels / 2, true);
Signature · 1 line
2.17.1
#24 lore raw

PATCH 17/23 usb: octeon-hcd: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Aaro Koskinen <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/staging/octeon-usb/octeon-hcd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/octeon-usb/octeon-hcd.c +1 -1
index cff5e790b196..1a6431879201 100644
@@ -2768,7 +2768,7 @@ static int cvmx_usb_poll_channel(struct octeon_hcd *usb, int channel)
 	    (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT))
 		pipe->flags |= CVMX_USB_PIPE_FLAGS_NEED_PING;
 
-	if (unlikely(WARN_ON_ONCE(bytes_this_transfer < 0))) {
+	if (WARN_ON_ONCE(bytes_this_transfer < 0)) {
 		/*
 		 * In some rare cases the DMA engine seems to get stuck and
 		 * keeps substracting same byte count over and over again. In
Signature · 1 line
2.17.1
#25 lore raw

PATCH 18/23 infiniband: scsi: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Bart Van Assche <[email protected]>
---
 drivers/infiniband/ulp/srpt/ib_srpt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srpt/ib_srpt.c +1 -1
index f37cbad022a2..447d21ea479a 100644
@@ -2708,7 +2708,7 @@ static void srpt_queue_response(struct se_cmd *cmd)
 		break;
 	}
 
-	if (unlikely(WARN_ON_ONCE(state == SRPT_STATE_CMD_RSP_SENT)))
+	if (WARN_ON_ONCE(state == SRPT_STATE_CMD_RSP_SENT))
 		return;
 
 	/* For read commands, transfer the data to the initiator. */
Signature · 1 line
2.17.1
#27 lore raw

PATCH 19/23 pinctrl: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Andrew Jeffery <[email protected]>
Cc Linus Walleij <[email protected]>
---
 drivers/pinctrl/aspeed/pinctrl-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/aspeed/pinctrl-aspeed.c +1 -1
index aefe3c33dffd..eb87ab774269 100644
@@ -715,7 +715,7 @@ int aspeed_pin_config_set(struct pinctrl_dev *pctldev, unsigned int offset,
 
 		pmap = find_pinconf_map(param, MAP_TYPE_ARG, arg);
 
-		if (unlikely(WARN_ON(!pmap)))
+		if (WARN_ON(!pmap))
 			return -EINVAL;
 
 		val = pmap->val << pconf->bit;
Signature · 1 line
2.17.1
#29 lore raw

PATCH 20/23 mm: percpu: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc zijun_hu <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Dennis Zhou <[email protected]>
---
 mm/percpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/percpu.c +1 -1
index a749d4d96e3e..f5c2796fe63e 100644
@@ -2588,7 +2588,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size,
 	BUG_ON(ai->nr_groups != 1);
 	upa = ai->alloc_size/ai->unit_size;
 	nr_g0_units = roundup(num_possible_cpus(), upa);
-	if (unlikely(WARN_ON(ai->groups[0].nr_units != nr_g0_units))) {
+	if (WARN_ON(ai->groups[0].nr_units != nr_g0_units)) {
 		pcpu_free_alloc_info(ai);
 		return -EINVAL;
 	}
Signature · 1 line
2.17.1
#31 lore raw

PATCH 21/23 filesystems: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Alexander Viro <[email protected]>
---
 fs/open.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/open.c +1 -1
index 0285ce7dbd51..19a9e4b378d3 100644
@@ -750,7 +750,7 @@ static int do_dentry_open(struct file *f,
 		f->f_mode |= FMODE_ATOMIC_POS;
 
 	f->f_op = fops_get(inode->i_fop);
-	if (unlikely(WARN_ON(!f->f_op))) {
+	if (WARN_ON(!f->f_op)) {
 		error = -ENODEV;
 		goto cleanup_all;
 	}
Signature · 1 line
2.17.1
#32 lore raw

PATCH 22/23 powerpc: remove unnecessary unlikely()

In reply to a message not in the archive

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc Arseny Solokha <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Michael Ellerman <[email protected]>
---
 arch/powerpc/mm/tlb_nohash.c      | 2 +-
 arch/powerpc/sysdev/xive/common.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/mm/tlb_nohash.c +1 -1
index 15fe5f0c8665..46f5d8c972fb 100644
@@ -302,7 +302,7 @@ void __flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
 	 * This function as well as __local_flush_tlb_page() must only be called
 	 * for user contexts.
 	 */
-	if (unlikely(WARN_ON(!mm)))
+	if (WARN_ON(!mm))
 		return;
 
 	preempt_disable();
arch/powerpc/sysdev/xive/common.c +1 -1
index 959a2a62f233..7dde46b38979 100644
@@ -442,7 +442,7 @@ static void xive_dec_target_count(int cpu)
 	struct xive_cpu *xc = per_cpu(xive_cpu, cpu);
 	struct xive_q *q = &xc->queue[xive_irq_priority];
 
-	if (unlikely(WARN_ON(cpu < 0 || !xc))) {
+	if (WARN_ON(cpu < 0 || !xc)) {
 		pr_err("%s: cpu=%d xc=%p\n", __func__, cpu, xc);
 		return;
 	}
Signature · 1 line
2.17.1
#33 lore raw

PATCH 23/23 scsi: remove unnecessary unlikely()

In reply to a message not in the archive

BUG_ON() already contains an unlikely(), there is no need for another one.

Cc "Martin K. Petersen" <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
---
 drivers/scsi/scsi_lib.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +2 -2
index 0adfb3bce0fd..aaa1819b0a69 100644
@@ -1207,8 +1207,8 @@ int scsi_init_io(struct scsi_cmnd *cmd)
 
 		count = blk_rq_map_integrity_sg(rq->q, rq->bio,
 						prot_sdb->table.sgl);
-		BUG_ON(unlikely(count > ivecs));
-		BUG_ON(unlikely(count > queue_max_integrity_segments(rq->q)));
+		BUG_ON(count > ivecs);
+		BUG_ON(count > queue_max_integrity_segments(rq->q));
 
 		cmd->prot_sdb = prot_sdb;
 		cmd->prot_sdb->table.nents = count;
Signature · 1 line
2.17.1
#7 lore raw

Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

In reply to Igor Stoppa

Hi Igor,

Quoted 1 line · Igor Stoppa

BUG_ON() is unlikely() to BUG()

This selftest runs in userspace..
So, we should define the macro somehow, as i.e:
rseq/rseq.h:#define rseq_unlikely(x) __builtin_expect(!!(x), 0)

Otherwise,
[selftests]$ make vm/map_populate
cc vm/map_populate.c -o vm/map_populate
vm/map_populate.c: In function ‘parent_f’:
vm/map_populate.c:26:7: warning: implicit declaration of function ‘unlikely’; did you mean ‘unlinkat’? [-Wimplicit-function-declaration]

   if (unlikely(condition)) {     \
       ^

vm/map_populate.c:38:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(ret <= 0, "read(sock)");
^~~~~~
/tmp/cc7evGVG.o: In function `parent_f':
map_populate.c:(.text+0x3d): undefined reference to unlikely' map_populate.c:(.text+0xbb): undefined reference to unlikely' map_populate.c:(.text+0x135): undefined reference to unlikely' map_populate.c:(.text+0x1b0): undefined reference to unlikely'

Not sure if we care for this at all for userspace test.
I don't mind as it runs each time by kbuild robot and cumulatively may save something. But it's better be at least compile-tested.

Signature · 1 line
            Dima
#8 lore raw

Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

Quoted 27 lines · Dmitry Safonov

Hi Igor,

Quoted 1 line · Igor Stoppa

BUG_ON() is unlikely() to BUG()

This selftest runs in userspace..
So, we should define the macro somehow, as i.e:
rseq/rseq.h:#define rseq_unlikely(x) __builtin_expect(!!(x), 0)

Otherwise,
[selftests]$ make vm/map_populate
cc vm/map_populate.c -o vm/map_populate
vm/map_populate.c: In function ‘parent_f’:
vm/map_populate.c:26:7: warning: implicit declaration of function ‘unlikely’; did you mean ‘unlinkat’? [-Wimplicit-function- declaration]

   if (unlikely(condition)) {     \
       ^

vm/map_populate.c:38:2: note: in expansion of macro ‘BUG_ON’
BUG_ON(ret <= 0, "read(sock)");
^~~~~~
/tmp/cc7evGVG.o: In function `parent_f':
map_populate.c:(.text+0x3d): undefined reference to unlikely' map_populate.c:(.text+0xbb): undefined reference to unlikely' map_populate.c:(.text+0x135): undefined reference to unlikely' map_populate.c:(.text+0x1b0): undefined reference to unlikely'

Quoted 4 lines

Not sure if we care for this at all for userspace test. I don't mind as it runs each time by kbuild robot and cumulatively may
save something. But it's better be at least compile-tested.

JFI, there are a plenty of definitions for unlikely():
[linux]$ git grep 'define unlikely' tools +rseq_unlikely() from tools/testing/selftests/rseq/rseq.h

Probably, the one from "tools/include/linux/compiler.h" can be used in tools directory.

Signature · 1 line
            Dima
Acked-by on v1 20/23
#30 lore raw

Re: [PATCH 20/23] mm: percpu: remove unnecessary unlikely()

In reply to Igor Stoppa
Quoted 28 lines · Igor Stoppa

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

Cc zijun_hu <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Dennis Zhou <[email protected]>
---
 mm/percpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/percpu.c +1 -1
index a749d4d96e3e..f5c2796fe63e 100644
@@ -2588,7 +2588,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size,
 	BUG_ON(ai->nr_groups != 1);
 	upa = ai->alloc_size/ai->unit_size;
 	nr_g0_units = roundup(num_possible_cpus(), upa);
-	if (unlikely(WARN_ON(ai->groups[0].nr_units != nr_g0_units))) {
+	if (WARN_ON(ai->groups[0].nr_units != nr_g0_units)) {
 		pcpu_free_alloc_info(ai);
 		return -EINVAL;
 	}
Signature · 1 line
2.17.1

Thanks,
Dennis

#16 lore raw

Re: [PATCH 10/23] wireless: remove unnecessary unlikely()

In reply to Igor Stoppa

+ linux-wireless

Quoted 6 lines · Igor Stoppa

WARN_ON_ONCE() already contains an unlikely(), and the logical or of two of them is still unlikely(), so it's not necessary to wrap them into another.

Cc Christian Lamparter <[email protected]>
Cc Kalle Valo <[email protected]>

IMHO you could fold patches 10, 11 and 12 into one to avoid having three patches with duplicate titles. Or alternatively use proper driver prefixes like "ath10k:", "b43:" and so on.

But how do you want these to be applied? For the wireless patches you didn't Cc linux-wireless so our patchwork won't see them and hence I can't take them. So if you want me to take these, please resend and include linux-wireless.

Signature · 1 line
Kalle Valo
#17 lore raw

Re: [PATCH 10/23] wireless: remove unnecessary unlikely()

Quoted 5 lines · Kalle Valo

+ linux-wireless

IMHO you could fold patches 10, 11 and 12 into one to avoid having three patches with duplicate titles. Or alternatively use proper driver prefixes like "ath10k:", "b43:" and so on.

I was wondering if it would be ok to fold them, but it's easier to fold than to split, so I started with 3

Quoted 4 lines

But how do you want these to be applied? For the wireless patches you didn't Cc linux-wireless so our patchwork won't see them and hence I can't take them. So if you want me to take these, please resend and include linux-wireless.

ok, I was hoping to avoid joining the ml but it's done
I had patches for about 20 different trees, so I decided to first see if the patches could be taken in right away. In at least one case (pinctrl) I got lucky :-)

--
thanks, igor

Acked-by on v1 1/23
#2 lore raw
In reply to Igor Stoppa
Quoted 8 lines · Igor Stoppa

Typically the assert is expected to not fail.

Cc Chien Tung <[email protected]>
Cc Roland Dreier <[email protected]>
Cc Faisal Latif <[email protected]>
Cc Doug Ledford <[email protected]>
Cc Jason Gunthorpe <[email protected]>
Quoted 17 lines
---
 drivers/infiniband/hw/nes/nes.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/nes/nes.h +1 -1
index bedaa02749fb..d2d0098f38e0 100644
@@ -151,7 +151,7 @@ do { \
 
 #define assert(expr) \
 do { \
-	if (!(expr)) { \
+	if (unlikely(!(expr))) { \
 		printk(KERN_ERR PFX "Assertion failed! %s, %s, %s, line %d\n", \
 			   #expr, __FILE__, __func__, __LINE__); \
 	} \
Signature · 3 lines
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
    Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD
maintainer
#34 lore raw

Re: [PATCH 00/23] Make use of unlikely() more consistently.

In reply to a message not in the archive
Quoted 12 lines · Igor Stoppa

In some cases, checks that are expected to not fail, do not take advantage of specifying that the condition being tested is unlikely().

Ex:

#define assert(condition)
...

        if (!(condition))
                error_action()

...

Quoted 7 lines

should be

#define assert(condition)
...

        if (unlikely(!(condition)))
                error_action()

...

There is a potential that this introduces false-postive -Wmaybe-uninitialized warnings when CONFIG_PROFILE_ANNOTATED_BRANCHES is
set, since that turns unlikely() into a complex operation that in turn confuses the compiler so it no longer keeps track of which variables are initialized or not.

It's possible that none of your patches do that, but one needs to be aware of the problem, and possibly revert some of your patches if it does cause warning regressions in drivers that don't actually benefit from the micro-optimization.

Quoted 7 lines

In other cases, the hint is given twice: once explicitly and once inside whatever test is being performed: assert(), BUG_ON(), WARN_ON(), etc.

Ex:

if (unlikely(WARN_ON(condition, message)))
...

Removing those is definitely fine.

Arnd

#35 lore raw

Re: [PATCH 00/23] Make use of unlikely() more consistently.

On 31/08/18 17:09, Arnd Bergmann wrote:

[...]

Quoted 12 lines
Quoted 5 lines

#define assert(condition)
...

         if (unlikely(!(condition)))
                 error_action()

...

There is a potential that this introduces false-postive -Wmaybe-uninitialized warnings when CONFIG_PROFILE_ANNOTATED_BRANCHES is
set, since that turns unlikely() into a complex operation that in turn confuses the compiler so it no longer keeps track of which variables are initialized or not.

Quoted 4 lines

It's possible that none of your patches do that, but one needs to be aware of the problem, and possibly revert some of your patches if it does cause warning regressions in drivers that don't actually benefit from the micro-optimization.

I see.
But if such case might arise, it might be possible, instead of reverting these patches, to locally - and conditionally - turn unlikely() into an identity macro.

For example:

#ifdef CONFIG_PROFILE_ANNOTATOED_BRANCHES
#define unlikely(x) (x)
#endif

Without giving up the hint for the case of normal compilation.

--
igor

#9 lore raw

Re: [PATCH 05/23] selftest: vm: add unlikely() to BUG_ON()

In reply to Dmitry Safonov

Hi Dmitry,

Quoted 2 lines · Dmitry Safonov

Probably, the one from "tools/include/linux/compiler.h" can be used in tools directory.

Thank you for the advice. It seems to work now.

--
igor

Acked-by on v1 7/23
#12 lore raw

Re: [PATCH 07/23] seccomp: remove unnecessary unlikely()

In reply to Igor Stoppa
Quoted 5 lines · Igor Stoppa

WARN_ON() already contains an unlikely(), so it's not necessary to wrap it into another.

-Kees

Quoted 29 lines
---
 kernel/seccomp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/seccomp.c +2 -3
index fd023ac24e10..5a2a9af4663e 100644
@@ -195,7 +195,7 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd,
                        READ_ONCE(current->seccomp.filter);
 
        /* Ensure unexpected behavior doesn't result in failing open. */
-       if (unlikely(WARN_ON(f == NULL)))
+       if (WARN_ON(f == NULL))
                return SECCOMP_RET_KILL_PROCESS;
 
        if (!sd) {
@@ -297,7 +297,7 @@ static inline pid_t seccomp_can_sync_threads(void)
                /* Return the first thread that cannot be synchronized. */
                failed = task_pid_vnr(thread);
                /* If the pid cannot be resolved, then return -ESRCH */
-               if (unlikely(WARN_ON(failed == 0)))
+               if (WARN_ON(failed == 0))
                        failed = -ESRCH;
                return failed;
        }
--

2.17.1

Signature · 2 lines
Kees Cook
Pixel Security