2009-12-09 19:39:58 +08:00
|
|
|
/*
|
|
|
|
* Media device
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
|
|
|
|
* Sakari Ailus <sakari.ailus@iki.fi>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2016-03-05 18:13:39 +08:00
|
|
|
/* We need to access legacy defines from linux/media.h */
|
|
|
|
#define __NEED_MEDIA_LEGACY_API
|
|
|
|
|
2013-01-22 23:27:56 +08:00
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <linux/export.h>
|
2015-12-16 21:32:17 +08:00
|
|
|
#include <linux/idr.h>
|
2009-12-09 19:39:58 +08:00
|
|
|
#include <linux/ioctl.h>
|
2010-08-18 22:41:22 +08:00
|
|
|
#include <linux/media.h>
|
[media] media: convert links from array to list
The entire logic that represent graph links were developed on a
time where there were no needs to dynamic remove links. So,
although links are created/removed one by one via some
functions, they're stored as an array inside the entity struct.
As the array may grow, there's a logic inside the code that
checks if the amount of space is not enough to store
the needed links. If it isn't the core uses krealloc()
to change the size of the link, with is bad, as it
leaves the memory fragmented.
So, convert links into a list.
Also, currently, both source and sink entities need the link
at the graph traversal logic inside media_entity. So there's
a logic duplicating all links. That makes it to spend
twice the memory needed. This is not a big deal for today's
usage, where the number of links are not big.
Yet, if during the MC workshop discussions, it was said that
IIO graphs could have up to 4,000 entities. So, we may
want to remove the duplication on some future. The problem
is that it would require a separate linked list to store
the backlinks inside the entity, or to use a more complex
algorithm to do graph backlink traversal, with is something
that the current graph traversal inside the core can't cope
with. So, let's postpone a such change if/when it is actually
needed.
It should also be noticed that the media_link structure uses
44 bytes on 32-bit architectures and 84 bytes on 64-bit
architecture. It will thus be allocated out of the 64-bytes and
96-bytes pools respectively. That's a 12.5% memory waste on
64-bit architectures and 31.25% on 32-bit architecture.
A linked list is less efficient than an array in this case, but
this could later be optimized if we can get rid of the reverse
links (with would reduce memory allocation by 50%).
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2015-08-07 17:55:40 +08:00
|
|
|
#include <linux/slab.h>
|
2015-12-11 17:23:09 +08:00
|
|
|
#include <linux/types.h>
|
2016-02-22 22:42:04 +08:00
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/usb.h>
|
2009-12-09 19:39:58 +08:00
|
|
|
|
|
|
|
#include <media/media-device.h>
|
|
|
|
#include <media/media-devnode.h>
|
2009-12-09 19:40:00 +08:00
|
|
|
#include <media/media-entity.h>
|
2009-12-09 19:39:58 +08:00
|
|
|
|
2015-06-06 04:11:54 +08:00
|
|
|
#ifdef CONFIG_MEDIA_CONTROLLER
|
|
|
|
|
2010-08-18 22:41:22 +08:00
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Userspace API
|
|
|
|
*/
|
|
|
|
|
2016-02-23 04:47:04 +08:00
|
|
|
static inline void __user *media_get_uptr(__u64 arg)
|
|
|
|
{
|
|
|
|
return (void __user *)(uintptr_t)arg;
|
|
|
|
}
|
|
|
|
|
2010-08-18 22:41:22 +08:00
|
|
|
static int media_device_open(struct file *filp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int media_device_close(struct file *filp)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int media_device_get_info(struct media_device *dev,
|
2016-05-04 05:42:13 +08:00
|
|
|
struct media_device_info *info)
|
2010-08-18 22:41:22 +08:00
|
|
|
{
|
2016-05-04 05:42:13 +08:00
|
|
|
memset(info, 0, sizeof(*info));
|
2010-08-18 22:41:22 +08:00
|
|
|
|
2016-02-12 00:24:23 +08:00
|
|
|
if (dev->driver_name[0])
|
2016-05-04 05:42:13 +08:00
|
|
|
strlcpy(info->driver, dev->driver_name, sizeof(info->driver));
|
2016-02-12 00:24:23 +08:00
|
|
|
else
|
2016-05-04 05:42:13 +08:00
|
|
|
strlcpy(info->driver, dev->dev->driver->name,
|
|
|
|
sizeof(info->driver));
|
2016-02-12 00:24:23 +08:00
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
strlcpy(info->model, dev->model, sizeof(info->model));
|
|
|
|
strlcpy(info->serial, dev->serial, sizeof(info->serial));
|
|
|
|
strlcpy(info->bus_info, dev->bus_info, sizeof(info->bus_info));
|
2010-08-18 22:41:22 +08:00
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
info->media_version = MEDIA_API_VERSION;
|
|
|
|
info->hw_revision = dev->hw_revision;
|
|
|
|
info->driver_version = dev->driver_version;
|
2010-08-18 22:41:22 +08:00
|
|
|
|
2012-08-07 16:24:59 +08:00
|
|
|
return 0;
|
2010-08-18 22:41:22 +08:00
|
|
|
}
|
|
|
|
|
2009-12-09 19:40:01 +08:00
|
|
|
static struct media_entity *find_entity(struct media_device *mdev, u32 id)
|
|
|
|
{
|
|
|
|
struct media_entity *entity;
|
|
|
|
int next = id & MEDIA_ENT_ID_FLAG_NEXT;
|
|
|
|
|
|
|
|
id &= ~MEDIA_ENT_ID_FLAG_NEXT;
|
|
|
|
|
|
|
|
media_device_for_each_entity(entity, mdev) {
|
2015-08-14 21:42:05 +08:00
|
|
|
if (((media_entity_id(entity) == id) && !next) ||
|
|
|
|
((media_entity_id(entity) > id) && next)) {
|
2009-12-09 19:40:01 +08:00
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long media_device_enum_entities(struct media_device *mdev,
|
2016-05-04 05:42:13 +08:00
|
|
|
struct media_entity_desc *entd)
|
2009-12-09 19:40:01 +08:00
|
|
|
{
|
|
|
|
struct media_entity *ent;
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
ent = find_entity(mdev, entd->id);
|
2009-12-09 19:40:01 +08:00
|
|
|
if (ent == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
memset(entd, 0, sizeof(*entd));
|
|
|
|
|
|
|
|
entd->id = media_entity_id(ent);
|
2014-07-17 19:52:08 +08:00
|
|
|
if (ent->name)
|
2016-05-04 05:42:13 +08:00
|
|
|
strlcpy(entd->name, ent->name, sizeof(entd->name));
|
|
|
|
entd->type = ent->function;
|
|
|
|
entd->revision = 0; /* Unused */
|
|
|
|
entd->flags = ent->flags;
|
|
|
|
entd->group_id = 0; /* Unused */
|
|
|
|
entd->pads = ent->num_pads;
|
|
|
|
entd->links = ent->num_links - ent->num_backlinks;
|
2016-03-05 18:13:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Workaround for a bug at media-ctl <= v1.10 that makes it to
|
|
|
|
* do the wrong thing if the entity function doesn't belong to
|
|
|
|
* either MEDIA_ENT_F_OLD_BASE or MEDIA_ENT_F_OLD_SUBDEV_BASE
|
|
|
|
* Ranges.
|
|
|
|
*
|
|
|
|
* Non-subdevices are expected to be at the MEDIA_ENT_F_OLD_BASE,
|
|
|
|
* or, otherwise, will be silently ignored by media-ctl when
|
|
|
|
* printing the graphviz diagram. So, map them into the devnode
|
|
|
|
* old range.
|
|
|
|
*/
|
|
|
|
if (ent->function < MEDIA_ENT_F_OLD_BASE ||
|
|
|
|
ent->function > MEDIA_ENT_T_DEVNODE_UNKNOWN) {
|
|
|
|
if (is_media_entity_v4l2_subdev(ent))
|
2016-05-04 05:42:13 +08:00
|
|
|
entd->type = MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN;
|
2016-03-05 18:13:39 +08:00
|
|
|
else if (ent->function != MEDIA_ENT_F_IO_V4L)
|
2016-05-04 05:42:13 +08:00
|
|
|
entd->type = MEDIA_ENT_T_DEVNODE_UNKNOWN;
|
2016-03-05 18:13:39 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
memcpy(&entd->raw, &ent->info, sizeof(ent->info));
|
|
|
|
|
2009-12-09 19:40:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void media_device_kpad_to_upad(const struct media_pad *kpad,
|
|
|
|
struct media_pad_desc *upad)
|
|
|
|
{
|
2015-08-14 21:42:05 +08:00
|
|
|
upad->entity = media_entity_id(kpad->entity);
|
2009-12-09 19:40:01 +08:00
|
|
|
upad->index = kpad->index;
|
|
|
|
upad->flags = kpad->flags;
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
static long media_device_enum_links(struct media_device *mdev,
|
|
|
|
struct media_links_enum *links)
|
2009-12-09 19:40:01 +08:00
|
|
|
{
|
|
|
|
struct media_entity *entity;
|
|
|
|
|
2013-01-22 23:27:56 +08:00
|
|
|
entity = find_entity(mdev, links->entity);
|
2009-12-09 19:40:01 +08:00
|
|
|
if (entity == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-01-22 23:27:56 +08:00
|
|
|
if (links->pads) {
|
2009-12-09 19:40:01 +08:00
|
|
|
unsigned int p;
|
|
|
|
|
|
|
|
for (p = 0; p < entity->num_pads; p++) {
|
|
|
|
struct media_pad_desc pad;
|
2013-04-13 17:32:15 +08:00
|
|
|
|
|
|
|
memset(&pad, 0, sizeof(pad));
|
2009-12-09 19:40:01 +08:00
|
|
|
media_device_kpad_to_upad(&entity->pads[p], &pad);
|
2013-01-22 23:27:56 +08:00
|
|
|
if (copy_to_user(&links->pads[p], &pad, sizeof(pad)))
|
2009-12-09 19:40:01 +08:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-22 23:27:56 +08:00
|
|
|
if (links->links) {
|
2015-12-11 17:25:01 +08:00
|
|
|
struct media_link *link;
|
|
|
|
struct media_link_desc __user *ulink_desc = links->links;
|
2009-12-09 19:40:01 +08:00
|
|
|
|
2015-12-11 17:25:01 +08:00
|
|
|
list_for_each_entry(link, &entity->links, list) {
|
|
|
|
struct media_link_desc klink_desc;
|
2009-12-09 19:40:01 +08:00
|
|
|
|
|
|
|
/* Ignore backlinks. */
|
2015-12-11 17:25:01 +08:00
|
|
|
if (link->source->entity != entity)
|
2009-12-09 19:40:01 +08:00
|
|
|
continue;
|
2015-12-11 17:25:01 +08:00
|
|
|
memset(&klink_desc, 0, sizeof(klink_desc));
|
|
|
|
media_device_kpad_to_upad(link->source,
|
|
|
|
&klink_desc.source);
|
|
|
|
media_device_kpad_to_upad(link->sink,
|
|
|
|
&klink_desc.sink);
|
|
|
|
klink_desc.flags = link->flags;
|
|
|
|
if (copy_to_user(ulink_desc, &klink_desc,
|
|
|
|
sizeof(*ulink_desc)))
|
2009-12-09 19:40:01 +08:00
|
|
|
return -EFAULT;
|
2015-12-11 17:25:01 +08:00
|
|
|
ulink_desc++;
|
2009-12-09 19:40:01 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-22 23:27:56 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-09 19:40:03 +08:00
|
|
|
static long media_device_setup_link(struct media_device *mdev,
|
2016-05-04 05:42:13 +08:00
|
|
|
struct media_link_desc *linkd)
|
2009-12-09 19:40:03 +08:00
|
|
|
{
|
|
|
|
struct media_link *link = NULL;
|
|
|
|
struct media_entity *source;
|
|
|
|
struct media_entity *sink;
|
|
|
|
|
|
|
|
/* Find the source and sink entities and link.
|
|
|
|
*/
|
2016-05-04 05:42:13 +08:00
|
|
|
source = find_entity(mdev, linkd->source.entity);
|
|
|
|
sink = find_entity(mdev, linkd->sink.entity);
|
2009-12-09 19:40:03 +08:00
|
|
|
|
|
|
|
if (source == NULL || sink == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
if (linkd->source.index >= source->num_pads ||
|
|
|
|
linkd->sink.index >= sink->num_pads)
|
2009-12-09 19:40:03 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
link = media_entity_find_link(&source->pads[linkd->source.index],
|
|
|
|
&sink->pads[linkd->sink.index]);
|
2009-12-09 19:40:03 +08:00
|
|
|
if (link == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Setup the link on both entities. */
|
2016-05-04 05:42:13 +08:00
|
|
|
return __media_entity_setup_link(link, linkd->flags);
|
2009-12-09 19:40:03 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
static long media_device_get_topology(struct media_device *mdev,
|
2015-08-23 21:36:41 +08:00
|
|
|
struct media_v2_topology *topo)
|
|
|
|
{
|
|
|
|
struct media_entity *entity;
|
|
|
|
struct media_interface *intf;
|
|
|
|
struct media_pad *pad;
|
|
|
|
struct media_link *link;
|
2016-02-23 04:47:03 +08:00
|
|
|
struct media_v2_entity kentity, __user *uentity;
|
|
|
|
struct media_v2_interface kintf, __user *uintf;
|
|
|
|
struct media_v2_pad kpad, __user *upad;
|
|
|
|
struct media_v2_link klink, __user *ulink;
|
2015-09-09 19:23:51 +08:00
|
|
|
unsigned int i;
|
|
|
|
int ret = 0;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
|
|
|
topo->topology_version = mdev->topology_version;
|
|
|
|
|
|
|
|
/* Get entities and number of entities */
|
|
|
|
i = 0;
|
2015-12-12 02:07:57 +08:00
|
|
|
uentity = media_get_uptr(topo->ptr_entities);
|
2015-08-23 21:36:41 +08:00
|
|
|
media_device_for_each_entity(entity, mdev) {
|
|
|
|
i++;
|
2015-12-12 02:07:57 +08:00
|
|
|
if (ret || !uentity)
|
2015-08-23 21:36:41 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i > topo->num_entities) {
|
|
|
|
ret = -ENOSPC;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy fields to userspace struct if not error */
|
2015-12-12 02:07:57 +08:00
|
|
|
memset(&kentity, 0, sizeof(kentity));
|
|
|
|
kentity.id = entity->graph_obj.id;
|
|
|
|
kentity.function = entity->function;
|
|
|
|
strncpy(kentity.name, entity->name,
|
|
|
|
sizeof(kentity.name));
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
if (copy_to_user(uentity, &kentity, sizeof(kentity)))
|
2015-08-23 21:36:41 +08:00
|
|
|
ret = -EFAULT;
|
2015-12-12 02:07:57 +08:00
|
|
|
uentity++;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
topo->num_entities = i;
|
|
|
|
|
|
|
|
/* Get interfaces and number of interfaces */
|
|
|
|
i = 0;
|
2015-12-12 02:07:57 +08:00
|
|
|
uintf = media_get_uptr(topo->ptr_interfaces);
|
2015-08-23 21:36:41 +08:00
|
|
|
media_device_for_each_intf(intf, mdev) {
|
|
|
|
i++;
|
2015-12-12 02:07:57 +08:00
|
|
|
if (ret || !uintf)
|
2015-08-23 21:36:41 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i > topo->num_interfaces) {
|
|
|
|
ret = -ENOSPC;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
memset(&kintf, 0, sizeof(kintf));
|
2015-08-23 21:36:41 +08:00
|
|
|
|
|
|
|
/* Copy intf fields to userspace struct */
|
2015-12-12 02:07:57 +08:00
|
|
|
kintf.id = intf->graph_obj.id;
|
|
|
|
kintf.intf_type = intf->type;
|
|
|
|
kintf.flags = intf->flags;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
|
|
|
if (media_type(&intf->graph_obj) == MEDIA_GRAPH_INTF_DEVNODE) {
|
|
|
|
struct media_intf_devnode *devnode;
|
|
|
|
|
|
|
|
devnode = intf_to_devnode(intf);
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
kintf.devnode.major = devnode->major;
|
|
|
|
kintf.devnode.minor = devnode->minor;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
if (copy_to_user(uintf, &kintf, sizeof(kintf)))
|
2015-08-23 21:36:41 +08:00
|
|
|
ret = -EFAULT;
|
2015-12-12 02:07:57 +08:00
|
|
|
uintf++;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
topo->num_interfaces = i;
|
|
|
|
|
|
|
|
/* Get pads and number of pads */
|
|
|
|
i = 0;
|
2015-12-12 02:07:57 +08:00
|
|
|
upad = media_get_uptr(topo->ptr_pads);
|
2015-08-23 21:36:41 +08:00
|
|
|
media_device_for_each_pad(pad, mdev) {
|
|
|
|
i++;
|
2015-12-12 02:07:57 +08:00
|
|
|
if (ret || !upad)
|
2015-08-23 21:36:41 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i > topo->num_pads) {
|
|
|
|
ret = -ENOSPC;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
memset(&kpad, 0, sizeof(kpad));
|
2015-08-23 21:36:41 +08:00
|
|
|
|
|
|
|
/* Copy pad fields to userspace struct */
|
2015-12-12 02:07:57 +08:00
|
|
|
kpad.id = pad->graph_obj.id;
|
|
|
|
kpad.entity_id = pad->entity->graph_obj.id;
|
|
|
|
kpad.flags = pad->flags;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
if (copy_to_user(upad, &kpad, sizeof(kpad)))
|
2015-08-23 21:36:41 +08:00
|
|
|
ret = -EFAULT;
|
2015-12-12 02:07:57 +08:00
|
|
|
upad++;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
topo->num_pads = i;
|
|
|
|
|
|
|
|
/* Get links and number of links */
|
|
|
|
i = 0;
|
2015-12-12 02:07:57 +08:00
|
|
|
ulink = media_get_uptr(topo->ptr_links);
|
2015-08-23 21:36:41 +08:00
|
|
|
media_device_for_each_link(link, mdev) {
|
2015-08-30 20:53:57 +08:00
|
|
|
if (link->is_backlink)
|
|
|
|
continue;
|
|
|
|
|
2015-08-23 21:36:41 +08:00
|
|
|
i++;
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
if (ret || !ulink)
|
2015-08-23 21:36:41 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (i > topo->num_links) {
|
|
|
|
ret = -ENOSPC;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
memset(&klink, 0, sizeof(klink));
|
2015-08-23 21:36:41 +08:00
|
|
|
|
|
|
|
/* Copy link fields to userspace struct */
|
2015-12-12 02:07:57 +08:00
|
|
|
klink.id = link->graph_obj.id;
|
|
|
|
klink.source_id = link->gobj0->id;
|
|
|
|
klink.sink_id = link->gobj1->id;
|
|
|
|
klink.flags = link->flags;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2015-12-12 02:07:57 +08:00
|
|
|
if (copy_to_user(ulink, &klink, sizeof(klink)))
|
2015-08-23 21:36:41 +08:00
|
|
|
ret = -EFAULT;
|
2015-12-12 02:07:57 +08:00
|
|
|
ulink++;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
topo->num_links = i;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
static long copy_arg_from_user(void *karg, void __user *uarg, unsigned int cmd)
|
2015-08-23 21:36:41 +08:00
|
|
|
{
|
2016-05-04 05:42:13 +08:00
|
|
|
/* All media IOCTLs are _IOWR() */
|
|
|
|
if (copy_from_user(karg, uarg, _IOC_SIZE(cmd)))
|
2015-12-15 19:00:40 +08:00
|
|
|
return -EFAULT;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
static long copy_arg_to_user(void __user *uarg, void *karg, unsigned int cmd)
|
|
|
|
{
|
|
|
|
/* All media IOCTLs are _IOWR() */
|
|
|
|
if (copy_to_user(uarg, karg, _IOC_SIZE(cmd)))
|
2015-12-15 19:00:40 +08:00
|
|
|
return -EFAULT;
|
2015-08-23 21:36:41 +08:00
|
|
|
|
2015-12-15 19:00:40 +08:00
|
|
|
return 0;
|
2015-08-23 21:36:41 +08:00
|
|
|
}
|
|
|
|
|
2016-04-27 21:15:52 +08:00
|
|
|
/* Do acquire the graph mutex */
|
|
|
|
#define MEDIA_IOC_FL_GRAPH_MUTEX BIT(0)
|
|
|
|
|
|
|
|
#define MEDIA_IOC_ARG(__cmd, func, fl, from_user, to_user) \
|
|
|
|
[_IOC_NR(MEDIA_IOC_##__cmd)] = { \
|
|
|
|
.cmd = MEDIA_IOC_##__cmd, \
|
2016-05-04 05:42:13 +08:00
|
|
|
.fn = (long (*)(struct media_device *, void *))func, \
|
2016-04-27 21:15:52 +08:00
|
|
|
.flags = fl, \
|
|
|
|
.arg_from_user = from_user, \
|
|
|
|
.arg_to_user = to_user, \
|
2016-05-04 05:35:12 +08:00
|
|
|
}
|
2016-04-27 20:39:17 +08:00
|
|
|
|
2016-04-27 21:15:52 +08:00
|
|
|
#define MEDIA_IOC(__cmd, func, fl) \
|
|
|
|
MEDIA_IOC_ARG(__cmd, func, fl, copy_arg_from_user, copy_arg_to_user)
|
2016-05-04 05:42:13 +08:00
|
|
|
|
2016-04-27 20:39:17 +08:00
|
|
|
/* the table is indexed by _IOC_NR(cmd) */
|
|
|
|
struct media_ioctl_info {
|
|
|
|
unsigned int cmd;
|
2016-04-27 21:15:52 +08:00
|
|
|
unsigned short flags;
|
2016-05-04 05:42:13 +08:00
|
|
|
long (*fn)(struct media_device *dev, void *arg);
|
|
|
|
long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
|
|
|
|
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
|
2016-04-27 20:39:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct media_ioctl_info ioctl_info[] = {
|
2016-04-27 21:15:52 +08:00
|
|
|
MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
|
|
|
|
MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, MEDIA_IOC_FL_GRAPH_MUTEX),
|
|
|
|
MEDIA_IOC(ENUM_LINKS, media_device_enum_links, MEDIA_IOC_FL_GRAPH_MUTEX),
|
|
|
|
MEDIA_IOC(SETUP_LINK, media_device_setup_link, MEDIA_IOC_FL_GRAPH_MUTEX),
|
|
|
|
MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, MEDIA_IOC_FL_GRAPH_MUTEX),
|
2016-04-27 20:39:17 +08:00
|
|
|
};
|
|
|
|
|
2010-08-18 22:41:22 +08:00
|
|
|
static long media_device_ioctl(struct file *filp, unsigned int cmd,
|
2016-05-04 05:42:13 +08:00
|
|
|
unsigned long __arg)
|
2010-08-18 22:41:22 +08:00
|
|
|
{
|
|
|
|
struct media_devnode *devnode = media_devnode_data(filp);
|
2016-04-28 06:28:26 +08:00
|
|
|
struct media_device *dev = devnode->media_dev;
|
2016-05-04 05:35:12 +08:00
|
|
|
const struct media_ioctl_info *info;
|
2016-05-04 05:42:13 +08:00
|
|
|
void __user *arg = (void __user *)__arg;
|
|
|
|
char __karg[256], *karg = __karg;
|
2010-08-18 22:41:22 +08:00
|
|
|
long ret;
|
|
|
|
|
2016-04-27 20:39:17 +08:00
|
|
|
if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
|
|
|
|
|| ioctl_info[_IOC_NR(cmd)].cmd != cmd)
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
2016-05-04 05:35:12 +08:00
|
|
|
info = &ioctl_info[_IOC_NR(cmd)];
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
if (_IOC_SIZE(info->cmd) > sizeof(__karg)) {
|
|
|
|
karg = kmalloc(_IOC_SIZE(info->cmd), GFP_KERNEL);
|
|
|
|
if (!karg)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->arg_from_user) {
|
|
|
|
ret = info->arg_from_user(karg, arg, cmd);
|
|
|
|
if (ret)
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2016-04-27 21:15:52 +08:00
|
|
|
if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
|
|
|
|
mutex_lock(&dev->graph_mutex);
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
ret = info->fn(dev, karg);
|
2016-04-27 21:15:52 +08:00
|
|
|
|
|
|
|
if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
|
|
|
|
mutex_unlock(&dev->graph_mutex);
|
2010-08-18 22:41:22 +08:00
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
if (!ret && info->arg_to_user)
|
|
|
|
ret = info->arg_to_user(arg, karg, cmd);
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
if (karg != __karg)
|
|
|
|
kfree(karg);
|
|
|
|
|
2010-08-18 22:41:22 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-22 23:27:56 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
|
|
|
|
struct media_links_enum32 {
|
|
|
|
__u32 entity;
|
|
|
|
compat_uptr_t pads; /* struct media_pad_desc * */
|
|
|
|
compat_uptr_t links; /* struct media_link_desc * */
|
|
|
|
__u32 reserved[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
static long media_device_enum_links32(struct media_device *mdev,
|
|
|
|
struct media_links_enum32 __user *ulinks)
|
|
|
|
{
|
|
|
|
struct media_links_enum links;
|
|
|
|
compat_uptr_t pads_ptr, links_ptr;
|
|
|
|
|
|
|
|
memset(&links, 0, sizeof(links));
|
|
|
|
|
|
|
|
if (get_user(links.entity, &ulinks->entity)
|
|
|
|
|| get_user(pads_ptr, &ulinks->pads)
|
|
|
|
|| get_user(links_ptr, &ulinks->links))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
links.pads = compat_ptr(pads_ptr);
|
|
|
|
links.links = compat_ptr(links_ptr);
|
|
|
|
|
2016-05-04 05:42:13 +08:00
|
|
|
return media_device_enum_links(mdev, &links);
|
2013-01-22 23:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32)
|
|
|
|
|
|
|
|
static long media_device_compat_ioctl(struct file *filp, unsigned int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
struct media_devnode *devnode = media_devnode_data(filp);
|
2016-04-28 06:28:26 +08:00
|
|
|
struct media_device *dev = devnode->media_dev;
|
2013-01-22 23:27:56 +08:00
|
|
|
long ret;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MEDIA_IOC_ENUM_LINKS32:
|
|
|
|
mutex_lock(&dev->graph_mutex);
|
|
|
|
ret = media_device_enum_links32(dev,
|
|
|
|
(struct media_links_enum32 __user *)arg);
|
|
|
|
mutex_unlock(&dev->graph_mutex);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-03-21 20:19:31 +08:00
|
|
|
return media_device_ioctl(filp, cmd, arg);
|
2013-01-22 23:27:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_COMPAT */
|
|
|
|
|
2009-12-09 19:39:58 +08:00
|
|
|
static const struct media_file_operations media_device_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2010-08-18 22:41:22 +08:00
|
|
|
.open = media_device_open,
|
|
|
|
.ioctl = media_device_ioctl,
|
2013-01-22 23:27:56 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = media_device_compat_ioctl,
|
|
|
|
#endif /* CONFIG_COMPAT */
|
2010-08-18 22:41:22 +08:00
|
|
|
.release = media_device_close,
|
2009-12-09 19:39:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* sysfs
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ssize_t show_model(struct device *cd,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
2016-04-28 06:28:26 +08:00
|
|
|
struct media_devnode *devnode = to_media_devnode(cd);
|
|
|
|
struct media_device *mdev = devnode->media_dev;
|
2009-12-09 19:39:58 +08:00
|
|
|
|
|
|
|
return sprintf(buf, "%.*s\n", (int)sizeof(mdev->model), mdev->model);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------------
|
|
|
|
* Registration/unregistration
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void media_device_release(struct media_devnode *mdev)
|
|
|
|
{
|
2015-08-14 02:22:24 +08:00
|
|
|
dev_dbg(mdev->parent, "Media device released\n");
|
2009-12-09 19:39:58 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 18:26:52 +08:00
|
|
|
/**
|
|
|
|
* media_device_register_entity - Register an entity with a media device
|
|
|
|
* @mdev: The media device
|
|
|
|
* @entity: The entity
|
|
|
|
*/
|
|
|
|
int __must_check media_device_register_entity(struct media_device *mdev,
|
|
|
|
struct media_entity *entity)
|
|
|
|
{
|
2016-02-12 07:41:21 +08:00
|
|
|
struct media_entity_notify *notify, *next;
|
2015-12-15 18:26:52 +08:00
|
|
|
unsigned int i;
|
2015-12-17 01:33:54 +08:00
|
|
|
int ret;
|
2015-12-15 18:26:52 +08:00
|
|
|
|
|
|
|
if (entity->function == MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN ||
|
|
|
|
entity->function == MEDIA_ENT_F_UNKNOWN)
|
|
|
|
dev_warn(mdev->dev,
|
|
|
|
"Entity type for entity %s was not initialized!\n",
|
|
|
|
entity->name);
|
|
|
|
|
|
|
|
/* Warn if we apparently re-register an entity */
|
|
|
|
WARN_ON(entity->graph_obj.mdev != NULL);
|
|
|
|
entity->graph_obj.mdev = mdev;
|
|
|
|
INIT_LIST_HEAD(&entity->links);
|
|
|
|
entity->num_links = 0;
|
|
|
|
entity->num_backlinks = 0;
|
|
|
|
|
2015-12-17 01:33:54 +08:00
|
|
|
if (!ida_pre_get(&mdev->entity_internal_idx, GFP_KERNEL))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_lock(&mdev->graph_mutex);
|
2015-12-16 21:32:17 +08:00
|
|
|
|
2015-12-17 01:33:54 +08:00
|
|
|
ret = ida_get_new_above(&mdev->entity_internal_idx, 1,
|
|
|
|
&entity->internal_idx);
|
|
|
|
if (ret < 0) {
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2015-12-17 01:33:54 +08:00
|
|
|
return ret;
|
2015-12-16 21:32:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mdev->entity_internal_idx_max =
|
|
|
|
max(mdev->entity_internal_idx_max, entity->internal_idx);
|
|
|
|
|
2015-12-15 18:26:52 +08:00
|
|
|
/* Initialize media_gobj embedded at the entity */
|
|
|
|
media_gobj_create(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj);
|
|
|
|
|
|
|
|
/* Initialize objects at the pads */
|
|
|
|
for (i = 0; i < entity->num_pads; i++)
|
|
|
|
media_gobj_create(mdev, MEDIA_GRAPH_PAD,
|
|
|
|
&entity->pads[i].graph_obj);
|
|
|
|
|
2016-02-12 07:41:21 +08:00
|
|
|
/* invoke entity_notify callbacks */
|
|
|
|
list_for_each_entry_safe(notify, next, &mdev->entity_notify, list) {
|
|
|
|
(notify)->notify(entity, notify->notify_data);
|
|
|
|
}
|
|
|
|
|
2016-02-22 00:25:08 +08:00
|
|
|
if (mdev->entity_internal_idx_max
|
|
|
|
>= mdev->pm_count_walk.ent_enum.idx_max) {
|
|
|
|
struct media_entity_graph new = { .top = 0 };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialise the new graph walk before cleaning up
|
|
|
|
* the old one in order not to spoil the graph walk
|
|
|
|
* object of the media device if graph walk init fails.
|
|
|
|
*/
|
|
|
|
ret = media_entity_graph_walk_init(&new, mdev);
|
|
|
|
if (ret) {
|
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
media_entity_graph_walk_cleanup(&mdev->pm_count_walk);
|
|
|
|
mdev->pm_count_walk = new;
|
|
|
|
}
|
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
|
|
|
|
2015-12-15 18:26:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_register_entity);
|
|
|
|
|
2015-12-15 18:36:51 +08:00
|
|
|
static void __media_device_unregister_entity(struct media_entity *entity)
|
2015-12-15 18:26:52 +08:00
|
|
|
{
|
|
|
|
struct media_device *mdev = entity->graph_obj.mdev;
|
|
|
|
struct media_link *link, *tmp;
|
|
|
|
struct media_interface *intf;
|
|
|
|
unsigned int i;
|
|
|
|
|
2015-12-16 21:32:17 +08:00
|
|
|
ida_simple_remove(&mdev->entity_internal_idx, entity->internal_idx);
|
|
|
|
|
2015-12-15 18:26:52 +08:00
|
|
|
/* Remove all interface links pointing to this entity */
|
|
|
|
list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
|
|
|
|
list_for_each_entry_safe(link, tmp, &intf->links, list) {
|
|
|
|
if (link->entity == entity)
|
|
|
|
__media_remove_intf_link(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove all data links that belong to this entity */
|
|
|
|
__media_entity_remove_links(entity);
|
|
|
|
|
|
|
|
/* Remove all pads that belong to this entity */
|
|
|
|
for (i = 0; i < entity->num_pads; i++)
|
|
|
|
media_gobj_destroy(&entity->pads[i].graph_obj);
|
|
|
|
|
|
|
|
/* Remove the entity */
|
|
|
|
media_gobj_destroy(&entity->graph_obj);
|
|
|
|
|
2016-02-12 07:41:21 +08:00
|
|
|
/* invoke entity_notify callbacks to handle entity removal?? */
|
|
|
|
|
2015-12-15 18:26:52 +08:00
|
|
|
entity->graph_obj.mdev = NULL;
|
|
|
|
}
|
2015-12-15 18:36:51 +08:00
|
|
|
|
|
|
|
void media_device_unregister_entity(struct media_entity *entity)
|
|
|
|
{
|
|
|
|
struct media_device *mdev = entity->graph_obj.mdev;
|
|
|
|
|
|
|
|
if (mdev == NULL)
|
|
|
|
return;
|
|
|
|
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_lock(&mdev->graph_mutex);
|
2015-12-15 18:36:51 +08:00
|
|
|
__media_device_unregister_entity(entity);
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2015-12-15 18:36:51 +08:00
|
|
|
}
|
2015-12-15 18:26:52 +08:00
|
|
|
EXPORT_SYMBOL_GPL(media_device_unregister_entity);
|
|
|
|
|
2009-12-09 19:39:58 +08:00
|
|
|
/**
|
2015-12-12 06:57:08 +08:00
|
|
|
* media_device_init() - initialize a media device
|
2009-12-09 19:39:58 +08:00
|
|
|
* @mdev: The media device
|
|
|
|
*
|
|
|
|
* The caller is responsible for initializing the media device before
|
|
|
|
* registration. The following fields must be set:
|
|
|
|
*
|
|
|
|
* - dev must point to the parent device
|
|
|
|
* - model must be filled with the device model name
|
|
|
|
*/
|
2015-12-12 06:57:08 +08:00
|
|
|
void media_device_init(struct media_device *mdev)
|
2009-12-09 19:39:58 +08:00
|
|
|
{
|
2009-12-09 19:40:00 +08:00
|
|
|
INIT_LIST_HEAD(&mdev->entities);
|
2015-08-21 20:23:22 +08:00
|
|
|
INIT_LIST_HEAD(&mdev->interfaces);
|
2015-08-23 19:00:33 +08:00
|
|
|
INIT_LIST_HEAD(&mdev->pads);
|
|
|
|
INIT_LIST_HEAD(&mdev->links);
|
2016-02-12 07:41:21 +08:00
|
|
|
INIT_LIST_HEAD(&mdev->entity_notify);
|
2010-03-08 02:04:59 +08:00
|
|
|
mutex_init(&mdev->graph_mutex);
|
2015-12-16 21:32:17 +08:00
|
|
|
ida_init(&mdev->entity_internal_idx);
|
2009-12-09 19:40:00 +08:00
|
|
|
|
2015-12-12 06:57:08 +08:00
|
|
|
dev_dbg(mdev->dev, "Media device initialized\n");
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_init);
|
|
|
|
|
|
|
|
void media_device_cleanup(struct media_device *mdev)
|
|
|
|
{
|
2015-12-16 21:32:17 +08:00
|
|
|
ida_destroy(&mdev->entity_internal_idx);
|
|
|
|
mdev->entity_internal_idx_max = 0;
|
2016-02-22 00:25:08 +08:00
|
|
|
media_entity_graph_walk_cleanup(&mdev->pm_count_walk);
|
2015-12-12 06:57:08 +08:00
|
|
|
mutex_destroy(&mdev->graph_mutex);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_cleanup);
|
|
|
|
|
|
|
|
int __must_check __media_device_register(struct media_device *mdev,
|
|
|
|
struct module *owner)
|
|
|
|
{
|
2016-04-28 06:28:26 +08:00
|
|
|
struct media_devnode *devnode;
|
2015-12-12 06:57:08 +08:00
|
|
|
int ret;
|
|
|
|
|
2016-04-28 06:28:26 +08:00
|
|
|
devnode = kzalloc(sizeof(*devnode), GFP_KERNEL);
|
|
|
|
if (!devnode)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2009-12-09 19:39:58 +08:00
|
|
|
/* Register the device node. */
|
2016-04-28 06:28:26 +08:00
|
|
|
mdev->devnode = devnode;
|
|
|
|
devnode->fops = &media_device_fops;
|
|
|
|
devnode->parent = mdev->dev;
|
|
|
|
devnode->release = media_device_release;
|
2015-12-12 06:57:09 +08:00
|
|
|
|
|
|
|
/* Set version 0 to indicate user-space that the graph is static */
|
|
|
|
mdev->topology_version = 0;
|
|
|
|
|
2016-04-28 06:28:26 +08:00
|
|
|
ret = media_devnode_register(mdev, devnode, owner);
|
|
|
|
if (ret < 0) {
|
2016-05-05 03:48:28 +08:00
|
|
|
/* devnode free is handled in media_devnode_*() */
|
2016-04-28 06:28:26 +08:00
|
|
|
mdev->devnode = NULL;
|
2009-12-09 19:39:58 +08:00
|
|
|
return ret;
|
2016-04-28 06:28:26 +08:00
|
|
|
}
|
2009-12-09 19:39:58 +08:00
|
|
|
|
2016-04-28 06:28:26 +08:00
|
|
|
ret = device_create_file(&devnode->dev, &dev_attr_model);
|
2009-12-09 19:39:58 +08:00
|
|
|
if (ret < 0) {
|
2016-05-05 03:48:28 +08:00
|
|
|
/* devnode free is handled in media_devnode_*() */
|
2016-04-28 06:28:26 +08:00
|
|
|
mdev->devnode = NULL;
|
2016-06-11 01:37:23 +08:00
|
|
|
media_devnode_unregister_prepare(devnode);
|
2016-04-28 06:28:26 +08:00
|
|
|
media_devnode_unregister(devnode);
|
2009-12-09 19:39:58 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-14 02:22:24 +08:00
|
|
|
dev_dbg(mdev->dev, "Media device registered\n");
|
|
|
|
|
2009-12-09 19:39:58 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2013-12-12 23:38:17 +08:00
|
|
|
EXPORT_SYMBOL_GPL(__media_device_register);
|
2009-12-09 19:39:58 +08:00
|
|
|
|
2016-02-12 07:41:21 +08:00
|
|
|
int __must_check media_device_register_entity_notify(struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr)
|
|
|
|
{
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_lock(&mdev->graph_mutex);
|
2016-02-12 07:41:21 +08:00
|
|
|
list_add_tail(&nptr->list, &mdev->entity_notify);
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2016-02-12 07:41:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_register_entity_notify);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: Should be called with mdev->lock held.
|
|
|
|
*/
|
|
|
|
static void __media_device_unregister_entity_notify(struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr)
|
|
|
|
{
|
|
|
|
list_del(&nptr->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void media_device_unregister_entity_notify(struct media_device *mdev,
|
|
|
|
struct media_entity_notify *nptr)
|
|
|
|
{
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_lock(&mdev->graph_mutex);
|
2016-02-12 07:41:21 +08:00
|
|
|
__media_device_unregister_entity_notify(mdev, nptr);
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2016-02-12 07:41:21 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_unregister_entity_notify);
|
|
|
|
|
2009-12-09 19:39:58 +08:00
|
|
|
void media_device_unregister(struct media_device *mdev)
|
|
|
|
{
|
2009-12-09 19:40:00 +08:00
|
|
|
struct media_entity *entity;
|
|
|
|
struct media_entity *next;
|
2015-08-30 08:23:44 +08:00
|
|
|
struct media_interface *intf, *tmp_intf;
|
2016-02-12 07:41:21 +08:00
|
|
|
struct media_entity_notify *notify, *nextp;
|
2015-08-30 08:23:44 +08:00
|
|
|
|
2015-12-15 18:36:51 +08:00
|
|
|
if (mdev == NULL)
|
|
|
|
return;
|
|
|
|
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_lock(&mdev->graph_mutex);
|
2015-12-15 18:36:51 +08:00
|
|
|
|
2015-12-12 06:57:07 +08:00
|
|
|
/* Check if mdev was ever registered at all */
|
2016-04-28 06:28:26 +08:00
|
|
|
if (!media_devnode_is_registered(mdev->devnode)) {
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2015-12-12 06:57:07 +08:00
|
|
|
return;
|
2015-12-15 18:36:51 +08:00
|
|
|
}
|
2015-12-12 06:57:07 +08:00
|
|
|
|
2016-06-11 01:37:23 +08:00
|
|
|
/* Clear the devnode register bit to avoid races with media dev open */
|
|
|
|
media_devnode_unregister_prepare(mdev->devnode);
|
|
|
|
|
2015-09-05 02:10:29 +08:00
|
|
|
/* Remove all entities from the media device */
|
|
|
|
list_for_each_entry_safe(entity, next, &mdev->entities, graph_obj.list)
|
2015-12-15 18:36:51 +08:00
|
|
|
__media_device_unregister_entity(entity);
|
2015-09-05 02:10:29 +08:00
|
|
|
|
2016-02-12 07:41:21 +08:00
|
|
|
/* Remove all entity_notify callbacks from the media device */
|
|
|
|
list_for_each_entry_safe(notify, nextp, &mdev->entity_notify, list)
|
|
|
|
__media_device_unregister_entity_notify(mdev, notify);
|
|
|
|
|
2015-08-30 08:23:44 +08:00
|
|
|
/* Remove all interfaces from the media device */
|
|
|
|
list_for_each_entry_safe(intf, tmp_intf, &mdev->interfaces,
|
|
|
|
graph_obj.list) {
|
|
|
|
__media_remove_intf_links(intf);
|
2015-12-11 21:55:40 +08:00
|
|
|
media_gobj_destroy(&intf->graph_obj);
|
2015-08-30 08:23:44 +08:00
|
|
|
kfree(intf);
|
|
|
|
}
|
2015-12-15 18:36:51 +08:00
|
|
|
|
[media] media-device: get rid of the spinlock
Right now, the lock schema for media_device struct is messy,
since sometimes, it is protected via a spin lock, while, for
media graph traversal, it is protected by a mutex.
Solve this conflict by always using a mutex.
As a side effect, this prevents a bug when the media notifiers
is called at atomic context, while running the notifier callback:
BUG: sleeping function called from invalid context at mm/slub.c:1289
in_atomic(): 1, irqs_disabled(): 0, pid: 3479, name: modprobe
4 locks held by modprobe/3479:
#0: (&dev->mutex){......}, at: [<ffffffff81ce8933>] __driver_attach+0xa3/0x160
#1: (&dev->mutex){......}, at: [<ffffffff81ce8941>] __driver_attach+0xb1/0x160
#2: (register_mutex#5){+.+.+.}, at: [<ffffffffa10596c7>] usb_audio_probe+0x257/0x1c90 [snd_usb_audio]
#3: (&(&mdev->lock)->rlock){+.+.+.}, at: [<ffffffffa0e6051b>] media_device_register_entity+0x1cb/0x700 [media]
CPU: 2 PID: 3479 Comm: modprobe Not tainted 4.5.0-rc3+ #49
Hardware name: /NUC5i7RYB, BIOS RYBDWi35.86A.0350.2015.0812.1722 08/12/2015
0000000000000000 ffff8803b3f6f288 ffffffff81933901 ffff8803c4bae000
ffff8803c4bae5c8 ffff8803b3f6f2b0 ffffffff811c6af5 ffff8803c4bae000
ffffffff8285d7f6 0000000000000509 ffff8803b3f6f2f0 ffffffff811c6ce5
Call Trace:
[<ffffffff81933901>] dump_stack+0x85/0xc4
[<ffffffff811c6af5>] ___might_sleep+0x245/0x3a0
[<ffffffff811c6ce5>] __might_sleep+0x95/0x1a0
[<ffffffff8155aade>] kmem_cache_alloc_trace+0x20e/0x300
[<ffffffffa0e66e3d>] ? media_add_link+0x4d/0x140 [media]
[<ffffffffa0e66e3d>] media_add_link+0x4d/0x140 [media]
[<ffffffffa0e69931>] media_create_pad_link+0xa1/0x600 [media]
[<ffffffffa0fe11b3>] au0828_media_graph_notify+0x173/0x360 [au0828]
[<ffffffffa0e68a6a>] ? media_gobj_create+0x1ba/0x480 [media]
[<ffffffffa0e606fb>] media_device_register_entity+0x3ab/0x700 [media]
Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2016-04-06 21:55:24 +08:00
|
|
|
mutex_unlock(&mdev->graph_mutex);
|
2009-12-09 19:40:00 +08:00
|
|
|
|
2016-04-28 06:28:26 +08:00
|
|
|
dev_dbg(mdev->dev, "Media device unregistered\n");
|
|
|
|
|
2016-06-11 01:37:23 +08:00
|
|
|
device_remove_file(&mdev->devnode->dev, &dev_attr_model);
|
|
|
|
media_devnode_unregister(mdev->devnode);
|
|
|
|
/* devnode free is handled in media_devnode_*() */
|
|
|
|
mdev->devnode = NULL;
|
2009-12-09 19:39:58 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_unregister);
|
2009-12-09 19:40:00 +08:00
|
|
|
|
2015-06-03 23:12:53 +08:00
|
|
|
static void media_device_release_devres(struct device *dev, void *res)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct media_device *media_device_get_devres(struct device *dev)
|
|
|
|
{
|
|
|
|
struct media_device *mdev;
|
|
|
|
|
|
|
|
mdev = devres_find(dev, media_device_release_devres, NULL, NULL);
|
|
|
|
if (mdev)
|
|
|
|
return mdev;
|
|
|
|
|
|
|
|
mdev = devres_alloc(media_device_release_devres,
|
|
|
|
sizeof(struct media_device), GFP_KERNEL);
|
|
|
|
if (!mdev)
|
|
|
|
return NULL;
|
|
|
|
return devres_get(dev, mdev, NULL, NULL);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_get_devres);
|
|
|
|
|
|
|
|
struct media_device *media_device_find_devres(struct device *dev)
|
|
|
|
{
|
|
|
|
return devres_find(dev, media_device_release_devres, NULL, NULL);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_find_devres);
|
2015-06-06 04:11:54 +08:00
|
|
|
|
2016-05-05 19:01:34 +08:00
|
|
|
#if IS_ENABLED(CONFIG_PCI)
|
2016-02-22 23:10:49 +08:00
|
|
|
void media_device_pci_init(struct media_device *mdev,
|
|
|
|
struct pci_dev *pci_dev,
|
|
|
|
const char *name)
|
2016-02-22 22:42:04 +08:00
|
|
|
{
|
|
|
|
mdev->dev = &pci_dev->dev;
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
strlcpy(mdev->model, name, sizeof(mdev->model));
|
|
|
|
else
|
|
|
|
strlcpy(mdev->model, pci_name(pci_dev), sizeof(mdev->model));
|
|
|
|
|
|
|
|
sprintf(mdev->bus_info, "PCI:%s", pci_name(pci_dev));
|
|
|
|
|
|
|
|
mdev->hw_revision = (pci_dev->subsystem_vendor << 16)
|
|
|
|
| pci_dev->subsystem_device;
|
|
|
|
|
|
|
|
mdev->driver_version = LINUX_VERSION_CODE;
|
|
|
|
|
|
|
|
media_device_init(mdev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(media_device_pci_init);
|
2016-05-05 19:01:34 +08:00
|
|
|
#endif
|
2016-02-22 22:42:04 +08:00
|
|
|
|
2016-05-05 19:01:34 +08:00
|
|
|
#if IS_ENABLED(CONFIG_USB)
|
2016-02-22 23:10:49 +08:00
|
|
|
void __media_device_usb_init(struct media_device *mdev,
|
|
|
|
struct usb_device *udev,
|
|
|
|
const char *board_name,
|
|
|
|
const char *driver_name)
|
2016-02-22 22:42:04 +08:00
|
|
|
{
|
|
|
|
mdev->dev = &udev->dev;
|
|
|
|
|
|
|
|
if (driver_name)
|
|
|
|
strlcpy(mdev->driver_name, driver_name,
|
|
|
|
sizeof(mdev->driver_name));
|
|
|
|
|
|
|
|
if (board_name)
|
|
|
|
strlcpy(mdev->model, board_name, sizeof(mdev->model));
|
|
|
|
else if (udev->product)
|
|
|
|
strlcpy(mdev->model, udev->product, sizeof(mdev->model));
|
|
|
|
else
|
|
|
|
strlcpy(mdev->model, "unknown model", sizeof(mdev->model));
|
|
|
|
if (udev->serial)
|
|
|
|
strlcpy(mdev->serial, udev->serial, sizeof(mdev->serial));
|
|
|
|
usb_make_path(udev, mdev->bus_info, sizeof(mdev->bus_info));
|
|
|
|
mdev->hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
|
|
|
|
mdev->driver_version = LINUX_VERSION_CODE;
|
|
|
|
|
|
|
|
media_device_init(mdev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(__media_device_usb_init);
|
2016-05-05 19:01:34 +08:00
|
|
|
#endif
|
2016-02-22 22:42:04 +08:00
|
|
|
|
|
|
|
|
2015-06-06 04:11:54 +08:00
|
|
|
#endif /* CONFIG_MEDIA_CONTROLLER */
|