All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: devel@driverdev.osuosl.org, robh@kernel.org, mchehab@kernel.org,
	jorhand@linux.microsoft.com, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, kieran.bingham@ideasonboard.com,
	Daniel Scally <djrscally@gmail.com>,
	kitakar@gmail.com, yong.zhi@intel.com, bingbu.cao@intel.com,
	andriy.shevchenko@linux.intel.com, davem@davemloft.net,
	tian.shu.qiu@intel.com, linux-media@vger.kernel.org
Subject: Re: [RFC PATCH] Add bridge driver to connect sensors to CIO2 device via software nodes on ACPI platforms
Date: Fri, 18 Sep 2020 11:16:09 +0300	[thread overview]
Message-ID: <20200918081609.GR18329@kadam> (raw)
In-Reply-To: <20200918064043.GE26842@paasikivi.fi.intel.com>

On Fri, Sep 18, 2020 at 09:40:43AM +0300, Sakari Ailus wrote:
> 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.

I'm not trying to be rude, I'm honestly puzzled by this...

The "i" variable is not a size, it's an iterator...  Comparing signed
and unsigned isn't necessarily a problem, but the only comparison in
this case is here:

   253          struct property_entry *cio2_props;
   254          struct fwnode_handle *fwnode;
   255          struct software_node *nodes;
   256          struct v4l2_subdev *sd;
   257          int i, ret;
   258  
   259          for (i = 0; i < ARRAY_SIZE(supported_devices); i++) {
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That's obviously fine.  The compiler knows at compile time the value of
ARRAY_SIZE().  I feel like there must be a static checker which
complains about this?  ARRAY_SIZE() is size_t.

   260                  adev = acpi_dev_get_first_match_dev(supported_devices[i],
   261                                                      NULL, -1);
   262  
   263                  if (!adev)
   264                          continue;
   265  

regards,
dan carpenter


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: devel@driverdev.osuosl.org, robh@kernel.org,
	andriy.shevchenko@linux.intel.com, jorhand@linux.microsoft.com,
	linux-media@vger.kernel.org, gregkh@linuxfoundation.org,
	linux-kernel@vger.kernel.org, kieran.bingham@ideasonboard.com,
	Daniel Scally <djrscally@gmail.com>,
	yong.zhi@intel.com, bingbu.cao@intel.com, mchehab@kernel.org,
	davem@davemloft.net, tian.shu.qiu@intel.com, kitakar@gmail.com
Subject: Re: [RFC PATCH] Add bridge driver to connect sensors to CIO2 device via software nodes on ACPI platforms
Date: Fri, 18 Sep 2020 11:16:09 +0300	[thread overview]
Message-ID: <20200918081609.GR18329@kadam> (raw)
In-Reply-To: <20200918064043.GE26842@paasikivi.fi.intel.com>

On Fri, Sep 18, 2020 at 09:40:43AM +0300, Sakari Ailus wrote:
> 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.

I'm not trying to be rude, I'm honestly puzzled by this...

The "i" variable is not a size, it's an iterator...  Comparing signed
and unsigned isn't necessarily a problem, but the only comparison in
this case is here:

   253          struct property_entry *cio2_props;
   254          struct fwnode_handle *fwnode;
   255          struct software_node *nodes;
   256          struct v4l2_subdev *sd;
   257          int i, ret;
   258  
   259          for (i = 0; i < ARRAY_SIZE(supported_devices); i++) {
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That's obviously fine.  The compiler knows at compile time the value of
ARRAY_SIZE().  I feel like there must be a static checker which
complains about this?  ARRAY_SIZE() is size_t.

   260                  adev = acpi_dev_get_first_match_dev(supported_devices[i],
   261                                                      NULL, -1);
   262  
   263                  if (!adev)
   264                          continue;
   265  

regards,
dan carpenter

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2020-09-18  8:16 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 21:36 [RFC PATCH] Add bridge driver to connect sensors to CIO2 device via software nodes on ACPI platforms Daniel Scally
2020-09-16 21:36 ` Daniel Scally
2020-09-17  0:17 ` kernel test robot
2020-09-17  3:02 ` kernel test robot
2020-09-17  7:53 ` Greg KH
2020-09-17  7:53   ` Greg KH
2020-09-17  9:47   ` Dan Scally
2020-09-17  9:47     ` Dan Scally
2020-09-17 10:15     ` Dan Carpenter
2020-09-17 10:15       ` Dan Carpenter
2020-09-17 10:24       ` Dan Scally
2020-09-17 10:24         ` Dan Scally
2020-09-17 13:28     ` Kieran Bingham
2020-09-17 13:28       ` Kieran Bingham
2020-09-17 14:08       ` Andy Shevchenko
2020-09-17 14:08         ` Andy Shevchenko
2020-09-17 14:19         ` Kieran Bingham
2020-09-17 14:19           ` Kieran Bingham
2020-09-17 14:36           ` Andy Shevchenko
2020-09-17 14:36             ` Andy Shevchenko
2020-09-17  9:34 ` Dan Carpenter
2020-09-17  9:34   ` Dan Carpenter
2020-09-17 10:19   ` Joe Perches
2020-09-17 10:19     ` Joe Perches
2020-09-18 22:50   ` Dan Scally
2020-09-18 22:50     ` Dan Scally
2020-09-17 10:33 ` Sakari Ailus
2020-09-17 10:33   ` Sakari Ailus
2020-09-17 10:49   ` Dan Carpenter
2020-09-17 10:49     ` Dan Carpenter
2020-09-17 12:25     ` Andy Shevchenko
2020-09-17 12:25       ` Andy Shevchenko
2020-09-17 13:15       ` Dan Carpenter
2020-09-17 13:15         ` Dan Carpenter
2020-09-18  6:40     ` Sakari Ailus
2020-09-18  6:40       ` Sakari Ailus
2020-09-18  8:16       ` Dan Carpenter [this message]
2020-09-18  8:16         ` Dan Carpenter
2020-09-17 10:52   ` Dan Scally
2020-09-17 10:52     ` Dan Scally
2020-09-17 12:45     ` Andy Shevchenko
2020-09-17 12:45       ` Andy Shevchenko
2020-09-17 13:36       ` Dan Scally
2020-09-17 13:36         ` Dan Scally
2020-09-17 14:14         ` Andy Shevchenko
2020-09-17 14:14           ` Andy Shevchenko
2020-09-17 21:25           ` Daniel Scally
2020-09-17 21:25             ` Daniel Scally
2020-09-17 14:44         ` Andy Shevchenko
2020-09-17 14:44           ` Andy Shevchenko
2020-09-18  7:51       ` Sakari Ailus
2020-09-18  7:51         ` Sakari Ailus
2020-09-18 13:07         ` Andy Shevchenko
2020-09-18 13:07           ` Andy Shevchenko
2020-09-21 13:33           ` Dan Scally
2020-09-21 13:33             ` Dan Scally
2020-09-21 14:33             ` Andy Shevchenko
2020-09-21 14:33               ` Andy Shevchenko
2020-09-23  9:39   ` Dan Scally
2020-09-23  9:39     ` Dan Scally
2020-09-28 11:37   ` Dan Scally
2020-09-28 11:37     ` Dan Scally
2020-09-18  8:03 ` Dan Carpenter
2020-09-18  8:03   ` Dan Carpenter
2020-09-18  8:09   ` Dan Scally
2020-09-18  8:09     ` Dan Scally
2020-09-20 21:34 ` kernel test robot
2020-09-20 21:34 ` [RFC PATCH] cio2_sync_state() can be static kernel test robot

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=20200918081609.GR18329@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bingbu.cao@intel.com \
    --cc=davem@davemloft.net \
    --cc=devel@driverdev.osuosl.org \
    --cc=djrscally@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jorhand@linux.microsoft.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=kitakar@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=robh@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=tian.shu.qiu@intel.com \
    --cc=yong.zhi@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.