From patchwork Fri Feb 26 22:49:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12107433 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E2AEC433E0 for ; Fri, 26 Feb 2021 22:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F26964EE2 for ; Fri, 26 Feb 2021 22:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229989AbhBZWuw (ORCPT ); Fri, 26 Feb 2021 17:50:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbhBZWuw (ORCPT ); Fri, 26 Feb 2021 17:50:52 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23ED1C061574; Fri, 26 Feb 2021 14:50:12 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C14F0580; Fri, 26 Feb 2021 23:50:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614379810; bh=9xbPoCselTfaNNlFq/iLq9ax7icwUScwxe77vp6/2sE=; h=From:To:Cc:Subject:Date:From; b=EgSG0elkYNBxRPWqVrss9X85CeI4D0IvYDkmaiVRjw55Exn3kCsdZJ42XbvBvOo2E vQhi0iYxnEXTN0P1KvZQYtBW9DRfAroJ4goAxmPkYuPpkvEZW8gZkVY+eYvjAE4l+K lss1SmybeDqocMBnZpA0K/+Prym5f8Kn4LGjiIGs= From: Laurent Pinchart To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus , linux-renesas-soc@vger.kernel.org, Laurent Pinchart Subject: [PATCH 1/2] list: Add list_is_null() to check if a list_head has been initialized Date: Sat, 27 Feb 2021 00:49:37 +0200 Message-Id: <20210226224938.18166-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Laurent Pinchart The new function checks if the list_head prev and next pointers are NULL, in order to see if a list_head that has been zeroed when allocated has been initialized with INIT_LIST_HEAD() or added to a list. This can be used in cleanup functions that want to support being safely called when an object has not been initialized, to return immediately. In most cases other fields of the object can be checked for this purpose, but in some cases a list_head field is the only option. Signed-off-by: Laurent Pinchart --- include/linux/list.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index 85c92555e31f..e4fc6954de3b 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -29,6 +29,19 @@ static inline void INIT_LIST_HEAD(struct list_head *list) list->prev = list; } +/** + * list_is_null - check if a list_head has been initialized + * @list: the list + * + * Check if the list_head prev and next pointers are NULL. This is useful to + * see if a list_head that has been zeroed when allocated has been initialized + * with INIT_LIST_HEAD() or added to a list. + */ +static inline bool list_is_null(struct list_head *list) +{ + return list->prev == NULL && list->next == NULL; +} + #ifdef CONFIG_DEBUG_LIST extern bool __list_add_valid(struct list_head *new, struct list_head *prev, From patchwork Fri Feb 26 22:49:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12107435 X-Patchwork-Delegate: kieran@bingham.xyz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 952DAC433E6 for ; Fri, 26 Feb 2021 22:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B89364F13 for ; Fri, 26 Feb 2021 22:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230001AbhBZWux (ORCPT ); Fri, 26 Feb 2021 17:50:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229863AbhBZWuw (ORCPT ); Fri, 26 Feb 2021 17:50:52 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3783DC06174A; Fri, 26 Feb 2021 14:50:12 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 591DB8C2; Fri, 26 Feb 2021 23:50:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1614379810; bh=m338KCSxr+6lpZlr2Hw3GyKsvcoDSYDUn5BOWKz1KzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XGNpWKYMilkBUWDLKCR5OqgNy1/6Lcm8j+/qgbnyPy66mYvzm/cw4fKO2nTzI5dww Dd9M1S0BeCnEnFXFt/+iYvEqFGH+l+1jZ/g2o1oNh9WGjdcCLUVtKSdYSFi4Venibf DJwojdd4uSOokY+cBFQjUSd6kKhok/6QN46Yf6d4= From: Laurent Pinchart To: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Sakari Ailus , linux-renesas-soc@vger.kernel.org, Laurent Pinchart Subject: [PATCH 2/2] media: v4l2-async: Safely unregister an non-registered async subdev Date: Sat, 27 Feb 2021 00:49:38 +0200 Message-Id: <20210226224938.18166-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210226224938.18166-1-laurent.pinchart@ideasonboard.com> References: <20210226224938.18166-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org From: Laurent Pinchart Make the V4L2 async framework a bit more robust by allowing to unregister a non-registered async subdev. Otherwise the v4l2_async_cleanup() will attempt to delete the async subdev from the subdev_list with the corresponding list_head not initialized. Signed-off-by: Laurent Pinchart Acked-by: Sakari Ailus --- drivers/media/v4l2-core/v4l2-async.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-async.c b/drivers/media/v4l2-core/v4l2-async.c index 37cc0263b273..2347b7ac54d4 100644 --- a/drivers/media/v4l2-core/v4l2-async.c +++ b/drivers/media/v4l2-core/v4l2-async.c @@ -750,6 +750,9 @@ EXPORT_SYMBOL(v4l2_async_register_subdev); void v4l2_async_unregister_subdev(struct v4l2_subdev *sd) { + if (list_is_null(&sd->async_list)) + return; + mutex_lock(&list_lock); __v4l2_async_notifier_unregister(sd->subdev_notifier);