media: i2c: max9286: Allocate v4l2_async_subdev dynamically
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tue, 11 Aug 2020 20:59:39 +0000 (22:59 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 10 Sep 2020 12:27:46 +0000 (14:27 +0200)
commit86d37bf31af647760f1f17e7c1afa1bdba075198
tree8392ebbc5c5eb672db5c5c248f95433a6ab0b028
parent2cac7cbfb4099980e78244359ab9c6f056d6a7ec
media: i2c: max9286: Allocate v4l2_async_subdev dynamically

v4l2_async_notifier_add_subdev() requires the asd to be allocated
dynamically, but the max9286 driver embeds it in the max9286_source
structure. This causes memory corruption when the notifier is destroyed
at remove time with v4l2_async_notifier_cleanup().

Fix this issue by registering the asd with
v4l2_async_notifier_add_fwnode_subdev(), which allocates it dynamically
internally. A new max9286_asd structure is introduced, to store a
pointer to the corresonding max9286_source that needs to be accessed
from bound and unbind callbacks. There's no need to take an extra
explicit reference to the fwnode anymore as
v4l2_async_notifier_add_fwnode_subdev() does so internally.

While at it, use %u instead of %d to print the unsigned index in the
error message from the v4l2_async_notifier_add_fwnode_subdev() error
path.

Fixes: 66d8c9d2422d ("media: i2c: Add MAX9286 driver")
Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/i2c/max9286.c