public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
To: Sakari Ailus <sakari.ailus@iki.fi>
Cc: linux-media@vger.kernel.org, laurent.pinchart@ideasonboard.com,
	hverkuil@xs4all.nl, javier@osg.samsung.com,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Subject: Re: [PATCH v2 03/22] media: Add an API to manage entity enumerations
Date: Wed, 16 Dec 2015 06:04:55 -0200	[thread overview]
Message-ID: <20151216060455.2d905dc6@recife.lan> (raw)
In-Reply-To: <20151215231629.GM17128@valkosipuli.retiisi.org.uk>

Em Wed, 16 Dec 2015 01:16:30 +0200
Sakari Ailus <sakari.ailus@iki.fi> escreveu:

> Hi Mauro,
> 
> On Sun, Dec 13, 2015 at 10:54:57PM -0200, Mauro Carvalho Chehab wrote:
> > > >> +	e->idx_max = idx_max;
> > > >> +
> > > >> +	return 0;
> > > >> +}
> > > >> +EXPORT_SYMBOL_GPL(__media_entity_enum_init);
> > > >> +
> > > >> +/**
> > > >> + * media_entity_enum_cleanup - Release resources of an entity enumeration
> > > >> + *
> > > >> + * @e: Entity enumeration to be released
> > > >> + */
> > > >> +void media_entity_enum_cleanup(struct media_entity_enum *e)
> > > >> +{
> > > >> +	if (e->e != e->__e)
> > > >> +		kfree(e->e);
> > > >> +	e->e = NULL;
> > > >> +}
> > > >> +EXPORT_SYMBOL_GPL(media_entity_enum_cleanup);
> > > >> +
> > > >> +/**
> > > >>   * media_entity_init - Initialize a media entity
> > > >>   *
> > > >>   * @num_pads: Total number of sink and source pads.
> > > >> diff --git a/include/media/media-device.h b/include/media/media-device.h
> > > >> index c0e1764..2d46c66 100644
> > > >> --- a/include/media/media-device.h
> > > >> +++ b/include/media/media-device.h
> > > >> @@ -110,6 +110,20 @@ struct media_device {
> > > >>  /* media_devnode to media_device */
> > > >>  #define to_media_device(node) container_of(node, struct media_device, devnode)
> > > >>  
> > > >> +/**
> > > >> + * media_entity_enum_init - Initialise an entity enumeration
> > > >> + *
> > > >> + * @e: Entity enumeration to be initialised
> > > >> + * @mdev: The related media device
> > > >> + *
> > > >> + * Returns zero on success or a negative error code.
> > > >> + */
> > > >> +static inline __must_check int media_entity_enum_init(
> > > >> +	struct media_entity_enum *e, struct media_device *mdev)
> > > >> +{
> > > >> +	return __media_entity_enum_init(e, mdev->entity_internal_idx_max + 1);
> > > >> +}
> > > >> +
> > > >>  void media_device_init(struct media_device *mdev);
> > > >>  void media_device_cleanup(struct media_device *mdev);
> > > >>  int __must_check __media_device_register(struct media_device *mdev,
> > > >> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> > > >> index d3d3a39..5a0339a 100644
> > > >> --- a/include/media/media-entity.h
> > > >> +++ b/include/media/media-entity.h
> > > >> @@ -23,7 +23,7 @@
> > > >>  #ifndef _MEDIA_ENTITY_H
> > > >>  #define _MEDIA_ENTITY_H
> > > >>  
> > > >> -#include <linux/bitops.h>
> > > >> +#include <linux/bitmap.h>
> > > >>  #include <linux/kernel.h>
> > > >>  #include <linux/list.h>
> > > >>  #include <linux/media.h>
> > > >> @@ -71,6 +71,30 @@ struct media_gobj {
> > > >>  	struct list_head	list;
> > > >>  };
> > > >>  
> > > >> +#define MEDIA_ENTITY_ENUM_MAX_DEPTH	16
> > > >> +#define MEDIA_ENTITY_ENUM_MAX_ID	64
> > > >> +
> > > >> +/*
> > > >> + * The number of pads can't be bigger than the number of entities,
> > > >> + * as the worse-case scenario is to have one entity linked up to
> > > >> + * MEDIA_ENTITY_ENUM_MAX_ID - 1 entities.
> > > >> + */
> > > >> +#define MEDIA_ENTITY_MAX_PADS		(MEDIA_ENTITY_ENUM_MAX_ID - 1)
> > > >> +
> > > >> +/* struct media_entity_enum - An enumeration of media entities.
> > > >> + *
> > > >> + * @__e:	Pre-allocated space reserved for media entities if the total
> > > >> + *		number of entities  does not exceed MEDIA_ENTITY_ENUM_MAX_ID.
> > > >> + * @e:		Bit mask in which each bit represents one entity at struct
> > > >> + *		media_entity->internal_idx.
> > > >> + * @idx_max:	Number of bits in the enum.
> > > >> + */
> > > >> +struct media_entity_enum {
> > > >> +	DECLARE_BITMAP(__e, MEDIA_ENTITY_ENUM_MAX_ID);
> > > >> +	unsigned long *e;
> > > > 
> > > > As mentioned before, don't use single letter names, specially inside
> > > > publicly used structures. There's no good reason for that, and the
> > > > code become really obscure.
> > > > 
> > > > Also, just declare one bitmap. having a "pre-allocated" hardcoded
> > > > one here is very confusing.
> > > 
> > > I prefer to keep it as allocating a few bytes of memory is silly. In the
> > > vast majority of the cases the pre-allocated array will be sufficient.
> > 
> > "vast majority" actually depends on the driver/subsystem. The fact that
> > right now most drivers work fine with < 64 entities may not be
> > true in the future.
> 
> One reason the pre-allocated bitmap shouldn't be removed yet is that by
> doing that, i.e. allocating memory in media_entity_enum_init(), the user
> must check the return code. The further patches in the set make drivers do
> that add __must_check modifier to the prototype.
> 
> I will thus add another patch near the top to remove the pre-allocated
> bitmap.

Works for me.

Regards,
Mauro

  reply	other threads:[~2015-12-16  8:05 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-29 19:20 [PATCH v2 00/22] Unrestricted media entity ID range support Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 01/22] media: Enforce single entity->pipe in a pipeline Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 02/22] media: Introduce internal index for media entities Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 03/22] media: Add an API to manage entity enumerations Sakari Ailus
