Skip to content

Commit 7274496

Browse files
cricard13Samuel Ortiz
authored andcommitted
NFC: st21nfcb: Fix "NULL pointer dereference" possible error
When the platform with CONFIG_ST21NFCB_I2C=y without any st21nfcb component physically connected a: "Unable to handle kernel NULL pointer dereference at virtual address" may show up at driver initialization phase. Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent c490c55 commit 7274496

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

  • drivers/nfc/st21nfcb

‎drivers/nfc/st21nfcb/i2c.c‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static irqreturn_t st21nfcb_nci_irq_thread_fn(int irq, void *phy_id)
199199
struct sk_buff *skb = NULL;
200200
int r;
201201

202-
if (!phy || irq != phy->i2c_dev->irq) {
202+
if (!phy || !phy->ndlc || irq != phy->i2c_dev->irq) {
203203
WARN_ON_ONCE(1);
204204
return IRQ_NONE;
205205
}
@@ -343,18 +343,22 @@ static int st21nfcb_nci_i2c_probe(struct i2c_client *client,
343343
return -ENODEV;
344344
}
345345

346+
r = ndlc_probe(phy, &i2c_phy_ops, &client->dev,
347+
ST21NFCB_FRAME_HEADROOM, ST21NFCB_FRAME_TAILROOM,
348+
&phy->ndlc);
349+
if (r < 0) {
350+
nfc_err(&client->dev, "Unable to register ndlc layer\n");
351+
return r;
352+
}
353+
346354
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
347355
st21nfcb_nci_irq_thread_fn,
348356
phy->irq_polarity | IRQF_ONESHOT,
349357
ST21NFCB_NCI_DRIVER_NAME, phy);
350-
if (r < 0) {
358+
if (r < 0)
351359
nfc_err(&client->dev, "Unable to register IRQ handler\n");
352-
return r;
353-
}
354360

355-
return ndlc_probe(phy, &i2c_phy_ops, &client->dev,
356-
ST21NFCB_FRAME_HEADROOM, ST21NFCB_FRAME_TAILROOM,
357-
&phy->ndlc);
361+
return r;
358362
}
359363

360364
static int st21nfcb_nci_i2c_remove(struct i2c_client *client)

0 commit comments

Comments
 (0)