OpenCloudOS-Kernel/include/media/media-dev-allocator.h

64 lines
2.2 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* media-dev-allocator.h - Media Controller Device Allocator API
*
* Copyright (c) 2019 Shuah Khan <shuah@kernel.org>
*
* Credits: Suggested by Laurent Pinchart <laurent.pinchart@ideasonboard.com>
*/
/*
* This file adds a global ref-counted Media Controller Device Instance API.
* A system wide global media device list is managed and each media device
* includes a kref count. The last put on the media device releases the media
* device instance.
*/
#ifndef _MEDIA_DEV_ALLOCATOR_H
#define _MEDIA_DEV_ALLOCATOR_H
struct usb_device;
media: Fix Media Controller API config checks Smatch static checker warns that "mdev" can be null: sound/usb/media.c:287 snd_media_device_create() warn: 'mdev' can also be NULL If CONFIG_MEDIA_CONTROLLER is disabled, this file should not be included in the build. The below conditions in the sound/usb/Makefile are in place to ensure that media.c isn't included in the build. sound/usb/Makefile: snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o select SND_USB_AUDIO_USE_MEDIA_CONTROLLER if MEDIA_CONTROLLER && (MEDIA_SUPPORT=y || MEDIA_SUPPORT=SND_USB_AUDIO) The following config check in include/media/media-dev-allocator.h is in place to enable the API only when CONFIG_MEDIA_CONTROLLER and CONFIG_USB are enabled. #if defined(CONFIG_MEDIA_CONTROLLER) && defined(CONFIG_USB) This check doesn't work as intended when CONFIG_USB=m. When CONFIG_USB=m, CONFIG_USB_MODULE is defined and CONFIG_USB is not. The above config check doesn't catch that CONFIG_USB is defined as a module and disables the API. This results in sound/usb enabling Media Controller specific ALSA driver code, while Media disables the Media Controller API. Fix the problem requires two changes: 1. Change the check to use IS_ENABLED to detect when CONFIG_USB is enabled as a module or static. Since CONFIG_MEDIA_CONTROLLER is a bool, leave the check unchanged to be consistent with drivers/media/Makefile. 2. Change the drivers/media/mc/Makefile to include mc-dev-allocator.o in mc-objs when CONFIG_USB is enabled. Link: https://lore.kernel.org/alsa-devel/YLeAvT+R22FQ%2FEyw@mwanda/ Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
2021-06-16 23:19:06 +08:00
#if defined(CONFIG_MEDIA_CONTROLLER) && IS_ENABLED(CONFIG_USB)
/**
* media_device_usb_allocate() - Allocate and return struct &media device
*
* @udev: struct &usb_device pointer
* @module_name: should be filled with %KBUILD_MODNAME
* @owner: struct module pointer %THIS_MODULE for the driver.
* %THIS_MODULE is null for a built-in driver.
* It is safe even when %THIS_MODULE is null.
*
* This interface should be called to allocate a Media Device when multiple
* drivers share usb_device and the media device. This interface allocates
* &media_device structure and calls media_device_usb_init() to initialize
* it.
*
*/
struct media_device *media_device_usb_allocate(struct usb_device *udev,
const char *module_name,
struct module *owner);
/**
* media_device_delete() - Release media device. Calls kref_put().
*
* @mdev: struct &media_device pointer
* @module_name: should be filled with %KBUILD_MODNAME
* @owner: struct module pointer %THIS_MODULE for the driver.
* %THIS_MODULE is null for a built-in driver.
* It is safe even when %THIS_MODULE is null.
*
* This interface should be called to put Media Device Instance kref.
*/
void media_device_delete(struct media_device *mdev, const char *module_name,
struct module *owner);
#else
static inline struct media_device *media_device_usb_allocate(
struct usb_device *udev, const char *module_name,
struct module *owner)
{ return NULL; }
static inline void media_device_delete(
struct media_device *mdev, const char *module_name,
struct module *owner) { }
#endif /* CONFIG_MEDIA_CONTROLLER && CONFIG_USB */
#endif /* _MEDIA_DEV_ALLOCATOR_H */