2015-12-12 15:09   ` Mauro Carvalho Chehab
2015-12-13 22:12     ` Sakari Ailus
2015-12-14  0:54       ` Mauro Carvalho Chehab
2015-12-15 23:16         ` Sakari Ailus
2015-12-16  8:04           ` Mauro Carvalho Chehab [this message]
2015-11-29 19:20 ` [PATCH v2 04/22] media: Move struct media_entity_graph definition up Sakari Ailus
2015-12-12 15:12   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 05/22] media: Add KernelDoc documentation for struct media_entity_graph Sakari Ailus
2015-12-12 15:15   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 06/22] media: Move media graph state for streamon/off to the pipeline Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 07/22] media: Amend media graph walk API by init and cleanup functions Sakari Ailus
2015-12-12 15:18   ` Mauro Carvalho Chehab
2015-12-12 15:19   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 08/22] media: Use the new media_entity_graph_walk_start() Sakari Ailus
2015-12-12 15:18   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 09/22] v4l: omap3isp: Use the new media_entity_graph_walk_start() interface Sakari Ailus
2015-12-12 15:20   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 10/22] v4l: exynos4-is: " Sakari Ailus
2015-12-12 15:21   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 11/22] v4l: xilinx: " Sakari Ailus
2015-12-12 15:22   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 12/22] v4l: vsp1: " Sakari Ailus
2015-12-12 15:24   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 13/22] media: Use entity enums in graph walk Sakari Ailus
2015-12-12 15:25   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 14/22] media: Keep using the same graph walk object for a given pipeline Sakari Ailus
2015-12-12 15:26   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 15/22] v4l: omap3isp: Use media entity enumeration API Sakari Ailus
2015-12-12 15:29   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 16/22] v4l: vsp1: " Sakari Ailus
2015-12-12 15:31   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 17/22] staging: v4l: omap4iss: Fix sub-device power management code Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 18/22] staging: v4l: omap4iss: Use media entity enum API Sakari Ailus
2015-12-12 15:33   ` Mauro Carvalho Chehab
2015-11-29 19:20 ` [PATCH v2 19/22] staging: v4l: omap4iss: Use the new media_entity_graph_walk_start() interface Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 20/22] staging: v4l: davinci_vpbe: " Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 21/22] media: Rename MEDIA_ENTITY_ENUM_MAX_ID as MEDIA_ENTITY_ENUM_STACK_ALLOC Sakari Ailus
2015-11-29 19:20 ` [PATCH v2 22/22] media: Update media graph walk documentation for the changed API Sakari Ailus
2015-12-12 15:35   ` Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151216060455.2d905dc6@recife.lan \
    --to=mchehab@osg.samsung.com \
    --cc=hverkuil@xs4all.nl \
    --cc=javier@osg.samsung.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox