public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Luke Jones <luke@ljones.dev>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <markgross@kernel.org>,
	Platform Driver <platform-driver-x86@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] asus-wmi: Add support for ROG X13 tablet mode
Date: Tue, 09 Aug 2022 19:22:54 +1200	[thread overview]
Message-ID: <667CGR.TI5EUKB68MWN2@ljones.dev> (raw)
In-Reply-To: <CAHp75Vda5KX5pVrNeueQEODoEy405eTb9SYJtts-Lm9jMNocHQ@mail.gmail.com>



On Tue, Aug 9 2022 at 09:12:37 +0200, Andy Shevchenko 
<andy.shevchenko@gmail.com> wrote:
> On Tue, Aug 9, 2022 at 5:26 AM Luke Jones <luke@ljones.dev> wrote:
> 
> ...
> 
>>  >>  +                       pr_err("This device has lid-flip-rog 
>> quirk
>>  >> but got ENODEV checking it. This is a bug.");
>>  >
>>  > dev_err() ?
>> 
>>  Okay, changed here and in previous patch to match it.
>> 
>>  So that I'm clearer on dev_err(), this doesn't do something like 
>> exit
>>  the module does it? It's just a more detailed error print?
> 
> Yes, it's more specific when the user sees it. The pr_err() is global
> and anonymous (you can only point to the driver, and not the instance
> of the device bound to it), while dev_err() is device specific and the
> user will immediately see which device instance is failing. Yet it's
> not a problem for this particular driver, because I don't believe one
> may have two, but it's a good coding practice in general.
> 
> (Note the last sentence: "good coding practice")
> 
> ...
> 
>>  >>  +static void lid_flip_rog_tablet_mode_get_state(struct asus_wmi
>>  >> *asus)
>>  >>  +{
>>  >>  +       int result = asus_wmi_get_devstate_simple(asus,
>>  >> ASUS_WMI_DEVID_LID_FLIP_ROG);
>>  >>  +
>>  >>  +       if (result >= 0) {
>>  >
>>  > First of all, it's better to decouple assignment and definition, 
>> and
>>  > move assignment closer to its user. This is usual pattern.
>> 
>>  I don't fully understand why you would want the separation given how
>>  short these two blocks are (I'll change in this and previous patch 
>> of
>>  course, I just don't personally understand it).
> 
> See above, "good coding practice". Why?
> 
> Imagine your code to be in hypothetical v5.10:
> 
>   int x = foo(param1, param2, ...);
> 
>   if (x)
>     return Y;
> 
> 
> Now, at v5.12 somebody adds a new feature which touches your code:
> 
>   int x = foo(param1, param2, ...);
>   struct bar *baz;
> 
>   if (we_have_such_feature_disabled)
>     return Z;
> 
>   if (x)
>     return Y;
> 
>   baz = ...
> 
> And then somebody else in v5.13 does another feature:
> 
>   int x = foo(param1, param2, ...);
>   struct bar *baz;
> 
>   if (we_have_such_feature_disabled)
>     return Z;
> 
>   /* parameter 1 can be NULL, check it */
>   if (!param1)
>     return -EINVAL;
> 
>   if (x)
>     return Y;
> 
>   baz = ...
> 
> Do you see now an issue? If you emulate this as a sequence of Git
> changes the last one is easily missing subtle detail. That's why "good
> coding practice".
> 
> --
> With Best Regards,
> Andy Shevchenko

That's a great example! Thanks mate, really appreciate it.




  reply	other threads:[~2022-08-09  7:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  3:11 [PATCH v2 0/2] asus-wmi: add support for ROG XFlow tablet mode Luke D. Jones
2022-08-08  3:11 ` [PATCH v2 1/2] asus-wmi: Adjust tablet/lidflip handling to use enum Luke D. Jones
2022-08-08 15:48   ` Andy Shevchenko
2022-08-08 16:13     ` Hans de Goede
2022-08-08 16:24       ` Andy Shevchenko
2022-08-08 17:18         ` Hans de Goede
2022-08-08  3:11 ` [PATCH v2 2/2] asus-wmi: Add support for ROG X13 tablet mode Luke D. Jones
2022-08-08 15:52   ` Andy Shevchenko
2022-08-09  3:26     ` Luke Jones
2022-08-09  7:12       ` Andy Shevchenko
2022-08-09  7:22         ` Luke Jones [this message]
2022-08-08 15:46 ` [PATCH v2 0/2] asus-wmi: add support for ROG XFlow " Andy Shevchenko

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=667CGR.TI5EUKB68MWN2@ljones.dev \
    --to=luke@ljones.dev \
    --cc=andy.shevchenko@gmail.com \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.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