From patchwork Thu Aug 8 15:51:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylwester Nawrocki X-Patchwork-Id: 19635 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1V7SVI-0002fB-I6; Thu, 08 Aug 2013 17:51:56 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-7) with esmtp id 1V7SVG-0001M5-1O; Thu, 08 Aug 2013 17:51:56 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965899Ab3HHPvv (ORCPT + 1 other); Thu, 8 Aug 2013 11:51:51 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:19937 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965896Ab3HHPvt (ORCPT ); Thu, 8 Aug 2013 11:51:49 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MR700NVCYQ64TB0@mailout1.w1.samsung.com> for linux-media@vger.kernel.org; Thu, 08 Aug 2013 16:51:47 +0100 (BST) X-AuditID: cbfec7f4-b7f5f6d000000ff6-0f-5203be938958 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id AA.E0.04086.39EB3025; Thu, 08 Aug 2013 16:51:47 +0100 (BST) Received: from [106.116.147.32] by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MR700E8SYQBRTB0@eusync4.samsung.com>; Thu, 08 Aug 2013 16:51:47 +0100 (BST) Message-id: <5203BE92.1020100@samsung.com> Date: Thu, 08 Aug 2013 17:51:46 +0200 From: Sylwester Nawrocki User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-version: 1.0 To: Laurent Pinchart Cc: linux-media@vger.kernel.org, Guennadi Liakhovetski Subject: Re: [PATCH] V4L: async: Make sure subdevs are stored in a list before being moved References: <1375872115-32505-1-git-send-email-laurent.pinchart@ideasonboard.com> In-reply-to: <1375872115-32505-1-git-send-email-laurent.pinchart@ideasonboard.com> Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprHLMWRmVeSWpSXmKPExsVy+t/xa7qT9zEHGTydpGbxfuM8JovOiUvY LXo2bGV1YPb48DHOY3bHTFaPz5vkApijuGxSUnMyy1KL9O0SuDK23qwqaJesmHP3C3MD4yaR LkZODgkBE4m9P98wQ9hiEhfurWfrYuTiEBJYyihxbdU7ZgjnE6PEkSsbWECqeAW0JD7+n8AI YrMIqEpcefyCDcRmEzCU6D3aBxYXFQiQWLzkHDtEvaDEj8n3wHpFBCwkehdNB6thFvCTWHlt B1hcWCBGoufrTyYQW0ggGGjxP7AaToEQiatXjrFA1OtI7G+dxgZhy0tsXvOWeQKjwCwkK2Yh KZuFpGwBI/MqRtHU0uSC4qT0XEO94sTc4tK8dL3k/NxNjJAw/bKDcfExq0OMAhyMSjy8J7Yw BwmxJpYVV+YeYpTgYFYS4X2RBRTiTUmsrEotyo8vKs1JLT7EyMTBKdXAuNLxiOLf3HDuvZIO JrYWak/27rr/ZVLgCp/PzWqpmS88levbZT6+t/ztUqz9cxfvKUlWtx8VN7tjw4ISnp09y7/5 ZtzLP4KBnl+T62x5WJgXnZvm1P3LxCUs4tOLV3OK07b2fGhb8fjRPNd0vTNfpvKLyGfwTix4 9niLsMUTxc8dM9Qs818UKLEUZyQaajEXFScCANmJQOQxAgAA Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2013.8.8.153928 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __FORWARDED_MSG 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MOZILLA_MSGID 0, __MOZILLA_USER_AGENT 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __TO_MALFORMED_2 0, __URI_NO_WWW 0, __URI_NS , __USER_AGENT 0' Hi Laurent, On 08/07/2013 12:41 PM, Laurent Pinchart wrote: > Subdevices have an async_list field used to store them in the global > list of subdevices or in the notifier done lists. List entries are moved > from the former to the latter in v4l2_async_test_notify() using > list_move(). However, v4l2_async_test_notify() can be called right away > when the subdev is registered with v4l2_async_register_subdev(), in > which case the entry is not stored in any list. > > Although this behaviour is not correct, the code doesn't crash at the > moment as the async_list field is initialized as a list head, despite > being a list entry. > > Add the subdev to the global subdevs list a registration time before > matching them with the notifiers to make sure the list_move() call will > get a subdev that is stored in a list, and remove the list head > initialization for the subdev async_list field. > > Signed-off-by: Laurent Pinchart Shouldn't we initialize the async_list field in v4l2_subdev_init() ? > --- > drivers/media/v4l2-core/v4l2-async.c | 11 ++++++----- > 1 file changed, 6 insertions(+), 5 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c > index b350ab9..4485dfe 100644 > --- a/drivers/media/v4l2-core/v4l2-async.c > +++ b/drivers/media/v4l2-core/v4l2-async.c > @@ -122,7 +122,7 @@ static void v4l2_async_cleanup(struct v4l2_subdev *sd) > { > v4l2_device_unregister_subdev(sd); > /* Subdevice driver will reprobe and put the subdev back onto the list */ > - list_del_init(&sd->async_list); > + list_del(&sd->async_list); It is not safe to do so, since v4l2_async_cleanup() can be called multiple times and list_del() leaves async_list in an undefined state. I'm actually observing a crash with this change. > sd->asd = NULL; > sd->dev = NULL; > } > @@ -238,7 +238,11 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd) > > mutex_lock(&list_lock); > > - INIT_LIST_HEAD(&sd->async_list); > + /* > + * Add the subdev to the global subdevs list. It will be moved to the > + * notifier done list by v4l2_async_test_notify(). > + */ > + list_add(&sd->async_list, &subdev_list); > > list_for_each_entry(notifier, ¬ifier_list, list) { > struct v4l2_async_subdev *asd = v4l2_async_belongs(notifier, sd); > @@ -249,9 +253,6 @@ int v4l2_async_register_subdev(struct v4l2_subdev *sd) > } > } > > - /* None matched, wait for hot-plugging */ > - list_add(&sd->async_list, &subdev_list); > - > mutex_unlock(&list_lock); > > return 0; > Regards, Sylwester --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index 996c248..31b2375 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -460,6 +460,7 @@ EXPORT_SYMBOL_GPL(v4l2_subdev_link_validate); void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) { INIT_LIST_HEAD(&sd->list); + INIT_LIST_HEAD(&sd->async_list); BUG_ON(!ops); sd->ops = ops; sd->v4l2_dev = NULL;