linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] drop if around WARN_ON
@ 2012-11-03 20:30 Julia Lawall
  2012-11-03 20:30 ` [PATCH 1/8] fs/btrfs: " Julia Lawall
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

These patches convert a conditional with a simple test expression and a
then branch that only calls WARN_ON(1) to just a call to WARN_ON, which
will test the condition.

// <smpl>
@@
expression e;
@@

(
if(<+...e(...)...+>) WARN_ON(1);
|
- if (e) WARN_ON(1);
+ WARN_ON(e);
)// </smpl>


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/8] fs/btrfs: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-05 15:39   ` David Sterba
  2012-11-03 20:30 ` [PATCH 2/8] drivers/scsi/bfa/bfa_svc.c: " Julia Lawall
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Chris Mason; +Cc: kernel-janitors, linux-btrfs, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 fs/btrfs/backref.c |    3 +--
 fs/btrfs/ctree.c   |    9 +++------
 fs/btrfs/inode.c   |    3 +--
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 208d8aa..a321952 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -890,8 +890,7 @@ again:
 	while (!list_empty(&prefs)) {
 		ref = list_first_entry(&prefs, struct __prelim_ref, list);
 		list_del(&ref->list);
-		if (ref->count < 0)
-			WARN_ON(1);
+		WARN_ON(ref->count < 0);
 		if (ref->count && ref->root_id && ref->parent == 0) {
 			/* no parent == root of tree */
 			ret = ulist_add(roots, ref->root_id, 0, GFP_NOFS);
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index cdfb4c4..8ecb995 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1469,10 +1469,8 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans,
 	if (cache_only && parent_level != 1)
 		return 0;
 
-	if (trans->transaction != root->fs_info->running_transaction)
-		WARN_ON(1);
-	if (trans->transid != root->fs_info->generation)
-		WARN_ON(1);
+	WARN_ON(trans->transaction != root->fs_info->running_transaction);
+	WARN_ON(trans->transid != root->fs_info->generation);
 
 	parent_nritems = btrfs_header_nritems(parent);
 	blocksize = btrfs_level_size(root, parent_level - 1);
@@ -3403,8 +3401,7 @@ static noinline int __push_leaf_right(struct btrfs_trans_handle *trans,
 	if (push_items == 0)
 		goto out_unlock;
 
-	if (!empty && push_items == left_nritems)
-		WARN_ON(1);
+	WARN_ON(!empty && push_items == left_nritems);
 
 	/* push left to right */
 	right_nritems = btrfs_header_nritems(right);
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 95542a1..0d169ab 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1657,8 +1657,7 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
 int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end,
 			      struct extent_state **cached_state)
 {
-	if ((end & (PAGE_CACHE_SIZE - 1)) == 0)
-		WARN_ON(1);
+	WARN_ON((end & (PAGE_CACHE_SIZE - 1)) == 0);
 	return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end,
 				   cached_state, GFP_NOFS);
 }


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/8] drivers/scsi/bfa/bfa_svc.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
  2012-11-03 20:30 ` [PATCH 1/8] fs/btrfs: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-03 20:30 ` [PATCH 3/8] arch/x86/kernel/cpu/mtrr/cleanup.c: " Julia Lawall
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Krishna C Gudipati
  Cc: kernel-janitors, James E.J. Bottomley, linux-scsi, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/scsi/bfa/bfa_svc.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c
index 299c1c8..765b8d0 100644
--- a/drivers/scsi/bfa/bfa_svc.c
+++ b/drivers/scsi/bfa/bfa_svc.c
@@ -626,8 +626,7 @@ bfa_fcxp_init_reqrsp(struct bfa_fcxp_s *fcxp,
 		/*
 		 * alloc required sgpgs
 		 */
-		if (n_sgles > BFI_SGE_INLINE)
-			WARN_ON(1);
+		WARN_ON(n_sgles > BFI_SGE_INLINE);
 	}
 
 }


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/8] arch/x86/kernel/cpu/mtrr/cleanup.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
  2012-11-03 20:30 ` [PATCH 1/8] fs/btrfs: " Julia Lawall
  2012-11-03 20:30 ` [PATCH 2/8] drivers/scsi/bfa/bfa_svc.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-03 20:30 ` [PATCH 4/8] fs/ext3/inode.c: " Julia Lawall
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: kernel-janitors, Ingo Molnar, H. Peter Anvin, x86, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 arch/x86/kernel/cpu/mtrr/cleanup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/mtrr/cleanup.c b/arch/x86/kernel/cpu/mtrr/cleanup.c
index 35ffda5..dd833bf 100644
--- a/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ b/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -967,8 +967,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)
 	if (total_trim_size) {
 		pr_warning("WARNING: BIOS bug: CPU MTRRs don't cover all of memory, losing %lluMB of RAM.\n", total_trim_size >> 20);
 
-		if (!changed_by_mtrr_cleanup)
-			WARN_ON(1);
+		WARN_ON(!changed_by_mtrr_cleanup);
 
 		pr_info("update e820 for mtrr\n");
 		update_e820();


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 4/8] fs/ext3/inode.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (2 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 3/8] arch/x86/kernel/cpu/mtrr/cleanup.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-06 23:04   ` Jan Kara
  2012-11-03 20:30 ` [PATCH 5/8] drivers/scsi/qla2xxx/qla_nx.c: " Julia Lawall
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Jan Kara
  Cc: kernel-janitors, Andrew Morton, Andreas Dilger, linux-ext4, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 fs/ext3/inode.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 7e87e37..b176d42 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1071,8 +1071,7 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
 	 * mapped. 0 in case of a HOLE.
 	 */
 	if (err > 0) {
-		if (err > 1)
-			WARN_ON(1);
+		WARN_ON(err > 1);
 		err = 0;
 	}
 	*errp = err;


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 5/8] drivers/scsi/qla2xxx/qla_nx.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (3 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 4/8] fs/ext3/inode.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-03 20:30 ` [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: " Julia Lawall
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Andrew Vasquez
  Cc: kernel-janitors, linux-driver, James E.J. Bottomley, linux-scsi,
	linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/scsi/qla2xxx/qla_nx.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/qla2xxx/qla_nx.c b/drivers/scsi/qla2xxx/qla_nx.c
index f5e297c..4c62a5d 100644
--- a/drivers/scsi/qla2xxx/qla_nx.c
+++ b/drivers/scsi/qla2xxx/qla_nx.c
@@ -388,8 +388,7 @@ qla82xx_pci_set_crbwindow(struct qla_hw_data *ha, u64 off)
 
 	if ((off >= QLA82XX_CRB_PCIX_HOST) && (off < QLA82XX_CRB_PCIX_HOST2)) {
 		/* We are in first CRB window */
-		if (ha->curr_window != 0)
-			WARN_ON(1);
+		WARN_ON(ha->curr_window != 0);
 		return off;
 	}
 


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (4 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 5/8] drivers/scsi/qla2xxx/qla_nx.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-12-14 18:53   ` Tony Lindgren
  2012-11-03 20:30 ` [PATCH 7/8] drivers/scsi/scsi_transport_fc.c: " Julia Lawall
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: kernel-janitors, Russell King, linux-arm-kernel, linux-omap,
	linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 arch/arm/mach-omap2/dpll3xxx.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm/mach-omap2/dpll3xxx.c b/arch/arm/mach-omap2/dpll3xxx.c
index eacf51f..ed855b0 100644
--- a/arch/arm/mach-omap2/dpll3xxx.c
+++ b/arch/arm/mach-omap2/dpll3xxx.c
@@ -478,8 +478,7 @@ int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate)
 		if (!soc_is_am33xx() && !cpu_is_omap44xx() && !cpu_is_omap3630()) {
 			freqsel = _omap3_dpll_compute_freqsel(clk,
 						dd->last_rounded_n);
-			if (!freqsel)
-				WARN_ON(1);
+			WARN_ON(!freqsel);
 		}
 
 		pr_debug("clock: %s: set rate: locking rate to %lu.\n",


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 7/8] drivers/scsi/scsi_transport_fc.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (5 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-03 20:30 ` [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: " Julia Lawall
  2012-11-04 14:59 ` [PATCH 0/8] " Sasha Levin
  8 siblings, 0 replies; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: James E.J. Bottomley; +Cc: kernel-janitors, linux-scsi, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/scsi/scsi_transport_fc.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index e894ca7..f54c945 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1699,9 +1699,8 @@ fc_stat_show(const struct device *dev, char *buf, unsigned long offset)
 	struct fc_host_statistics *stats;
 	ssize_t ret = -ENOENT;
 
-	if (offset > sizeof(struct fc_host_statistics) ||
-	    offset % sizeof(u64) != 0)
-		WARN_ON(1);
+	WARN_ON(offset > sizeof(struct fc_host_statistics) ||
+		offset % sizeof(u64) != 0);
 
 	if (i->f->get_fc_host_stats) {
 		stats = (i->f->get_fc_host_stats)(shost);


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (6 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 7/8] drivers/scsi/scsi_transport_fc.c: " Julia Lawall
@ 2012-11-03 20:30 ` Julia Lawall
  2012-11-16 11:39   ` Kalle Valo
  2012-11-04 14:59 ` [PATCH 0/8] " Sasha Levin
  8 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-03 20:30 UTC (permalink / raw)
  To: Kalle Valo
  Cc: kernel-janitors, John W. Linville, linux-wireless, netdev, linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Just use WARN_ON rather than an if containing only WARN_ON(1).

A simplified version of the semantic patch that makes this transformation
is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression e;
@@
- if (e) WARN_ON(1);
+ WARN_ON(e);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
 drivers/net/wireless/ath/ath6kl/hif.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/hif.c b/drivers/net/wireless/ath/ath6kl/hif.c
index 68ed6c2..9e47c4a 100644
--- a/drivers/net/wireless/ath/ath6kl/hif.c
+++ b/drivers/net/wireless/ath/ath6kl/hif.c
@@ -338,8 +338,7 @@ static int ath6kl_hif_proc_err_intr(struct ath6kl_device *dev)
 	status = hif_read_write_sync(dev->ar, ERROR_INT_STATUS_ADDRESS,
 				     reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
 
-	if (status)
-		WARN_ON(1);
+	WARN_ON(status);
 
 	return status;
 }
@@ -383,8 +382,7 @@ static int ath6kl_hif_proc_cpu_intr(struct ath6kl_device *dev)
 	status = hif_read_write_sync(dev->ar, CPU_INT_STATUS_ADDRESS,
 				     reg_buf, 4, HIF_WR_SYNC_BYTE_FIX);
 
-	if (status)
-		WARN_ON(1);
+	WARN_ON(status);
 
 	return status;
 }


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] drop if around WARN_ON
  2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
                   ` (7 preceding siblings ...)
  2012-11-03 20:30 ` [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: " Julia Lawall
@ 2012-11-04 14:59 ` Sasha Levin
  2012-11-04 15:57   ` Julia Lawall
  8 siblings, 1 reply; 18+ messages in thread
From: Sasha Levin @ 2012-11-04 14:59 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

Hi Julia,

On Sat, Nov 3, 2012 at 4:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
> These patches convert a conditional with a simple test expression and a
> then branch that only calls WARN_ON(1) to just a call to WARN_ON, which
> will test the condition.
>
> // <smpl>
> @@
> expression e;
> @@
>
> (
> if(<+...e(...)...+>) WARN_ON(1);
> |
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> )// </smpl>

So this deals with WARN_ON(), are you considering doing the same for
the rest of it's friends?


Thanks,
Sasha

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] drop if around WARN_ON
  2012-11-04 14:59 ` [PATCH 0/8] " Sasha Levin
@ 2012-11-04 15:57   ` Julia Lawall
  2012-11-04 16:00     ` Sasha Levin
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-04 15:57 UTC (permalink / raw)
  To: Sasha Levin; +Cc: linux-kernel, kernel-janitors

On Sun, 4 Nov 2012, Sasha Levin wrote:

> Hi Julia,
>
> On Sat, Nov 3, 2012 at 4:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>> These patches convert a conditional with a simple test expression and a
>> then branch that only calls WARN_ON(1) to just a call to WARN_ON, which
>> will test the condition.
>>
>> // <smpl>
>> @@
>> expression e;
>> @@
>>
>> (
>> if(<+...e(...)...+>) WARN_ON(1);
>> |
>> - if (e) WARN_ON(1);
>> + WARN_ON(e);
>> )// </smpl>
>
> So this deals with WARN_ON(), are you considering doing the same for
> the rest of it's friends?

I tried WARN_ON_ONCE, but the pattern never occurred.  Are there others 
that are worth trying?

thanks,
julia

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] drop if around WARN_ON
  2012-11-04 15:57   ` Julia Lawall
