From patchwork Tue Feb 2 14:49:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 374869 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=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 2E2ABC43381 for ; Tue, 2 Feb 2021 14:51:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DBD4764F4D for ; Tue, 2 Feb 2021 14:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234856AbhBBOvB (ORCPT ); Tue, 2 Feb 2021 09:51:01 -0500 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:56973 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234830AbhBBOuW (ORCPT ); Tue, 2 Feb 2021 09:50:22 -0500 Received: from cust-b5b5937f ([IPv6:fc0c:c16d:66b8:757f:c639:739b:9d66:799d]) by smtp-cloud7.xs4all.net with ESMTPA id 6wzel32bSefbk6wzilkQkT; Tue, 02 Feb 2021 15:49:30 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s2; t=1612277370; bh=UJOSA/AlptaPsHccog6qnCSI+XcbZdNBw0WGpS/T4qY=; h=From:To:Subject:Date:Message-Id:MIME-Version:From:Subject; b=sr1ynB0rRTJBocNf8sihu8U5WkLTM2BLXEAVC69giodxXLPmgSveGcmpISi1S94S1 jsyIy7XGGveoeypboQ0em1atYeX7EUlzzv8IQg/fO0PqRCBTgzp2r712GpqH6QsDP3 d230hA90lGfc2rotvlocoVwrP/cOFrVLOZf7lJQjTy8Rab2JGJO/WKdV09BGRXgKA/ 9m5mfNZ+m4+Z0pqQvaPuoLz7RKItkFQvXGDEVTDZ2A+vlVis/Jwpqw3MC0q/UK20Xn y9MdhrRvIF3TFdEAwb8JTbVVrU3upcmPEuNw8Pf6avIUDmiX99uFjUxkesiTBfjNWO gBaYfl+9xMgFQ== From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Sakari Ailus , Hans Verkuil Subject: [PATCHv3 2/4] media-device: add media_device_devt function Date: Tue, 2 Feb 2021 15:49:24 +0100 Message-Id: <20210202144926.620104-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210202144926.620104-1-hverkuil-cisco@xs4all.nl> References: <20210202144926.620104-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4xfO6uUqsrEFiRjNa9Fmoiux1SKkZGu29xct5yio4NBYpPxUio4i0ClHkEH02a0rxTf92NXZD4hF2cH/ag9FdD1gze7AtjVHLHAB3yg+lHDjYGKwwPGDrT G5p2XsTB3uYWbWk/WErBqoHJ6NF6Y5mxseZbJFg6kxOa/fxEPTiNWq6ahu3ujHYhehOSn2LxXwXk2ZbA75L9xKpKApdTHeq0l5lLbxV6uV5fv7frSNzKDyKJ gYxcYYObeIBrOe9/csgblz7hyWglNKCJAYGykC+U5YhRBi1uqnIZkdP62Fym9hI2CJYhNEwwoZWoCG0wT+chG5XpHV2OcDFRScXYzBJ7ypc= Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a helper function for use by the DVB and V4L2 core frameworks that safely returns the major and minor numbers of the media device node, or 0 if the device node is not registered. Signed-off-by: Hans Verkuil --- drivers/media/mc/mc-device.c | 16 ++++++++++++++++ include/media/media-device.h | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c index 9e56d2ad6b94..2207f1b01456 100644 --- a/drivers/media/mc/mc-device.c +++ b/drivers/media/mc/mc-device.c @@ -850,6 +850,22 @@ void media_device_unregister(struct media_device *mdev) } EXPORT_SYMBOL_GPL(media_device_unregister); +dev_t media_device_devt(struct media_device *mdev) +{ + dev_t devt = 0; + + if (!mdev) + return 0; + + mutex_lock(&mdev->graph_mutex); + /* Check if mdev is registered */ + if (media_devnode_is_registered(mdev->devnode)) + devt = mdev->devnode->dev.devt; + mutex_unlock(&mdev->graph_mutex); + return devt; +} +EXPORT_SYMBOL_GPL(media_device_devt); + #if IS_ENABLED(CONFIG_PCI) void media_device_pci_init(struct media_device *mdev, struct pci_dev *pci_dev, diff --git a/include/media/media-device.h b/include/media/media-device.h index 1345e6da688a..af089b1c55ef 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -300,6 +300,16 @@ int __must_check __media_device_register(struct media_device *mdev, */ void media_device_unregister(struct media_device *mdev); +/** + * media_device_devt() - return media device major/minor numbers + * + * @mdev: pointer to struct &media_device + * + * Returns 0 if the media device node is not registered, otherwise + * it will return the major/minor number of the media device node. + */ +dev_t media_device_devt(struct media_device *mdev); + /** * media_device_register_entity() - registers a media entity inside a * previously registered media device.