From patchwork Fri Sep 11 10:09:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 7159151 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02DB9BEEC1 for ; Fri, 11 Sep 2015 10:11:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7F46720829 for ; Fri, 11 Sep 2015 10:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 192AD2082C for ; Fri, 11 Sep 2015 10:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752267AbbIKKLS (ORCPT ); Fri, 11 Sep 2015 06:11:18 -0400 Received: from mga03.intel.com ([134.134.136.65]:28146 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751532AbbIKKLR (ORCPT ); Fri, 11 Sep 2015 06:11:17 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP; 11 Sep 2015 03:11:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,511,1437462000"; d="scan'208";a="787317289" Received: from paasikivi.fi.intel.com ([10.237.72.42]) by fmsmga001.fm.intel.com with ESMTP; 11 Sep 2015 03:11:01 -0700 Received: from nauris.fi.intel.com (nauris.localdomain [192.168.240.2]) by paasikivi.fi.intel.com (Postfix) with ESMTP id 808FF20EEC; Fri, 11 Sep 2015 13:11:00 +0300 (EEST) Received: by nauris.fi.intel.com (Postfix, from userid 1000) id 6E186201EE; Fri, 11 Sep 2015 13:09:23 +0300 (EEST) From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, javier@osg.samsung.com, mchehab@osg.samsung.com, hverkuil@xs4all.nl Subject: [RFC 4/9] media: Use media entity enum API for managing low IDs Date: Fri, 11 Sep 2015 13:09:07 +0300 Message-Id: <1441966152-28444-5-git-send-email-sakari.ailus@linux.intel.com> X-Mailer: git-send-email 2.1.0.231.g7484e3b In-Reply-To: <1441966152-28444-1-git-send-email-sakari.ailus@linux.intel.com> References: <1441966152-28444-1-git-send-email-sakari.ailus@linux.intel.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Sakari Ailus --- drivers/media/media-device.c | 15 +++++++-------- include/media/media-device.h | 2 +- include/media/media-entity.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c index dfc5e4a..43d0760 100644 --- a/drivers/media/media-device.c +++ b/drivers/media/media-device.c @@ -20,7 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include #include #include @@ -544,7 +543,7 @@ int __must_check __media_device_register(struct media_device *mdev, if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0)) return -EINVAL; - bitmap_zero(mdev->entity_low_id, MEDIA_ENTITY_MAX_LOW_ID); + media_entity_enum_init(mdev->entity_low_id); INIT_LIST_HEAD(&mdev->entities); INIT_LIST_HEAD(&mdev->interfaces); @@ -618,6 +617,7 @@ int __must_check media_device_register_entity(struct media_device *mdev, struct media_entity *entity) { unsigned int i; + int id; if (entity->function == MEDIA_ENT_F_V4L2_SUBDEV_UNKNOWN || entity->function == MEDIA_ENT_F_UNKNOWN) @@ -631,14 +631,13 @@ int __must_check media_device_register_entity(struct media_device *mdev, INIT_LIST_HEAD(&entity->links); spin_lock(&mdev->lock); - entity->low_id = find_first_zero_bit(mdev->entity_low_id, - MEDIA_ENTITY_MAX_LOW_ID); - if (entity->low_id == MEDIA_ENTITY_MAX_LOW_ID) { + id = media_entity_enum_get_next(mdev->entity_low_id); + if (id < 0) { spin_unlock(&mdev->lock); - return -ENOSPC; + return id; } - __set_bit(entity->low_id, mdev->entity_low_id); + entity->id = id; /* Initialize media_gobj embedded at the entity */ media_gobj_init(mdev, MEDIA_GRAPH_ENTITY, &entity->graph_obj); @@ -672,7 +671,7 @@ void media_device_unregister_entity(struct media_entity *entity) spin_lock(&mdev->lock); - __clear_bit(entity->low_id, mdev->entity_low_id); + media_entity_enum_clear(mdev->entity_low_id, entity); /* Remove interface links with this entity on it */ list_for_each_entry_safe(link, tmp, &mdev->links, graph_obj.list) { diff --git a/include/media/media-device.h b/include/media/media-device.h index 732163f..b074ff8 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -83,7 +83,7 @@ struct media_device { u32 pad_id; u32 link_id; u32 intf_devnode_id; - DECLARE_BITMAP(entity_low_id, MEDIA_ENTITY_MAX_LOW_ID); + DECLARE_MEDIA_ENTITY_ENUM(entity_low_id); struct list_head entities; struct list_head interfaces; diff --git a/include/media/media-entity.h b/include/media/media-entity.h index 17ec205..95b1061 100644 --- a/include/media/media-entity.h +++ b/include/media/media-entity.h @@ -352,6 +352,18 @@ static inline bool media_entity_enum_intersects(unsigned long *e, return bitmap_intersects(e, f, MEDIA_ENTITY_MAX_LOW_ID); } +static inline int media_entity_enum_get_next(unsigned long *e) +{ + unsigned int id = find_first_zero_bit(e, MEDIA_ENTITY_MAX_LOW_ID); + + if (id == MEDIA_ENTITY_MAX_LOW_ID) + return -ENOSPC; + + __set_bit(id, e); + + return id; +} + struct media_entity_graph { struct { struct media_entity *entity;