Skip to content

Commit

Permalink
NFC: digital: fix possible memory leak in digital_tg_listen_mdaa()
Browse files Browse the repository at this point in the history
'params' is allocated in digital_tg_listen_mdaa(), but not free when
digital_send_cmd() failed, which will cause memory leak. Fix it by
freeing 'params' if digital_send_cmd() return failed.

Fixes: 1c7a4c2 ("NFC Digital: Add target NFC-DEP support")
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Ziyang Xuan authored and Jakub Kicinski committed Oct 14, 2021
1 parent 0911ab3 commit 58e7dcc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions net/nfc/digital_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
{
struct digital_tg_mdaa_params *params;
int rc;

params = kzalloc(sizeof(*params), GFP_KERNEL);
if (!params)
Expand All @@ -291,8 +292,12 @@ static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2);
params->sc = DIGITAL_SENSF_FELICA_SC;

return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
500, digital_tg_recv_atr_req, NULL);
rc = digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
500, digital_tg_recv_atr_req, NULL);
if (rc)
kfree(params);

return rc;
}

static int digital_tg_listen_md(struct nfc_digital_dev *ddev, u8 rf_tech)
Expand Down

0 comments on commit 58e7dcc

Please sign in to comment.