@ 2012-11-04 16:00     ` Sasha Levin
  2012-11-04 16:16       ` Julia Lawall
  0 siblings, 1 reply; 18+ messages in thread
From: Sasha Levin @ 2012-11-04 16:00 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

On Sun, Nov 4, 2012 at 10:57 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> On Sun, 4 Nov 2012, Sasha Levin wrote:
>
>> Hi Julia,
>>
>> On Sat, Nov 3, 2012 at 4:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>>>
>>> These patches convert a conditional with a simple test expression and a
>>> then branch that only calls WARN_ON(1) to just a call to WARN_ON, which
>>> will test the condition.
>>>
>>> // <smpl>
>>> @@
>>> expression e;
>>> @@
>>>
>>> (
>>> if(<+...e(...)...+>) WARN_ON(1);
>>> |
>>> - if (e) WARN_ON(1);
>>> + WARN_ON(e);
>>> )// </smpl>
>>
>>
>> So this deals with WARN_ON(), are you considering doing the same for
>> the rest of it's friends?
>
>
> I tried WARN_ON_ONCE, but the pattern never occurred.  Are there others that
> are worth trying?

Definitely!

Here's the semantic patch I've got:

@@
expression e;
@@

(
- if (e) WARN_ON(1);
+ WARN_ON(e);
|
- if (e) WARN_ON_ONCE(1);
+ WARN_ON_ONCE(e);
|
- if (e) WARN_ON_SMP(1);
+ WARN_ON_SMP(e);
|
- if (e) BUG();
+ BUG_ON(e);
)

This gave me a really huge patch output.

I can send it out if you think the patch above looks good.


Thanks,
Sasha

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] drop if around WARN_ON
  2012-11-04 16:00     ` Sasha Levin
@ 2012-11-04 16:16       ` Julia Lawall
  2012-11-05  2:47         ` Sasha Levin
  0 siblings, 1 reply; 18+ messages in thread
From: Julia Lawall @ 2012-11-04 16:16 UTC (permalink / raw)
  To: Sasha Levin; +Cc: linux-kernel, kernel-janitors

On Sun, 4 Nov 2012, Sasha Levin wrote:

> On Sun, Nov 4, 2012 at 10:57 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> On Sun, 4 Nov 2012, Sasha Levin wrote:
>>
>>> Hi Julia,
>>>
>>> On Sat, Nov 3, 2012 at 4:30 PM, Julia Lawall <Julia.Lawall@lip6.fr> wrote:
>>>>
>>>> These patches convert a conditional with a simple test expression and a
>>>> then branch that only calls WARN_ON(1) to just a call to WARN_ON, which
>>>> will test the condition.
>>>>
>>>> // <smpl>
>>>> @@
>>>> expression e;
>>>> @@
>>>>
>>>> (
>>>> if(<+...e(...)...+>) WARN_ON(1);
>>>> |
>>>> - if (e) WARN_ON(1);
>>>> + WARN_ON(e);
>>>> )// </smpl>
>>>
>>>
>>> So this deals with WARN_ON(), are you considering doing the same for
>>> the rest of it's friends?
>>
>>
>> I tried WARN_ON_ONCE, but the pattern never occurred.  Are there others that
>> are worth trying?
>
> Definitely!
>
> Here's the semantic patch I've got:
>
> @@
> expression e;
> @@
>
> (
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> |
> - if (e) WARN_ON_ONCE(1);
> + WARN_ON_ONCE(e);
> |
> - if (e) WARN_ON_SMP(1);
> + WARN_ON_SMP(e);
> |
> - if (e) BUG();
> + BUG_ON(e);
> )
>
> This gave me a really huge patch output.
>
> I can send it out if you think the patch above looks good.

I didn't change any cases where the if test contains a function call.  The 
current definitions of WARN_ON seem to always evaluate the condition 
expression, but I was worried that that might not always be the case.  And 
calling a function (the ones I remember were some kinds of print 
functions) seems like something one might not want buried in the argument 
of a debugging macro.

WARN_ON_SMP is just WARN_ON if CONFIG_SMP is true, but it is just 0 
otherwise.  So in that case it seems important to check that one is not 
throwing away something important.

I remember working on the BUG_ON case several years ago, and other people 
worked on it too, but I guess some are still there...  The current 
definitions of BUG_ON seem to keep the condition, but there are quite a 
few specialized definitions, so someone at some point might make a version 
that does not have that property.

julia


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 0/8] drop if around WARN_ON
  2012-11-04 16:16       ` Julia Lawall
