Skip to content

Commit c08eadc

Browse files
mudongliangHans Verkuil
authored andcommitted
media: em28xx: initialize refcount before kref_get
The commit 47677e5("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") adds kref_get to many init functions (e.g., em28xx_audio_init). However, kref_init is called too late in em28xx_usb_probe, since em28xx_init_dev before will invoke those init functions and call kref_get function. Then refcount bug occurs in my local syzkaller instance. Fix it by moving kref_init before em28xx_init_dev. This issue occurs not only in dev but also dev->dev_next. Fixes: 47677e5 ("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") Reported-by: syzkaller <[email protected]> Signed-off-by: Dongliang Mu <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent dca4f5f commit c08eadc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/media/usb/em28xx/em28xx-cards.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,6 +3936,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
39363936
goto err_free;
39373937
}
39383938

3939+
kref_init(&dev->ref);
3940+
39393941
dev->devno = nr;
39403942
dev->model = id->driver_info;
39413943
dev->alt = -1;
@@ -4036,6 +4038,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
40364038
}
40374039

40384040
if (dev->board.has_dual_ts && em28xx_duplicate_dev(dev) == 0) {
4041+
kref_init(&dev->dev_next->ref);
4042+
40394043
dev->dev_next->ts = SECONDARY_TS;
40404044
dev->dev_next->alt = -1;
40414045
dev->dev_next->is_audio_only = has_vendor_audio &&
@@ -4090,12 +4094,8 @@ static int em28xx_usb_probe(struct usb_interface *intf,
40904094
em28xx_write_reg(dev, 0x0b, 0x82);
40914095
mdelay(100);
40924096
}
4093-
4094-
kref_init(&dev->dev_next->ref);
40954097
}
40964098

4097-
kref_init(&dev->ref);
4098-
40994099
request_modules(dev);
41004100

41014101
/*

0 commit comments

Comments
 (0)