Em Wed, 14 Oct 2015 12:56:54 +0200 Javier Martinez Canillas javier@osg.samsung.com escreveu:
Hello,
On 10/14/2015 12:09 PM, Sakari Ailus wrote:
On Mon, Oct 12, 2015 at 08:52:43PM -0300, Mauro Carvalho Chehab wrote:
Sakari Ailus sakari.ailus@iki.fi escreveu:
[snip]
static int isp_subdev_notifier_complete(struct v4l2_async_notifier *async) { struct isp_device *isp = container_of(async, struct isp_device, notifier);
- struct v4l2_device *v4l2_dev = &isp->v4l2_dev;
- struct v4l2_subdev *sd;
- struct isp_bus_cfg *bus;
- int ret;
- list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
list_for_each_entry(sd, &isp->v4l2_dev.subdevs, list) {
And you can drop local v4l2_dev.
This is Javier's patch, but I agree that this can be simplified.
Yes, the local variable is not needed but usually I prefer to use a variable when two levels of indirection are needed since I think that makes the code easier to read.
I don't have a strong opinion though so I don't mind if is dropped.
/* Only try to link entities whose interface was set on bound */
if (sd->host_priv) {
bus = (struct isp_bus_cfg *)sd->host_priv;
struct isp_bus_cfg *bus = sd->host_priv;
And you can drop "bus" from the beginning of the function.
Perhaps not a big deal, but I think it's cleaner this way.
I actually prefer to allocate the local vars only once at the function :)
Ok, if the compiler optimizer is good enough, this won't make any difference, but, if the optimizer is not that good, at least on archs with not many registers like x86, allocating local vars inside loops may create extra code.
I'm more worried about accidentally using the variables when they're not supposed to.
I see your point but gcc (or sparse/smatch) warns when a local var is overriden by some other var. So, I don't thing we should be worried about those risks on general case, as we'll get this before sending the patches upstream, as I always run with V=1 and we also check sparse/smatch to check for such warnings.
I don't think there's much risk of that here though. Cc Javier.
Yeah, I don't see any risk on this code. So, I would prefer to create those loop vars outside the loop, to be sure that the compiler won't be doing the wrong thing.
I thought that declaring all local variables at the beginning of the function was a convention but from a quick look at CodingStyle I found nothing so I agree with declaring the variable as locally as possible.
Best regards,