linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tomasz Figa <tfiga@chromium.org>
To: Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Andy Yeh <andy.yeh@intel.com>,
	Linux Media Mailing List <linux-media@vger.kernel.org>,
	"Chen, JasonX Z" <jasonx.z.chen@intel.com>,
	Alan Chiang <alanx.chiang@intel.com>
Subject: Re: [PATCH v6] media: imx258: Add imx258 camera sensor driver
Date: Tue, 6 Mar 2018 18:28:43 +0900	[thread overview]
Message-ID: <CAAFQd5A20nP16kFZSfZ5T2pONA2D80VXhoR0pEwy=Ev1B+gH6Q@mail.gmail.com> (raw)
In-Reply-To: <20180306091814.rd3coopexzlmrhhf@paasikivi.fi.intel.com>

On Tue, Mar 6, 2018 at 6:18 PM, Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
> On Tue, Mar 06, 2018 at 05:51:36PM +0900, Tomasz Figa wrote:
>> On Tue, Mar 6, 2018 at 5:40 PM, Sakari Ailus
>> <sakari.ailus@linux.intel.com> wrote:
>> > Hi Tomasz and Andy,
>> >
>> > On Sat, Mar 03, 2018 at 12:43:59AM +0900, Tomasz Figa wrote:
>> > ...
>> >> > +static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)
>> >> > +{
>> >> > +       struct imx258 *imx258 =
>> >> > +               container_of(ctrl->handler, struct imx258, ctrl_handler);
>> >> > +       struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd);
>> >> > +       int ret = 0;
>> >> > +       /*
>> >> > +        * Applying V4L2 control value only happens
>> >> > +        * when power is up for streaming
>> >> > +        */
>> >> > +       if (pm_runtime_get_if_in_use(&client->dev) <= 0)
>> >> > +               return 0;
>> >>
>> >> I thought we decided to fix this to handle disabled runtime PM properly.
>> >
>> > Good point. I bet this is a problem in a few other drivers, too. How would
>> > you fix that? Check for zero only?
>> >
>>
>> bool need_runtime_put;
>>
>> ret = pm_runtime_get_if_in_use(&client->dev);
>> if (ret <= 0 && ret != -EINVAL)
>>         return ret;
>> need_runtime_put = ret > 0;
>>
>> // Do stuff ...
>>
>> if (need_runtime_put)
>>        pm_runtime_put(&client->dev);
>>
>> I don't like how ugly it is, but it appears to be the only way to
>> handle this correctly.
>
> The driver enables runtime PM so if runtime PM is enabled in kernel
> configuration, it is enabled here. In that case pm_runtime_get_if_in_use()
> will return either 0 or 1. So as far as I can see, changing the lines to:
>
>         if (!pm_runtime_get_if_in_use(&client->dev))
>                 return 0;
>
> is enough.

Right, my bad. Somehow I was convinced that enable status can change at runtime.

>
>> >> > +       ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
>> >> > +       if (ret)
>> >>
>> >> Missing error message.
>
> Same for this actually, printing an error message here isn't useful. It'd
> be just waiting for someone to clean it up. :-)

Fair enough.

>
>> >>
>> >> > +               return ret;
>> >> > +
>> >> > +       mutex_init(&imx258->mutex);
>> >> > +       ctrl_hdlr->lock = &imx258->mutex;
>> >> > +       imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
>> >> > +                               &imx258_ctrl_ops,
>> >> > +                               V4L2_CID_LINK_FREQ,
>> >> > +                               ARRAY_SIZE(link_freq_menu_items) - 1,
>> >> > +                               0,
>> >> > +                               link_freq_menu_items);
>> >> > +
>> >> > +       if (!imx258->link_freq) {
>> >> > +               ret = -EINVAL;
>> >>
>> >> Missing error message.
>> >
>> > I wouldn't add an error message here. Typically you'd need that information
>> > at development time only, never after that. v4l2_ctrl_new_int_menu(), as
>> > other control framework functions creating new controls, can fail due to
>> > memory allocation failure (which is already vocally reported) or due to bad
>> > parameters (that are constants).
>> >
>> > I'd rather do:
>> >
>> > if (!imx258->link_freq)
>> >         ... |= ...;
>> >
>> > It simplifies error handling and removes the need for goto.
>>
>> Hmm, I'm not sure I understand your suggestion. Do you perhaps mean
>>
>> if (imx258->link_freq) {
>>         // Do stuff that dereferences imx258->link_freq
>> }
>>
>> // ...
>>
>> if (ctrl_hdlr->error) {
>>         // Check for error only here, at the end of control initialization.
>> }
>>
>> then it would be better indeed.
>
> Yes, indeed.

SGTM.

Best regards,
Tomasz

  reply	other threads:[~2018-03-06  9:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-02 14:55 [PATCH v6] media: imx258: Add imx258 camera sensor driver Andy Yeh
2018-03-02 15:43 ` Tomasz Figa
2018-03-06  8:40   ` Sakari Ailus
2018-03-06  8:51     ` Tomasz Figa
2018-03-06  9:18       ` Sakari Ailus
2018-03-06  9:28         ` Tomasz Figa [this message]
2018-03-06  9:46           ` Sakari Ailus
2018-03-06  9:52             ` Tomasz Figa
2018-03-06 10:11               ` Sakari Ailus
2018-03-11 15:58   ` Yeh, Andy
  -- strict thread matches above, loose matches on Subject: below --
2018-03-01 15:34 Andy Yeh

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='CAAFQd5A20nP16kFZSfZ5T2pONA2D80VXhoR0pEwy=Ev1B+gH6Q@mail.gmail.com' \
    --to=tfiga@chromium.org \
    --cc=alanx.chiang@intel.com \
    --cc=andy.yeh@intel.com \
    --cc=jasonx.z.chen@intel.com \
    --cc=linux-media@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).