Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp73108iof; Sun, 5 Jun 2022 21:31:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4/uUC4GWx5zMajdqbDJjWJqba5zCS+k9P32YMo2ppsYiHcrtVnw9zxG5R/gmimQiS2L65 X-Received: by 2002:a17:902:d584:b0:167:6ab9:b094 with SMTP id k4-20020a170902d58400b001676ab9b094mr8745426plh.16.1654489872932; Sun, 05 Jun 2022 21:31:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654489872; cv=none; d=google.com; s=arc-20160816; b=yyq4z5etGV4wghPYPgIG8KDI8xQ+QUG2Qzy/qs4hR/DC/EqYPpj1nyM3WB8xdKXnUt e+tOBbgZa/UTCzJ2s1wmeK/8s06ZCnyl+/XZMt62hmhsb8mUTHq6e7SUWhelOEhcBPAS EngbSiqWqSj9dfCJCkfZV0HnCHHBvhFeYAThXjB7SWy0CoqomtMNOsdBO6BKakf84U+k 6HQIf8L93tslKwEpUTaEOdVJrPpBXcKpa3odX5ZG+z2uSu2KsRwL0aEZYrOuWCrrNJnN mvbCnjzz6uOhl3VyIEq64keqHoXKLhr+BcNr8b9Wo2nr74jaOsJBP+tETkkcQWK+Okbp Dw3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NrOxou2U7Qe2/pLwL4KzheML6d+vsoju3KvB0eqEAYI=; b=l4JdJb+p7ZHqgbdUc32Sayfyya1cSRYUjmN7drZHcScRbbcSi4Xm6LKGN7pCXkPfx5 5VlDk2Fdqa4yK4C8dgwuGQvkLF1M8UodpdXkXZDzA2j4wJOnI9w++ugWveZ45f+xLqhY kqAZWJLWlu52JSXma5C8Slz3OM+tBChpMUSk7FYHBll2ubRMKmfegPS4foGpCLZUKFf/ uqRm0VXPkscuZJ/whBLckuIL73VjEwosZ2aKebndQy+QHDDF/JmujGKvyg8Vhs0zcJKX vfFLCZh4f2LItbgZ4owjOm0uCDBObAxZSIV0O0MiEWJgJOuQfswTF+C9BfE/HKv8OyFR +cwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M3rAhdjl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h28-20020aa79f5c000000b004fa3a8e005dsi18128293pfr.276.2022.06.05.21.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:31:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M3rAhdjl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9B9901055E; Sun, 5 Jun 2022 20:57:50 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345174AbiFCRsc (ORCPT + 99 others); Fri, 3 Jun 2022 13:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345186AbiFCRsH (ORCPT ); Fri, 3 Jun 2022 13:48:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0069253B5F; Fri, 3 Jun 2022 10:44:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B0951B82435; Fri, 3 Jun 2022 17:44:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB3B3C385A9; Fri, 3 Jun 2022 17:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278280; bh=eWjvNjzueHkRt9//1aAFhyP98DhCROAeyazCCvxs2UA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M3rAhdjlZib/uceFill+PWvjnm6oNqSCP5TA+JpkG0w9w8XhpcPo3THkp9SKjNECR oTQEdGozk8TXENWDxGFQMh/sRjBN/zW84pwBhWM+nFZfe+bJg+mrm9+90/1vOFswI3 nVJv8Fr146U8jMBK52c6ClIngXR9lxaiiWEJk6wY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sakari Ailus , Hans Verkuil , Mauro Carvalho Chehab , Mark-PK Tsai Subject: [PATCH 5.4 07/34] media: vim2m: Register video device after setting up internals Date: Fri, 3 Jun 2022 19:43:03 +0200 Message-Id: <20220603173816.210307047@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173815.990072516@linuxfoundation.org> References: <20220603173815.990072516@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sakari Ailus commit cf7f34777a5b4100a3a44ff95f3d949c62892bdd upstream. Prevent NULL (or close to NULL) pointer dereference in various places by registering the video device only when the V4L2 m2m framework has been set up. Fixes: commit 96d8eab5d0a1 ("V4L/DVB: [v5,2/2] v4l: Add a mem-to-mem videobuf framework test device") Signed-off-by: Sakari Ailus Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Mark-PK Tsai Signed-off-by: Greg Kroah-Hartman --- drivers/media/platform/vim2m.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) --- a/drivers/media/platform/vim2m.c +++ b/drivers/media/platform/vim2m.c @@ -1333,12 +1333,6 @@ static int vim2m_probe(struct platform_d vfd->lock = &dev->dev_mutex; vfd->v4l2_dev = &dev->v4l2_dev; - ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); - if (ret) { - v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); - goto error_v4l2; - } - video_set_drvdata(vfd, dev); v4l2_info(&dev->v4l2_dev, "Device registered as /dev/video%d\n", vfd->num); @@ -1353,6 +1347,12 @@ static int vim2m_probe(struct platform_d goto error_dev; } + ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0); + if (ret) { + v4l2_err(&dev->v4l2_dev, "Failed to register video device\n"); + goto error_m2m; + } + #ifdef CONFIG_MEDIA_CONTROLLER dev->mdev.dev = &pdev->dev; strscpy(dev->mdev.model, "vim2m", sizeof(dev->mdev.model)); @@ -1366,7 +1366,7 @@ static int vim2m_probe(struct platform_d MEDIA_ENT_F_PROC_VIDEO_SCALER); if (ret) { v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem media controller\n"); - goto error_dev; + goto error_v4l2; } ret = media_device_register(&dev->mdev); @@ -1381,11 +1381,13 @@ static int vim2m_probe(struct platform_d error_m2m_mc: v4l2_m2m_unregister_media_controller(dev->m2m_dev); #endif -error_dev: +error_v4l2: video_unregister_device(&dev->vfd); /* vim2m_device_release called by video_unregister_device to release various objects */ return ret; -error_v4l2: +error_m2m: + v4l2_m2m_release(dev->m2m_dev); +error_dev: v4l2_device_unregister(&dev->v4l2_dev); error_free: kfree(dev);