For reduce "if" condition, easy to read/understand the code,
optimize "if" condition in rx/tx processing.
Signed-off-by: Tomoya MORINAGA <[email protected]>
---
drivers/net/can/pch_can.c | 26 ++++++++++----------------
1 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
index 8efbe35..dcd8f00 100644
--- a/drivers/net/can/pch_can.c
+++ b/drivers/net/can/pch_can.c
@@ -746,19 +746,16 @@ static int pch_can_poll(struct napi_struct *napi, int quota)
if (int_stat == PCH_STATUS_INT) {
reg_stat = ioread32(&priv->regs->stat);
- if (reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) {
- if (reg_stat & PCH_BUS_OFF ||
- (reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL) {
- pch_can_error(ndev, reg_stat);
- quota--;
- }
- }
- if (reg_stat & PCH_TX_OK)
- pch_can_bit_clear(&priv->regs->stat, PCH_TX_OK);
+ if ((reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) &&
+ ((reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL)) {
+ pch_can_error(ndev, reg_stat);
+ quota--;
+ }
- if (reg_stat & PCH_RX_OK)
- pch_can_bit_clear(&priv->regs->stat, PCH_RX_OK);
+ if (reg_stat & (PCH_TX_OK | PCH_RX_OK))
+ pch_can_bit_clear(&priv->regs->stat,
+ reg_stat & (PCH_TX_OK | PCH_RX_OK));
int_stat = pch_can_int_pending(priv);
}
@@ -900,14 +897,13 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
if (can_dropped_invalid_skb(ndev, skb))
return NETDEV_TX_OK;
+ tx_obj_no = priv->tx_obj;
if (priv->tx_obj == PCH_TX_OBJ_END) {
if (ioread32(&priv->regs->treq2) & PCH_TREQ2_TX_MASK)
netif_stop_queue(ndev);
- tx_obj_no = priv->tx_obj;
priv->tx_obj = PCH_TX_OBJ_START;
} else {
- tx_obj_no = priv->tx_obj;
priv->tx_obj++;
}
@@ -926,9 +922,7 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
id2 |= PCH_ID_MSGVAL;
/* If remote frame has to be transmitted.. */
- if (cf->can_id & CAN_RTR_FLAG)
- id2 &= ~PCH_ID2_DIR;
- else
+ if (!(cf->can_id & CAN_RTR_FLAG))
id2 |= PCH_ID2_DIR;
iowrite32(id2, &priv->regs->ifregs[1].id2);
--
1.6.0.6
On 12/07/2010 12:11 PM, Tomoya MORINAGA wrote:
> For reduce "if" condition, easy to read/understand the code,
> optimize "if" condition in rx/tx processing.
>
> Signed-off-by: Tomoya MORINAGA <[email protected]>
Acked-by: Marc Kleine-Budde <[email protected]>
> ---
> drivers/net/can/pch_can.c | 26 ++++++++++----------------
> 1 files changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
> index 8efbe35..dcd8f00 100644
> --- a/drivers/net/can/pch_can.c
> +++ b/drivers/net/can/pch_can.c
> @@ -746,19 +746,16 @@ static int pch_can_poll(struct napi_struct *napi, int quota)
>
> if (int_stat == PCH_STATUS_INT) {
> reg_stat = ioread32(&priv->regs->stat);
> - if (reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) {
> - if (reg_stat & PCH_BUS_OFF ||
> - (reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL) {
> - pch_can_error(ndev, reg_stat);
> - quota--;
> - }
> - }
>
> - if (reg_stat & PCH_TX_OK)
> - pch_can_bit_clear(&priv->regs->stat, PCH_TX_OK);
> + if ((reg_stat & (PCH_BUS_OFF | PCH_LEC_ALL)) &&
> + ((reg_stat & PCH_LEC_ALL) != PCH_LEC_ALL)) {
> + pch_can_error(ndev, reg_stat);
> + quota--;
> + }
>
> - if (reg_stat & PCH_RX_OK)
> - pch_can_bit_clear(&priv->regs->stat, PCH_RX_OK);
> + if (reg_stat & (PCH_TX_OK | PCH_RX_OK))
> + pch_can_bit_clear(&priv->regs->stat,
> + reg_stat & (PCH_TX_OK | PCH_RX_OK));
>
> int_stat = pch_can_int_pending(priv);
> }
> @@ -900,14 +897,13 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
> if (can_dropped_invalid_skb(ndev, skb))
> return NETDEV_TX_OK;
>
> + tx_obj_no = priv->tx_obj;
> if (priv->tx_obj == PCH_TX_OBJ_END) {
> if (ioread32(&priv->regs->treq2) & PCH_TREQ2_TX_MASK)
> netif_stop_queue(ndev);
>
> - tx_obj_no = priv->tx_obj;
> priv->tx_obj = PCH_TX_OBJ_START;
> } else {
> - tx_obj_no = priv->tx_obj;
> priv->tx_obj++;
> }
>
> @@ -926,9 +922,7 @@ static netdev_tx_t pch_xmit(struct sk_buff *skb, struct net_device *ndev)
> id2 |= PCH_ID_MSGVAL;
>
> /* If remote frame has to be transmitted.. */
> - if (cf->can_id & CAN_RTR_FLAG)
> - id2 &= ~PCH_ID2_DIR;
> - else
> + if (!(cf->can_id & CAN_RTR_FLAG))
> id2 |= PCH_ID2_DIR;
>
> iowrite32(id2, &priv->regs->ifregs[1].id2);
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |