Skip to content

Commit

Permalink
media: em28xx: initialize refcount before kref_get
Browse files Browse the repository at this point in the history
commit c08eadc upstream.

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 <syzkaller@googlegroups.com>
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[DP: drop changes related to dev->dev_next as second tuner functionality was added in 4.16]
Signed-off-by: Dragos-Marian Panait <dragos.panait@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Dongliang Mu authored and Greg Kroah-Hartman committed Sep 28, 2022
1 parent 7c308ec commit 1f6ab28
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/media/usb/em28xx/em28xx-cards.c
Original file line number Diff line number Diff line change
@@ -3644,6 +3644,8 @@ static int em28xx_usb_probe(struct usb_interface *interface,
goto err_free;
}

kref_init(&dev->ref);

dev->devno = nr;
dev->model = id->driver_info;
dev->alt = -1;
@@ -3730,8 +3732,6 @@ static int em28xx_usb_probe(struct usb_interface *interface,
dev->dvb_xfer_bulk ? "bulk" : "isoc");
}

kref_init(&dev->ref);

request_modules(dev);

/*

0 comments on commit 1f6ab28

Please sign in to comment.