2012-09-07 06:51:48

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH] NFC: move the dereference below the NULL test

From: Wei Yongjun <[email protected]>

The dereference should be moved below the NULL test.

spatch with a semantic match is used to found this.
(http://coccinelle.lip6.fr/)

Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/nfc/nfcwilink.c | 4 ++--
drivers/nfc/pn544_hci.c | 3 ++-
drivers/nfc/pn544.c | 3 ++-
3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
index e7fd493..1a47190 100644
--- a/drivers/nfc/nfcwilink.c
+++ b/drivers/nfc/nfcwilink.c
@@ -352,8 +352,6 @@ static long nfcwilink_receive(void *priv_data, struct sk_buff *skb)
struct nfcwilink *drv = priv_data;
int rc;

- nfc_dev_dbg(&drv->pdev->dev, "receive entry, len %d", skb->len);
-
if (!skb)
return -EFAULT;

@@ -362,6 +360,8 @@ static long nfcwilink_receive(void *priv_data, struct sk_buff *skb)
return -EFAULT;
}

+ nfc_dev_dbg(&drv->pdev->dev, "receive entry, len %d", skb->len);
+
/* strip the ST header
(apart for the chnl byte, which is not received in the hdr) */
skb_pull(skb, (NFCWILINK_HDR_LEN-1));

diff --git a/drivers/nfc/pn544_hci.c b/drivers/nfc/pn544_hci.c
index aa71807..7b20f2d 100644
--- a/drivers/nfc/pn544_hci.c
+++ b/drivers/nfc/pn544_hci.c
@@ -341,13 +341,14 @@ flush:
static irqreturn_t pn544_hci_irq_thread_fn(int irq, void *dev_id)
{
struct pn544_hci_info *info = dev_id;
- struct i2c_client *client = info->i2c_dev;
+ struct i2c_client *client;
struct sk_buff *skb = NULL;
int r;

BUG_ON(!info);
BUG_ON(irq != info->i2c_dev->irq);

+ client = info->i2c_dev;
dev_dbg(&client->dev, "IRQ\n");

if (info->hard_fault != 0)

diff --git a/drivers/nfc/pn544.c b/drivers/nfc/pn544.c
index 724f65d..33696d6 100644
--- a/drivers/nfc/pn544.c
+++ b/drivers/nfc/pn544.c
@@ -288,11 +288,12 @@ static int pn544_fw_read(struct i2c_client *client, u8 *buf, int buflen)
static irqreturn_t pn544_irq_thread_fn(int irq, void *dev_id)
{
struct pn544_info *info = dev_id;
- struct i2c_client *client = info->i2c_dev;
+ struct i2c_client *client;

BUG_ON(!info);
BUG_ON(irq != info->i2c_dev->irq);

+ client = info->i2c_dev;
dev_dbg(&client->dev, "IRQ\n");

mutex_lock(&info->read_mutex);



2012-09-07 17:05:25

by Samuel Ortiz

[permalink] [raw]
Subject: Re: [PATCH] NFC: move the dereference below the NULL test

Hi Wei,

On Fri, Sep 07, 2012 at 02:51:47PM +0800, Wei Yongjun wrote:
> From: Wei Yongjun <[email protected]>
>
> The dereference should be moved below the NULL test.
>
> spatch with a semantic match is used to found this.
> (http://coccinelle.lip6.fr/)
>
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> drivers/nfc/nfcwilink.c | 4 ++--
> drivers/nfc/pn544_hci.c | 3 ++-
> drivers/nfc/pn544.c | 3 ++-
> 3 files changed, 6 insertions(+), 4 deletions(-)
Those are correct fixes but could you please split the nfcwilink and pn544_hci
fixes into 2 patches. Also, the pn544 driver is going to be removed so no need
to fix it.

Cheers,
Samuel.

--
Intel Open Source Technology Centre
http://oss.intel.com/