All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Witten <mfwitten@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] openprom: Fix 'opiocnextprop'; ensure integer conversions; use string size
Date: Fri, 25 Sep 2020 20:20:20 +0000	[thread overview]
Message-ID: <859f327c79da4d9c945e50568805456c@gmail.com> (raw)
In-Reply-To: <20200914.170321.1710628974878239639.davem@davemloft.net>

From: David Miller <davem@davemloft.net>
Date: Mon, 14 Sep 2020 17:03:21 -0700

> From: Michael Witten <mfwitten@gmail.com>
> Date: Fri, 04 Sep 2020 19:40:00 -0000
>
>> @@ -34,10 +34,10 @@ EXPORT_SYMBOL(of_console_options);
>>  int of_getintprop_default(struct device_node *np, const char *name, int def)
>>  {
>>       struct property *prop;
>> -     int len;
>> +     int size;
>> 
>> -     prop = of_find_property(np, name, &len);
>> -     if (!prop || len != 4)
>> +     prop = of_find_property(np, name, &size);
>> +     if (!prop || size != 4)
>>               return def;
>
> This is just changing the variable name and makes no functional change
> at all, and therefore is gratuitous.
>
> Please only include pure functional changes that fix the bug(s) in
> question.
>
> [...]

There's a reason the variable is named "size" (or even "len") rather than:

  v75127e6344

A name is functional; it is the only way we have to structure a [human]
reader's conceptual understanding of what's going on.

The name "len" is a poor choice; it added to my uncertainty when I began
trying to understand the code in question.

As explained in the commit message:

  | String Size
  | =====  |
  | There is an important distinction to be made between the following:
  |
  |   * A nul-terminated string's size
  |   * A nul-terminated string's length
  |
  | This commit tries to make this distinction as much as possible,
  | and assumes that all strings are intended to be nul-terminated.
  | The result is the following:
  |
  |   * Sometimes a variable's name is simply changed (e.g., from
  |     'len' to 'size').
  |
  |   * Sometimes 'strlen()' is called rather than relying on
  |     some buffer size.
  |
  |   * Sometimes, there is the replacement of code that erroneously
  |     uses string length rather than string size.
  |
  | All together, these changes make the code more robust and correct.

Are we trying to improve the code or not?

Also, this name change is like a surgeon removing a benign anomaly
while the abdomen is open for some other purpose; it's strategic,
not "gratuitous".

Sincerely,
Michael Witten

WARNING: multiple messages have this Message-ID (diff)
From: Michael Witten <mfwitten@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC] openprom: Fix 'opiocnextprop'; ensure integer conversions; use string size
Date: Fri, 25 Sep 2020 20:20:20 -0000	[thread overview]
Message-ID: <859f327c79da4d9c945e50568805456c@gmail.com> (raw)
In-Reply-To: <20200914.170321.1710628974878239639.davem@davemloft.net>

From: David Miller <davem@davemloft.net>
Date: Mon, 14 Sep 2020 17:03:21 -0700

> From: Michael Witten <mfwitten@gmail.com>
> Date: Fri, 04 Sep 2020 19:40:00 -0000
>
>> @@ -34,10 +34,10 @@ EXPORT_SYMBOL(of_console_options);
>>  int of_getintprop_default(struct device_node *np, const char *name, int def)
>>  {
>>       struct property *prop;
>> -     int len;
>> +     int size;
>> 
>> -     prop = of_find_property(np, name, &len);
>> -     if (!prop || len != 4)
>> +     prop = of_find_property(np, name, &size);
>> +     if (!prop || size != 4)
>>               return def;
>
> This is just changing the variable name and makes no functional change
> at all, and therefore is gratuitous.
>
> Please only include pure functional changes that fix the bug(s) in
> question.
>
> [...]

There's a reason the variable is named "size" (or even "len") rather than:

  v75127e6344

A name is functional; it is the only way we have to structure a [human]
reader's conceptual understanding of what's going on.

The name "len" is a poor choice; it added to my uncertainty when I began
trying to understand the code in question.

As explained in the commit message:

  | String Size
  | ===========
  |
  | There is an important distinction to be made between the following:
  |
  |   * A nul-terminated string's size
  |   * A nul-terminated string's length
  |
  | This commit tries to make this distinction as much as possible,
  | and assumes that all strings are intended to be nul-terminated.
  | The result is the following:
  |
  |   * Sometimes a variable's name is simply changed (e.g., from
  |     'len' to 'size').
  |
  |   * Sometimes 'strlen()' is called rather than relying on
  |     some buffer size.
  |
  |   * Sometimes, there is the replacement of code that erroneously
  |     uses string length rather than string size.
  |
  | All together, these changes make the code more robust and correct.

Are we trying to improve the code or not?

Also, this name change is like a surgeon removing a benign anomaly
while the abdomen is open for some other purpose; it's strategic,
not "gratuitous".

Sincerely,
Michael Witten

  reply	other threads:[~2020-09-25 20:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 19:40 [RFC] openprom: Fix 'opiocnextprop'; ensure integer conversions; use string size Michael Witten
2020-09-04 19:40 ` Michael Witten
2020-09-15  0:03 ` David Miller
2020-09-15  0:03   ` David Miller
2020-09-25 20:20   ` Michael Witten [this message]
2020-09-25 20:20     ` Michael Witten
2020-09-25 20:45     ` David Miller
2020-09-25 20:45       ` David Miller
2020-10-13  5:14 ` Randy Dunlap
2020-10-13  5:14   ` Randy Dunlap
2020-10-14  6:40 ` Randy Dunlap
2020-10-14  6:40   ` Randy Dunlap
2020-11-25 21:59 ` Randy Dunlap
2020-11-25 21:59   ` Randy Dunlap

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=859f327c79da4d9c945e50568805456c@gmail.com \
    --to=mfwitten@gmail.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sparclinux@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 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.