@ 2012-11-05  2:47         ` Sasha Levin
  0 siblings, 0 replies; 18+ messages in thread
From: Sasha Levin @ 2012-11-05  2:47 UTC (permalink / raw)
  To: Julia Lawall; +Cc: linux-kernel, kernel-janitors

On Sun, Nov 4, 2012 at 11:16 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> I didn't change any cases where the if test contains a function call.  The
> current definitions of WARN_ON seem to always evaluate the condition
> expression, but I was worried that that might not always be the case.  And
> calling a function (the ones I remember were some kinds of print functions)
> seems like something one might not want buried in the argument of a
> debugging macro.

Makes sense.

> WARN_ON_SMP is just WARN_ON if CONFIG_SMP is true, but it is just 0
> otherwise.  So in that case it seems important to check that one is not
> throwing away something important.

Yup, we just need to make sure that the expression being evaluated doesn't
have side-effects.

> I remember working on the BUG_ON case several years ago, and other people
> worked on it too, but I guess some are still there...  The current
> definitions of BUG_ON seem to keep the condition, but there are quite a few
> specialized definitions, so someone at some point might make a version that
> does not have that property.

It makes sense to keep an eye for such things when converting code. I
also don't think we'll get to see a version of BUG_ON which doesn't
evaluate the expression since the kernel already has more than enough
BUG_ONs that assume the expression will be evaluated:

BUG_ON(HYPERVISOR_callback_op(CALLBACKOP_register, &event));
BUG_ON(gpiochip_add(&gemini_gpio_chip));
BUG_ON(clocksource_register_hz(&sirfsoc_clocksource, CLOCK_TICK_RATE));
BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);

And so on, so we're probably safe converting to BUG_ON even if the
condition is a function, as long as it doesn't create a long and
complicated BUG_ON() ofcourse.


Thanks,
Sasha

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/8] fs/btrfs: drop if around WARN_ON
  2012-11-03 20:30 ` [PATCH 1/8] fs/btrfs: " Julia Lawall
