From patchwork Fri Nov 27 10:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 333895 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 AC4FDC2D0E4 for ; Fri, 27 Nov 2020 10:10:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CBB0221FD for ; Fri, 27 Nov 2020 10:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725989AbgK0KKL (ORCPT ); Fri, 27 Nov 2020 05:10:11 -0500 Received: from retiisi.eu ([95.216.213.190]:44568 "EHLO hillosipuli.retiisi.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgK0KKK (ORCPT ); Fri, 27 Nov 2020 05:10:10 -0500 Received: from lanttu.localdomain (lanttu-e.localdomain [192.168.1.64]) by hillosipuli.retiisi.eu (Postfix) with ESMTP id F34BF634C24 for ; Fri, 27 Nov 2020 12:09:17 +0200 (EET) From: Sakari Ailus To: linux-media@vger.kernel.org Subject: [PATCH v2 1/1] v4l: subdev: Set sd->devnode before registering the subdev Date: Fri, 27 Nov 2020 12:05:26 +0200 Message-Id: <20201127100526.27652-1-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The subdev's video device node was only assigned after registering the device node in the system. While it is unlikely that a driver needed to use this field in handling system calls to its file handle, there remains a slim chance the devnode field remains NULL while the driver expects to find a video node there. Assign the devnode field before registering the device, and assign it back to NULL if the registration failed. Signed-off-by: Sakari Ailus Reviewed-by: Hans Verkuil --- I'm sending this separately from the rest of the serialisation set, after a rebase, as it makes sense without it, too. drivers/media/v4l2-core/v4l2-device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c index de4287251a89..d2e58ae91f9b 100644 --- a/drivers/media/v4l2-core/v4l2-device.c +++ b/drivers/media/v4l2-core/v4l2-device.c @@ -218,13 +218,14 @@ int __v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev, vdev->ctrl_handler = sd->ctrl_handler; if (read_only) set_bit(V4L2_FL_SUBDEV_RO_DEVNODE, &vdev->flags); + sd->devnode = vdev; err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1, sd->owner); if (err < 0) { + sd->devnode = NULL; kfree(vdev); goto clean_up; } - sd->devnode = vdev; #if defined(CONFIG_MEDIA_CONTROLLER) sd->entity.info.dev.major = VIDEO_MAJOR; sd->entity.info.dev.minor = vdev->minor;