From: Jeff LaBundy <jeff@labundy.com>
To: Stephan Gerhold <stephan@gerhold.net>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Henrik Rydberg <rydberg@bitmath.org>,
linux-input@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
Jonathan Albrieux <jonathan.albrieux@gmail.com>
Subject: Re: [PATCH 2/2] Input: add Himax HX852x(ES) touchscreen driver
Date: Sun, 22 Oct 2023 13:28:14 -0500 [thread overview]
Message-ID: <ZTVpvlkORe4E41vy@nixie71> (raw)
In-Reply-To: <ZRg-uZskk07jxup0@gerhold.net>
Hi Stephan,
On Sat, Sep 30, 2023 at 05:28:57PM +0200, Stephan Gerhold wrote:
[...]
> In v2 I have added linux/of.h and linux/mod_devicetable.h, since I'm
> actually using definitions from these two only. Seems like including
> of_device.h is discouraged nowadays, see commit dbce1a7d5dce ("Input:
> Explicitly include correct DT includes").
Apologies for the delayed response and some confusion from my side. What
you have added in v2 is correct, and what I should have suggested in the
first place.
[...]
> > Nit: it would still be nice to preserve as many return values as possible, perhaps
> > as follows:
> >
> > +exit_test_mode:
> > error = i2c_smbus_write_byte_data(...) ? : error;
> >
> > > +power_off:
> > > + hx852x_power_off(hx);
> > > + return error;
> >
> > Similarly, with hx852x_power_off() being promoted to int as suggested above,
> > this could be:
> >
> > return hx852x_power_off(...) ? : error;
> >
> > There are other idiomatic ways to do the same thing based on your preference.
> > Another (perhaps more clear) option would be to move some of these test mode
> > functions into a helper, which would also avoid some goto statements.
> >
>
> I played with this for a bit. A problem of the "? : error" approach is
> that it hides the original error in case the new calls error again.
That's correct; good catch.
>
> Let's assume
>
> error = hx852x_start(hx);
> if (error)
> goto power_off;
>
> fails with error = -ENXIO. We jump to power_off:
>
> power_off:
> return hx852x_power_off(hx) ? : error;
>
> Let's say for whatever reason hx852x_power_off() fails too but returns
> -EINVAL. Then the final return value will be -EINVAL, while with the
> current approach in this patch it would return the original cause
> (-ENXIO). I think that's more clear.
>
> I also played with moving code to a separate function to avoid the
> gotos, but I feel like that makes the fairly focused logic of this
> function (reading the configuration by temporarily entering the test
> mode) just more confusing.
>
> To still fix the error handling I ended up with duplicating the
> "success" code path and the "error" code path (it's just two function
> calls), i.e.:
>
> error = i2c_smbus_write_byte_data(hx->client, HX852X_REG_SRAM_SWITCH, 0);
> if (error)
> goto err_power_off;
>
> return hx852x_power_off(hx);
>
> err_test_mode:
> i2c_smbus_write_byte_data(hx->client, HX852X_REG_SRAM_SWITCH, 0);
> err_power_off:
> hx852x_power_off(hx);
> return error;
>
> I hope that's fine too. A bit ugly maybe but in this case I would prefer
> having the main code path (reading the configuration) clearly readable.
>
> Let me know if you have a better suggestion for these (I'll send v2 in a
> bit so that you can see the full diff there).
Maybe we can massage this just a bit more; I have followed up with another
suggestion in v2.
>
> Thanks!
> Stephan
Kind regards,
Jeff LaBundy
next prev parent reply other threads:[~2023-10-22 18:28 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 13:25 [PATCH 0/2] Input: add Himax HX852x(ES) touchscreen driver Stephan Gerhold
2023-09-13 13:25 ` [PATCH 1/2] dt-bindings: input: touchscreen: document Himax HX852x(ES) Stephan Gerhold
2023-09-14 6:22 ` Krzysztof Kozlowski
2023-09-13 13:25 ` [PATCH 2/2] Input: add Himax HX852x(ES) touchscreen driver Stephan Gerhold
2023-09-16 20:47 ` Jeff LaBundy
2023-09-17 17:05 ` Stephan Gerhold
2023-09-27 2:59 ` Jeff LaBundy
2023-09-30 14:27 ` Stephan Gerhold
2023-09-30 15:28 ` Stephan Gerhold
2023-10-22 18:28 ` Jeff LaBundy [this message]
2023-09-17 6:03 ` Christophe JAILLET
2023-09-17 16:37 ` Jeff LaBundy
2023-09-17 17:15 ` Stephan Gerhold
2023-09-17 17:58 ` Christophe JAILLET
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=ZTVpvlkORe4E41vy@nixie71 \
--to=jeff@labundy.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jonathan.albrieux@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=rydberg@bitmath.org \
--cc=stephan@gerhold.net \
/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).