@ 2012-11-05 15:39   ` David Sterba
  0 siblings, 0 replies; 18+ messages in thread
From: David Sterba @ 2012-11-05 15:39 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Chris Mason, kernel-janitors, linux-btrfs, linux-kernel

On Sat, Nov 03, 2012 at 09:30:18PM +0100, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Just use WARN_ON rather than an if containing only WARN_ON(1).
> 
> A simplified version of the semantic patch that makes this transformation
> is as follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e;
> @@
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Reviewed-by: David Sterba <dsterba@suse.cz>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 4/8] fs/ext3/inode.c: drop if around WARN_ON
  2012-11-03 20:30 ` [PATCH 4/8] fs/ext3/inode.c: " Julia Lawall
@ 2012-11-06 23:04   ` Jan Kara
  0 siblings, 0 replies; 18+ messages in thread
From: Jan Kara @ 2012-11-06 23:04 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jan Kara, kernel-janitors, Andrew Morton, Andreas Dilger,
	linux-ext4, linux-kernel

On Sat 03-11-12 21:30:21, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Just use WARN_ON rather than an if containing only WARN_ON(1).
> 
> A simplified version of the semantic patch that makes this transformation
> is as follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e;
> @@
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
  Thanks. Added into my tree.

							Honza

> ---
>  fs/ext3/inode.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
> index 7e87e37..b176d42 100644
> --- a/fs/ext3/inode.c
> +++ b/fs/ext3/inode.c
> @@ -1071,8 +1071,7 @@ struct buffer_head *ext3_getblk(handle_t *handle, struct inode *inode,
>  	 * mapped. 0 in case of a HOLE.
>  	 */
>  	if (err > 0) {
> -		if (err > 1)
> -			WARN_ON(1);
> +		WARN_ON(err > 1);
>  		err = 0;
>  	}
>  	*errp = err;
> 
-- 
Jan Kara <jack@suse.cz>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: drop if around WARN_ON
  2012-11-03 20:30 ` [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: " Julia Lawall
@ 2012-11-16 11:39   ` Kalle Valo
  0 siblings, 0 replies; 18+ messages in thread
From: Kalle Valo @ 2012-11-16 11:39 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, John W. Linville, linux-wireless, netdev, linux-kernel

On 11/03/2012 10:30 PM, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Just use WARN_ON rather than an if containing only WARN_ON(1).
> 
> A simplified version of the semantic patch that makes this transformation
> is as follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e;
> @@
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Thanks, applied to ath6kl.git.

Kalle

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: drop if around WARN_ON
  2012-11-03 20:30 ` [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: " Julia Lawall
@ 2012-12-14 18:53   ` Tony Lindgren
  0 siblings, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-12-14 18:53 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors, Russell King, linux-arm-kernel, linux-omap,
	linux-kernel

* Julia Lawall <Julia.Lawall@lip6.fr> [121103 13:32]:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Just use WARN_ON rather than an if containing only WARN_ON(1).

Thanks applying this one into omap-for-v3.8/fixes-for-merge-window.

Regards,

Tony
 
> A simplified version of the semantic patch that makes this transformation
> is as follows: (http://coccinelle.lip6.fr/)
> 
> // <smpl>
> @@
> expression e;
> @@
> - if (e) WARN_ON(1);
> + WARN_ON(e);
> // </smpl>
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> ---
>  arch/arm/mach-omap2/dpll3xxx.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/dpll3xxx.c b/arch/arm/mach-omap2/dpll3xxx.c
> index eacf51f..ed855b0 100644
> --- a/arch/arm/mach-omap2/dpll3xxx.c
> +++ b/arch/arm/mach-omap2/dpll3xxx.c
> @@ -478,8 +478,7 @@ int omap3_noncore_dpll_set_rate(struct clk *clk, unsigned long rate)
>  		if (!soc_is_am33xx() && !cpu_is_omap44xx() && !cpu_is_omap3630()) {
>  			freqsel = _omap3_dpll_compute_freqsel(clk,
>  						dd->last_rounded_n);
> -			if (!freqsel)
> -				WARN_ON(1);
> +			WARN_ON(!freqsel);
>  		}
>  
>  		pr_debug("clock: %s: set rate: locking rate to %lu.\n",
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2012-12-14 18:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-03 20:30 [PATCH 0/8] drop if around WARN_ON Julia Lawall
2012-11-03 20:30 ` [PATCH 1/8] fs/btrfs: " Julia Lawall
2012-11-05 15:39   ` David Sterba
2012-11-03 20:30 ` [PATCH 2/8] drivers/scsi/bfa/bfa_svc.c: " Julia Lawall
2012-11-03 20:30 ` [PATCH 3/8] arch/x86/kernel/cpu/mtrr/cleanup.c: " Julia Lawall
2012-11-03 20:30 ` [PATCH 4/8] fs/ext3/inode.c: " Julia Lawall
2012-11-06 23:04   ` Jan Kara
2012-11-03 20:30 ` [PATCH 5/8] drivers/scsi/qla2xxx/qla_nx.c: " Julia Lawall
2012-11-03 20:30 ` [PATCH 6/8] arch/arm/mach-omap2/dpll3xxx.c: " Julia Lawall
2012-12-14 18:53   ` Tony Lindgren
2012-11-03 20:30 ` [PATCH 7/8] drivers/scsi/scsi_transport_fc.c: " Julia Lawall
2012-11-03 20:30 ` [PATCH 8/8] drivers/net/wireless/ath/ath6kl/hif.c: " Julia Lawall
2012-11-16 11:39   ` Kalle Valo
2012-11-04 14:59 ` [PATCH 0/8] " Sasha Levin
2012-11-04 15:57   ` Julia Lawall
2012-11-04 16:00     ` Sasha Levin
2012-11-04 16:16       ` Julia Lawall
2012-11-05  2:47         ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).