All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Deepak R Varma <mh12gx2825@gmail.com>
Cc: outreachy-kernel@googlegroups.com, gregkh@linuxfoundation.org,
	daniel.baluta@gmail.com
Subject: Re: [Outreachy kernel] [PATCH v2 3/4] staging: fbtft: simplify array index computation
Date: Sun, 15 Mar 2020 22:46:34 +0100	[thread overview]
Message-ID: <20200315224634.65f3efda@elisabeth> (raw)
In-Reply-To: <34620c89e9ecfd91ef35571fa1a167f33c777d52.1584105606.git.mh12gx2825@gmail.com>

Hmm, this isn't exactly simplifying if one looks at the diffstat:

On Fri, 13 Mar 2020 19:14:02 +0530
Deepak R Varma <mh12gx2825@gmail.com> wrote:

> An array index is being computed by mathematical calculation on the
> Lvalue side of the expression. This also further results in the staement
> exceeding 80 character statement length.
> 
> A local variable can store the value of the array index computation. The
> variable can then be used as array index. This improves readability of
> the code and also address 80 character warning raised by checkpatch.
> 
> Signed-off-by: Deepak R Varma <mh12gx2825@gmail.com>
> ---
>  drivers/staging/fbtft/fbtft-sysfs.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

More on that below:

> 
> diff --git a/drivers/staging/fbtft/fbtft-sysfs.c b/drivers/staging/fbtft/fbtft-sysfs.c
> index 2a5c630dab87..4d505a13f7ab 100644
> --- a/drivers/staging/fbtft/fbtft-sysfs.c
> +++ b/drivers/staging/fbtft/fbtft-sysfs.c
> @@ -25,6 +25,7 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
>  	unsigned long val = 0;
>  	int ret = 0;
>  	int curve_counter, value_counter;
> +	int counter = 0;

...there's no need to initialise this.

>  
>  	fbtft_par_dbg(DEBUG_SYSFS, par, "%s() str=\n", __func__);
>  
> @@ -68,7 +69,10 @@ int fbtft_gamma_parse_str(struct fbtft_par *par, u32 *curves,
>  			ret = get_next_ulong(&curve_p, &val, " ", 16);
>  			if (ret)
>  				goto out;
> -			curves[curve_counter * par->gamma.num_values + value_counter] = val;
> +
> +			counter = curve_counter * par->gamma.num_values +
> +					value_counter;

value_counter is summed to the whole thing, so it should be aligned
under curve_counter.

> +			curves[counter] = val;

And here, I think, the actual problem is variable naming itself. See
section "4) Naming" of Documentation/process/coding-style.rst -- this
looks a bit like Java. The "_counter" suffix doesn't add much here, I
guess those could just be "curve" and "value". I haven't checked for
ambiguities (could you have a look?), but if there's any, even "_count"
would make this a bit more tolerable.

-- 
Stefano



  reply	other threads:[~2020-03-15 21:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 13:41 [PATCH v2 0/4] staging: fbtft: code cleanup patchset - checkpatch Deepak R Varma
2020-03-13 13:42 ` [PATCH v2 1/4] staging: fbtft: Reformat line over 80 characters Deepak R Varma
2020-03-15 21:45   ` [Outreachy kernel] " Stefano Brivio
2020-03-13 13:43 ` [PATCH v2 2/4] staging: fbtft: Reformat long macro definitions Deepak R Varma
2020-03-15 21:46   ` [Outreachy kernel] " Stefano Brivio
2020-03-13 13:44 ` [PATCH v2 3/4] staging: fbtft: simplify array index computation Deepak R Varma
2020-03-15 21:46   ` Stefano Brivio [this message]
2020-03-13 13:44 ` [PATCH v2 4/4] staging: fbtft: Avoid potential precedence issues Deepak R Varma
2020-03-15 21:46   ` [Outreachy kernel] " Stefano Brivio

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=20200315224634.65f3efda@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=daniel.baluta@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=mh12gx2825@gmail.com \
    --cc=outreachy-kernel@googlegroups.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 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.