From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
"Rob Herring" <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
"Wolfram Sang" <wsa@kernel.org>,
"Luca Ceresoli" <luca.ceresoli@bootlin.com>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
"Matti Vaittinen" <Matti.Vaittinen@fi.rohmeurope.com>,
"Mauro Carvalho Chehab" <mchehab@kernel.org>,
"Peter Rosin" <peda@axentia.se>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
"Michael Tretter" <m.tretter@pengutronix.de>,
"Shawn Tu" <shawnx.tu@intel.com>,
"Hans Verkuil" <hverkuil@xs4all.nl>,
"Mike Pagano" <mpagano@gentoo.org>,
"Krzysztof Hałasa" <khalasa@piap.pl>,
"Marek Vasut" <marex@denx.de>,
"Satish Nagireddy" <satish.nagireddy@getcruise.com>
Subject: Re: [PATCH v8 5/7] media: i2c: add DS90UB960 driver
Date: Wed, 25 Jan 2023 13:34:25 +0200 [thread overview]
Message-ID: <a59ea457-58df-0058-ddaf-c605e5432864@ideasonboard.com> (raw)
In-Reply-To: <Y9EAw+PUwZJFH+NO@pendragon.ideasonboard.com>
On 25/01/2023 12:13, Laurent Pinchart wrote:
> Hi Tomi,
>
> On Wed, Jan 25, 2023 at 09:39:57AM +0200, Tomi Valkeinen wrote:
>> On 24/01/2023 20:27, Laurent Pinchart wrote:
>>
>>>>>> + } else if (ret < 0) {
>>>>>> + dev_err(dev, "rx%u: failed to read 'ti,cdr-mode': %d\n", nport,
>>>>>
>>>>> If you moved the "ti,cdr-mode" to an argument, printed with %s, the same
>>>>> format string would be used for the other properties below, and should
>>>>> thus be de-duplicated by the compiler.
>>>>
>>>> I'm not quite sure if this is a sensible optimization or not, but I did
>>>> it so that I introduce:
>>>>
>>>> const char *read_err_str = "rx%u: failed to read '%s': %d\n";
>>>
>>> static
>>>
>>>> and then use that in the function, which makes the lines much shorter
>>>> and, I think, a bit more readable.
>>>
>>> If you use the same string literal multiple times, the compiler should
>>> de-duplicate it automatically, so you don't have to create a variable
>>> manually.
>>
>> Yes, but I think this looked better, as it made the code look less
>> cluttered, and the point is more obvious. Otherwise, looking at the
>> code, seeing dev_dbg(dev, "Foo %s\n", "bar"); looks pretty weird.
>
> I find
>
> dev_dbg(dev, read_err_str, port, "ti,cdr-mode", ret);
>
> less readable as I then have to look up the read_err_str string to
> understand that line. I also wonder, in that case, if the compiler can
> still warn if the format string doesn't match the argument types.
That's a good point, it doesn't.
>>>>>> +static void ub960_notify_unbind(struct v4l2_async_notifier *notifier,
>>>>>> + struct v4l2_subdev *subdev,
>>>>>> + struct v4l2_async_subdev *asd)
>>>>>> +{
>>>>>> + struct ub960_rxport *rxport = to_ub960_asd(asd)->rxport;
>>>>>> +
>>>>>> + rxport->source_sd = NULL;
>>>>>
>>>>> Does this serve any purpose ? If not, I'd drop the unbind handler.
>>>>
>>>> It makes sure we don't access the source subdev after it has been
>>>> unbound. I don't see much harm with this function, but can catch cleanup
>>>> errors.
>>>
>>> Do you mean we'll crash on a NULL pointer dereference instead of
>>> accessing freed memory if this happens ? I suppose it's marginally
>>> better :-)
>>
>> Generally speaking I think it's significantly better. Accessing freed
>> memory might go unnoticed for a long time, and might not cause any
>> errors or cause randomly some minor errors. Here we might not even be
>> accessing freed memory, as the source sd is probably still there, so
>> KASAN wouldn't catch it.
>>
>> In this particular case it might not matter that much. The source_sd is
>> only used when starting streaming, so the chances are quite small that
>> we'd end up there after the unbind.
>>
>> Still, I think it's a very good practice to NULL the pointers when
>> they're no longer valid.
>
> Fine with me.
>
>>>>>> +}
>>>
>>> [snip]
>>>
>>>>>> +static int ub960_create_subdev(struct ub960_data *priv)
>>>>>> +{
>>>>>> + struct device *dev = &priv->client->dev;
>>>>>> + unsigned int i;
>>>>>> + int ret;
>>>>>> +
>>>>>> + v4l2_i2c_subdev_init(&priv->sd, priv->client, &ub960_subdev_ops);
>>>>>
>>>>> A blank line would be nice.
>>>>
>>>> Ok.
>>>>
>>>>>> + v4l2_ctrl_handler_init(&priv->ctrl_handler, 1);
>>>>>
>>>>> You create two controls.
>>>>
>>>> Yep. Although I dropped TPG, so only one again.
>>>>
>>>>>> + priv->sd.ctrl_handler = &priv->ctrl_handler;
>>>>>> +
>>>>>> + v4l2_ctrl_new_std_menu_items(&priv->ctrl_handler, &ub960_ctrl_ops,
>>>>>> + V4L2_CID_TEST_PATTERN,
>>>>>> + ARRAY_SIZE(ub960_tpg_qmenu) - 1, 0, 0,
>>>>>> + ub960_tpg_qmenu);
>>>>>> +
>>>>>> + v4l2_ctrl_new_int_menu(&priv->ctrl_handler, NULL, V4L2_CID_LINK_FREQ,
>>>>>> + ARRAY_SIZE(priv->tx_link_freq) - 1, 0,
>>>>>> + priv->tx_link_freq);
>>>>>> +
>>>>>> + if (priv->ctrl_handler.error) {
>>>>>> + ret = priv->ctrl_handler.error;
>>>>>> + goto err_free_ctrl;
>>>>>> + }
>>>>>> +
>>>>>> + priv->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
>>>>>> + V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_STREAMS;
>>>>>> + priv->sd.entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
>>>>>> + priv->sd.entity.ops = &ub960_entity_ops;
>>>>>> +
>>>>>> + for (i = 0; i < priv->hw_data->num_rxports + priv->hw_data->num_txports; i++) {
>>>>>> + priv->pads[i].flags = ub960_pad_is_sink(priv, i) ?
>>>>>> + MEDIA_PAD_FL_SINK :
>>>>>> + MEDIA_PAD_FL_SOURCE;
>>>>>> + }
>>>>>> +
>>>>>> + ret = media_entity_pads_init(&priv->sd.entity,
>>>>>> + priv->hw_data->num_rxports +
>>>>>> + priv->hw_data->num_txports,
>>>>>
>>>>> :-(
>>>>
>>>> I don't have strong opinion on this, but don't you find it a bit
>>>> confusing if a single argument spans multiple lines but without any indent?
>>>>
>>>> With a quick look, this looks like a call with 4 arguments:
>>>>
>>>> ret = media_entity_pads_init(&priv->sd.entity,
>>>> priv->hw_data->num_rxports +
>>>> priv->hw_data->num_txports,
>>>> priv->pads);
>>>
>>> I suppose I'm used to it, so it appears more readable to me. It's also
>>> the style used through most of the kernel. There's of course always the
>>> option of storing the result of the computation in a local variable.
>>
>> I'll be happy to indent like that if someone tells me how to configure
>> clang-format to do that =). I didn't figure it out.
>
> Setting ContinuationIndentWidth to 0 "fixes" it, but I suspect it may
> have other side effects.
Yes, it creates some funny indenting, like:
ret =
func(......);
> This being said, running clang-format on this file gives me a diffstat
> of 450 insertions(+), 365 deletions(-), so I don't think you can rely on
> it blindly...
True, although I the bulk of those are with the #defines and structs.
Tomi
next prev parent reply other threads:[~2023-01-25 11:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-20 15:34 [PATCH v8 0/7] i2c-atr and FPDLink Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 1/7] i2c: add I2C Address Translator (ATR) support Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 2/7] dt-bindings: media: add TI DS90UB913 FPD-Link III Serializer Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 3/7] dt-bindings: media: add TI DS90UB953 " Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 4/7] dt-bindings: media: add TI DS90UB960 FPD-Link III Deserializer Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 5/7] media: i2c: add DS90UB960 driver Tomi Valkeinen
2023-01-23 22:04 ` Laurent Pinchart
2023-01-24 14:48 ` Tomi Valkeinen
2023-01-24 18:27 ` Laurent Pinchart
2023-01-25 7:39 ` Tomi Valkeinen
2023-01-25 10:13 ` Laurent Pinchart
2023-01-25 11:34 ` Tomi Valkeinen [this message]
2023-01-25 11:41 ` Andy Shevchenko
2023-01-20 15:34 ` [PATCH v8 6/7] media: i2c: add DS90UB913 driver Tomi Valkeinen
2023-01-20 15:34 ` [PATCH v8 7/7] media: i2c: add DS90UB953 driver Tomi Valkeinen
2023-01-20 15:37 ` [PATCH v8 0/7] i2c-atr and FPDLink Tomi Valkeinen
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=a59ea457-58df-0058-ddaf-c605e5432864@ideasonboard.com \
--to=tomi.valkeinen@ideasonboard.com \
--cc=Matti.Vaittinen@fi.rohmeurope.com \
--cc=andriy.shevchenko@intel.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=hverkuil@xs4all.nl \
--cc=khalasa@piap.pl \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=lgirdwood@gmail.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=m.tretter@pengutronix.de \
--cc=marex@denx.de \
--cc=mchehab@kernel.org \
--cc=mpagano@gentoo.org \
--cc=peda@axentia.se \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=satish.nagireddy@getcruise.com \
--cc=shawnx.tu@intel.com \
--cc=wsa@kernel.org \
/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