Skip to content

Commit 71d6454

Browse files
Ma KeNipaLocal
authored andcommitted
NFC: Fix error handling in nfc_genl_dump_targets
nfc_genl_dump_targets() increments the device reference count via nfc_get_device() but fails to decrement it properly. nfc_get_device() calls class_find_device() which internally calls get_device() to increment the reference count. No corresponding put_device() is made to decrement the reference count. Add proper reference count decrementing using nfc_put_device() when the dump operation completes or encounters an error, ensuring balanced reference counting. Found by code review. Cc: stable@vger.kernel.org Fixes: 4d12b8b ("NFC: add nfc generic netlink interface") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Signed-off-by: NipaLocal <nipa@local>
1 parent 794cd13 commit 71d6454

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

net/nfc/netlink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ static int nfc_genl_dump_targets(struct sk_buff *skb,
159159

160160
cb->args[0] = i;
161161

162+
if (rc < 0 || i >= dev->n_targets) {
163+
nfc_put_device(dev);
164+
cb->args[1] = 0;
165+
}
166+
162167
return skb->len;
163168
}
164169

0 commit comments

Comments
 (0)