diff mbox

[v2] e1000e: Assign true and false to bool type variable instead of 1 and 0

Message ID 4EDED071.40900@linux.vnet.ibm.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Michael Wang Dec. 7, 2011, 2:33 a.m. UTC
From: Michael Wang <wangyun@linux.vnet.ibm.com>

Use true and false instead of 1 and 0 when assign value to a bool type
variable.

This patch is try to keep the style of driver, and according to David's
suggestion on patch "e1000e: Avoid wrong check on TX hang":

http://marc.info/?l=linux-netdev&m=132296931201839&w=2

v2: add more description

Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
---
 drivers/net/ethernet/intel/e1000e/netdev.c |   34
++++++++++++++--------------
 1 files changed, 17 insertions(+), 17 deletions(-)

 	i = rx_ring->next_to_clean;
@@ -904,7 +904,7 @@ static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter,

 		next_buffer = &rx_ring->buffer_info[i];

-		cleaned = 1;
+		cleaned = true;
 		cleaned_count++;
 		dma_unmap_single(&pdev->dev,
 				 buffer_info->dma,
@@ -1150,7 +1150,7 @@ static bool e1000_clean_tx_irq(struct
e1000_adapter *adapter)
 		 * Detect a transmit hang in hardware, this serializes the
 		 * check with the clearing of time_stamp and movement of i
 		 */
-		adapter->detect_tx_hung = 0;
+		adapter->detect_tx_hung = false;
 		if (tx_ring->buffer_info[i].time_stamp &&
 		    time_after(jiffies, tx_ring->buffer_info[i].time_stamp
 			       + (adapter->tx_timeout_factor * HZ)) &&
@@ -1185,7 +1185,7 @@ static bool e1000_clean_rx_irq_ps(struct
e1000_adapter *adapter,
 	unsigned int i, j;
 	u32 length, staterr;
 	int cleaned_count = 0;
-	bool cleaned = 0;
+	bool cleaned = false;
 	unsigned int total_rx_bytes = 0, total_rx_packets = 0;

 	i = rx_ring->next_to_clean;
@@ -1211,7 +1211,7 @@ static bool e1000_clean_rx_irq_ps(struct
e1000_adapter *adapter,

 		next_buffer = &rx_ring->buffer_info[i];

-		cleaned = 1;
+		cleaned = true;
 		cleaned_count++;
 		dma_unmap_single(&pdev->dev, buffer_info->dma,
 				 adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
@@ -1628,7 +1628,7 @@ static irqreturn_t e1000_intr_msi(int irq, void *data)
 	 */

 	if (icr & E1000_ICR_LSC) {
-		hw->mac.get_link_status = 1;
+		hw->mac.get_link_status = true;
 		/*
 		 * ICH8 workaround-- Call gig speed drop workaround on cable
 		 * disconnect (LSC) before accessing any PHY registers
@@ -1694,7 +1694,7 @@ static irqreturn_t e1000_intr(int irq, void *data)
 	 */

 	if (icr & E1000_ICR_LSC) {
-		hw->mac.get_link_status = 1;
+		hw->mac.get_link_status = true;
 		/*
 		 * ICH8 workaround-- Call gig speed drop workaround on cable
 		 * disconnect (LSC) before accessing any PHY registers
@@ -1751,7 +1751,7 @@ static irqreturn_t e1000_msix_other(int irq, void
*data)
 	if (icr & E1000_ICR_OTHER) {
 		if (!(icr & E1000_ICR_LSC))
 			goto no_link_interrupt;
-		hw->mac.get_link_status = 1;
+		hw->mac.get_link_status = true;
 		/* guard against interrupt when we're going down */
 		if (!test_bit(__E1000_DOWN, &adapter->state))
 			mod_timer(&adapter->watchdog_timer, jiffies + 1);
@@ -3327,7 +3327,7 @@ void e1000e_reset(struct e1000_adapter *adapter)
 		fc->pause_time = 0xFFFF;
 	else
 		fc->pause_time = E1000_FC_PAUSE_TIME;
-	fc->send_xon = 1;
+	fc->send_xon = true;
 	fc->current_mode = fc->requested_mode;

 	switch (hw->mac.type) {
@@ -4183,7 +4183,7 @@ static void e1000_print_link_info(struct
e1000_adapter *adapter)
 static bool e1000e_has_link(struct e1000_adapter *adapter)
 {
 	struct e1000_hw *hw = &adapter->hw;
-	bool link_active = 0;
+	bool link_active = false;
 	s32 ret_val = 0;

 	/*
@@ -4198,7 +4198,7 @@ static bool e1000e_has_link(struct e1000_adapter
*adapter)
 			ret_val = hw->mac.ops.check_for_link(hw);
 			link_active = !hw->mac.get_link_status;
 		} else {
-			link_active = 1;
+			link_active = true;
 		}
 		break;
 	case e1000_media_type_fiber:
@@ -4297,7 +4297,7 @@ static void e1000_watchdog_task(struct work_struct
*work)

 	if (link) {
 		if (!netif_carrier_ok(netdev)) {
-			bool txb2b = 1;
+			bool txb2b = true;

 			/* Cancel scheduled suspend requests. */
 			pm_runtime_resume(netdev->dev.parent);
@@ -4333,11 +4333,11 @@ static void e1000_watchdog_task(struct
work_struct *work)
 			adapter->tx_timeout_factor = 1;
 			switch (adapter->link_speed) {
 			case SPEED_10:
-				txb2b = 0;
+				txb2b = false;
 				adapter->tx_timeout_factor = 16;
 				break;
 			case SPEED_100:
-				txb2b = 0;
+				txb2b = false;
 				adapter->tx_timeout_factor = 10;
 				break;
 			}
@@ -4473,7 +4473,7 @@ link_up:
 	e1000e_flush_descriptors(adapter);

 	/* Force detection of hung controller every watchdog period */
-	adapter->detect_tx_hung = 1;
+	adapter->detect_tx_hung = true;

 	/*
 	 * With 82571 controllers, LAA may be overwritten due to controller
@@ -6134,8 +6134,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
 	INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);

 	/* Initialize link parameters. User can change them with ethtool */
-	adapter->hw.mac.autoneg = 1;
-	adapter->fc_autoneg = 1;
+	adapter->hw.mac.autoneg = true;
+	adapter->fc_autoneg = true;
 	adapter->hw.fc.requested_mode = e1000_fc_default;
 	adapter->hw.fc.current_mode = e1000_fc_default;
 	adapter->hw.phy.autoneg_advertised = 0x2f;

Comments

Kirsher, Jeffrey T Dec. 7, 2011, 3:43 a.m. UTC | #1
On Tue, 2011-12-06 at 18:33 -0800, Michael Wang wrote:
> From: Michael Wang <wangyun@linux.vnet.ibm.com>
> 
> Use true and false instead of 1 and 0 when assign value to a bool type
> variable.
> 
> This patch is try to keep the style of driver, and according to
> David's
> suggestion on patch "e1000e: Avoid wrong check on TX hang":
> 
> http://marc.info/?l=linux-netdev&m=132296931201839&w=2
> 
> v2: add more description
> 
> Signed-off-by: Michael Wang <wangyun@linux.vnet.ibm.com>
> ---
>  drivers/net/ethernet/intel/e1000e/netdev.c |   34
> ++++++++++++++--------------
>  1 files changed, 17 insertions(+), 17 deletions(-) 

Thanks Michael, I have added your patch to my queue of e1000e patches.
Joe Perches Dec. 7, 2011, 4:14 a.m. UTC | #2
On Tue, 2011-12-06 at 19:43 -0800, Jeff Kirsher wrote:
> On Tue, 2011-12-06 at 18:33 -0800, Michael Wang wrote:
> > From: Michael Wang <wangyun@linux.vnet.ibm.com>
> > Use true and false instead of 1 and 0 when assign value to a bool type
> > variable.
> Thanks Michael, I have added your patch to my queue of e1000e patches.

There are more of these uses in intel drivers.

Perhaps you could run this cocci/spatch
on drivers/net/ethernet/intel/...

$ cat bool.cocci
@@
bool b;
@@

-b = 0;
+b = false;

@@
bool b;
@@

-b = 1;
+b = true;

$ git ls-files drivers/net/ethernet/intel/ | grep "\.c$" | while read file ; do spatch -in_place -sp_file bool.cocci $file ; done


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael Wang Dec. 7, 2011, 4:49 a.m. UTC | #3
On 12/07/2011 12:14 PM, Joe Perches wrote:

> On Tue, 2011-12-06 at 19:43 -0800, Jeff Kirsher wrote:
>> On Tue, 2011-12-06 at 18:33 -0800, Michael Wang wrote:
>>> From: Michael Wang <wangyun@linux.vnet.ibm.com>
>>> Use true and false instead of 1 and 0 when assign value to a bool type
>>> variable.
>> Thanks Michael, I have added your patch to my queue of e1000e patches.
> 
> There are more of these uses in intel drivers.
> 
> Perhaps you could run this cocci/spatch
> on drivers/net/ethernet/intel/...
> 
> $ cat bool.cocci
> @@
> bool b;
> @@
> 
> -b = 0;
> +b = false;
> 
> @@
> bool b;
> @@
> 
> -b = 1;
> +b = true;
> 
> $ git ls-files drivers/net/ethernet/intel/ | grep "\.c$" | while read file ; do spatch -in_place -sp_file bool.cocci $file ; done
> 
> 

Hi, Joe

I think there are lots of such cases in kernel, and I think it is a
legacy issue with some story in it.

The reason I only change the e1000e is that the patch I send before will
broken the style of e1000e, because it's using true and false, not 1 and 0.

I think this will be a huge work if we want to correct all these cases,
and I think the good way is to separate the work to small pieces and
finish them slowly.

Thanks,
Michael Wang

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Joe Perches Dec. 7, 2011, 6:01 a.m. UTC | #4
On Wed, 2011-12-07 at 12:49 +0800, Michael Wang wrote:
> On 12/07/2011 12:14 PM, Joe Perches wrote:
> 
> > On Tue, 2011-12-06 at 19:43 -0800, Jeff Kirsher wrote:
> >> On Tue, 2011-12-06 at 18:33 -0800, Michael Wang wrote:
> >>> From: Michael Wang <wangyun@linux.vnet.ibm.com>
> >>> Use true and false instead of 1 and 0 when assign value to a bool type
> >>> variable.
> >> Thanks Michael, I have added your patch to my queue of e1000e patches.
> > 
> > There are more of these uses in intel drivers.
> > 
> > Perhaps you could run this cocci/spatch
> > on drivers/net/ethernet/intel/...
> > 
> > $ cat bool.cocci
> > @@
> > bool b;
> > @@
> > 
> > -b = 0;
> > +b = false;
> > 
> > @@
> > bool b;
> > @@
> > 
> > -b = 1;
> > +b = true;
> > 
> > $ git ls-files drivers/net/ethernet/intel/ | grep "\.c$" | while read file ; do spatch -in_place -sp_file bool.cocci $file ; done
> > 
> > 
> 
> Hi, Joe
> 
> I think there are lots of such cases in kernel, and I think it is a
> legacy issue with some story in it.

Actually, there are relatively few bool = 0|1; uses.

> The reason I only change the e1000e is that the patch I send before will
> broken the style of e1000e, because it's using true and false, not 1 and 0.

Scriptable fixes are easy.

> I think this will be a huge work if we want to correct all these cases,

Perhaps you're thinking of int uses that could be
converted to bool? There are a lot of those.

This is the diffstat I get for drivers/net/ethernet
for the current uses of bool foo = 0|1;

$ git diff --stat drivers/net
 drivers/net/ethernet/broadcom/tg3.c           |    8 ++++----
 drivers/net/ethernet/brocade/bna/bnad.c       |    4 ++--
 drivers/net/ethernet/dec/tulip/de4x5.c        |    4 ++--
 drivers/net/ethernet/intel/e1000/e1000_main.c |   10 +++++-----
 drivers/net/ethernet/intel/e1000e/netdev.c    |   16 ++++++++--------
 drivers/net/ethernet/intel/ixgb/ixgb_main.c   |    2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c  |    4 ++--
 drivers/net/ethernet/sfc/falcon.c             |    2 +-
 drivers/net/ethernet/sfc/mtd.c                |    6 +++---
 drivers/net/ethernet/tile/tilepro.c           |    4 ++--
 drivers/net/ethernet/xilinx/xilinx_emaclite.c |    4 ++--
 12 files changed, 33 insertions(+), 33 deletions(-)

> and I think the good way is to separate the work to small pieces and
> finish them slowly.

I think that's true for the int->bool conversions.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michael Wang Dec. 7, 2011, 6:08 a.m. UTC | #5
On 12/07/2011 02:01 PM, Joe Perches wrote:

> On Wed, 2011-12-07 at 12:49 +0800, Michael Wang wrote:
>> On 12/07/2011 12:14 PM, Joe Perches wrote:
>>
>>> On Tue, 2011-12-06 at 19:43 -0800, Jeff Kirsher wrote:
>>>> On Tue, 2011-12-06 at 18:33 -0800, Michael Wang wrote:
>>>>> From: Michael Wang <wangyun@linux.vnet.ibm.com>
>>>>> Use true and false instead of 1 and 0 when assign value to a bool type
>>>>> variable.
>>>> Thanks Michael, I have added your patch to my queue of e1000e patches.
>>>
>>> There are more of these uses in intel drivers.
>>>
>>> Perhaps you could run this cocci/spatch
>>> on drivers/net/ethernet/intel/...
>>>
>>> $ cat bool.cocci
>>> @@
>>> bool b;
>>> @@
>>>
>>> -b = 0;
>>> +b = false;
>>>
>>> @@
>>> bool b;
>>> @@
>>>
>>> -b = 1;
>>> +b = true;
>>>
>>> $ git ls-files drivers/net/ethernet/intel/ | grep "\.c$" | while read file ; do spatch -in_place -sp_file bool.cocci $file ; done
>>>
>>>
>>
>> Hi, Joe
>>
>> I think there are lots of such cases in kernel, and I think it is a
>> legacy issue with some story in it.
> 
> Actually, there are relatively few bool = 0|1; uses.
> 
>> The reason I only change the e1000e is that the patch I send before will
>> broken the style of e1000e, because it's using true and false, not 1 and 0.
> 
> Scriptable fixes are easy.

Hi, Joe

I'm not good at script, if you are interested, we can work together to
fix all the remain cases, and send out some patches.

Thanks,
Michael Wang

> 
>> I think this will be a huge work if we want to correct all these cases,
> 
> Perhaps you're thinking of int uses that could be
> converted to bool? There are a lot of those.
> 
> This is the diffstat I get for drivers/net/ethernet
> for the current uses of bool foo = 0|1;
> 
> $ git diff --stat drivers/net
>  drivers/net/ethernet/broadcom/tg3.c           |    8 ++++----
>  drivers/net/ethernet/brocade/bna/bnad.c       |    4 ++--
>  drivers/net/ethernet/dec/tulip/de4x5.c        |    4 ++--
>  drivers/net/ethernet/intel/e1000/e1000_main.c |   10 +++++-----
>  drivers/net/ethernet/intel/e1000e/netdev.c    |   16 ++++++++--------
>  drivers/net/ethernet/intel/ixgb/ixgb_main.c   |    2 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |    2 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c  |    4 ++--
>  drivers/net/ethernet/sfc/falcon.c             |    2 +-
>  drivers/net/ethernet/sfc/mtd.c                |    6 +++---
>  drivers/net/ethernet/tile/tilepro.c           |    4 ++--
>  drivers/net/ethernet/xilinx/xilinx_emaclite.c |    4 ++--
>  12 files changed, 33 insertions(+), 33 deletions(-)
> 
>> and I think the good way is to separate the work to small pieces and
>> finish them slowly.
> 
> I think that's true for the int->bool conversions.
> 


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c
b/drivers/net/ethernet/intel/e1000e/netdev.c
index a855db1..2e5e423 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -875,7 +875,7 @@  static bool e1000_clean_rx_irq(struct e1000_adapter
*adapter,
 	u32 length, staterr;
 	unsigned int i;
 	int cleaned_count = 0;
-	bool cleaned = 0;
+	bool cleaned = false;
 	unsigned int total_rx_bytes = 0, total_rx_packets = 0;