lkml.org 
[lkml]   [2020]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH] Add bridge driver to connect sensors to CIO2 device via software nodes on ACPI platforms
Hi Dan,

On Thu, Sep 17, 2020 at 01:49:41PM +0300, Dan Carpenter wrote:
> On Thu, Sep 17, 2020 at 01:33:43PM +0300, Sakari Ailus wrote:
> > > +static int connect_supported_devices(void)
> > > +{
> > > + struct acpi_device *adev;
> > > + struct device *dev;
> > > + struct sensor_bios_data ssdb;
> > > + struct sensor *sensor;
> > > + struct property_entry *sensor_props;
> > > + struct property_entry *cio2_props;
> > > + struct fwnode_handle *fwnode;
> > > + struct software_node *nodes;
> > > + struct v4l2_subdev *sd;
> > > + int i, ret;
> >
> > unsigned int i
> >
>
> Why?
>
> For list iterators then "int i;" is best... For sizes then unsigned is
> sometimes best. Or if it's part of the hardware spec or network spec
> unsigned is best. Otherwise unsigned variables cause a ton of bugs.
> They're not as intuitive as signed variables. Imagine if there is an
> error in this loop and you want to unwind. With a signed variable you
> can do:
>
> while (--i >= 0)
> cleanup(&bridge.sensors[i]);
>
> There are very few times where raising the type maximum from 2 billion
> to 4 billion fixes anything.

There's simply no need for the negative integers here. Sizes (as it's a
size here) are unsigned, too, so you'd be comparing signed and unsigned
numbers later in the function.

--
Regards,

Sakari Ailus

\
 
 \ /
  Last update: 2020-09-18 08:41    [W:0.130 / U:0.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site