linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Linus Walleij <linus.walleij@linaro.org>
Subject: Re: [PATCH 1/1] gpio: add sloppy logic analyzer using polling
Date: Mon, 6 Sep 2021 11:04:00 +0200	[thread overview]
Message-ID: <YTXZgNQJj0aI4zuC@kunai> (raw)
In-Reply-To: <CAHp75VdZt_dDb0YpThfsoqRvWdjfVZT70o=eCJCbThJ9qbD42w@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4917 bytes --]

Hi Andy,

thank you for the review again!

> > +       unsigned long state = 0; /* zeroed because GPIO arrays are bitfields */
> 
> Not sure if bitmap_zero() would be better. Up to you.

Looks cleaner, I'll check.

> > +static int fops_buf_size_set(void *data, u64 val)
> > +{
> > +       struct gpio_la_poll_priv *priv = data;
> > +       int ret = 0;
> > +       void *p;
> > +
> > +       if (!val)
> 
> > +               return -EINVAL;
> 
> Hmm... in this case you haven't updated the internal parameters, but...
> 
> > +       mutex_lock(&priv->lock);
> > +
> > +       vfree(priv->blob.data);
> > +       p = vzalloc(val);
> > +       if (!p) {
> > +               val = 0;
> > +               ret = -ENOMEM;
> 
> ...here you do. What's the difference?

vfree(). In the latter case, the old buffer is already gone.


> > +       if (ret >= 0 && ret != priv->descs->ndescs)
> 
> > +               ret = -ENOSTR;
> 
> A bit of an unusual error code.
> Perhaps -ENODATA?

OK, as long as it is unique...

> > +               /* '10' is length of 'probe00=\n\0' */
> 
> Maybe instead of comment is to use respective strlen():s / sizeof():s?
> 
> Actually, looking below possible option is
> 
> const char *fmt = "probe...";
> 
> add_len += sprintf(NULL, 0, fmt, 0, "");
> 
> ...
> 
> snprintf(..., fmt, ...);
> 
> But it's up to you.
> 
> > +               add_len = strlen(gpio_names[i]) + 10;
> > +
> > +               new_meta = devm_krealloc(dev, meta, meta_len + add_len, GFP_KERNEL);
> > +               if (!new_meta)
> > +                       return -ENOMEM;
> > +
> > +               meta = new_meta;
> > +               snprintf(meta + meta_len, add_len, "probe%02d=%s\n", i + 1, gpio_names[i]);
> 
> > +               /* ' - 1' to skip the NUL terminator */
> > +               meta_len += add_len - 1;
> 
> Reuse return value from snprintf()?

I will have a look at these string refactorings when I need the analyzer
next time and come back then.

> 
> > +       }
> 
> ...
> 
> > +static int gpio_la_poll_remove(struct platform_device *pdev)
> > +{
> > +       struct gpio_la_poll_priv *priv = platform_get_drvdata(pdev);
> > +
> > +       mutex_lock(&priv->lock);
> > +       debugfs_remove_recursive(priv->debug_dir);
> > +       mutex_unlock(&priv->lock);
> 
> mutex_destroy()?

Oh yes, thank you!

> 
> > +
> > +       return 0;
> > +}
> 
> ...
> 
> > +#!/bin/sh -eu
> 
> Next step is to add 'f' to the mix here :-)

-f broke zip file generation in a way I didn't know how to resolve
differently. Sadly, I can't recall the details right now.

> 
> ...
> 
> > +$0 - helper script for the Linux Kernel Sloppy GPIO Logic Analyzer
> 
> Use at the top something like
> 
> PROG_NAME="${0##*/}"

I like this!

> echo "$2'
> exit $1

I don't see the need now. We can update if we need it.

> > +       [ -n "$cur_cpu" ] && fail "CPU$isol_cpu requested but CPU$cur_cpu already isolated"
> 
> This theoretically may fail the script since you have '-e'.
> I guess I have mentioned that 'a && b' is not an equivalent to 'if-then-fi'.
> I suggest double checking all similar expressions and try under
> different shells (like dash).

Well, from the cover-letter:

* A *lot* of cleanups to the shell script guided by checkers, mainly
  'shellcheck'. This is mainly to ensure that the scripts works on most
  minimal shells. Tested are 'busybox ash', 'dash', and 'bash'.

> > +       [ -w "$cpufreqgov" ] && echo 'performance' > "$cpufreqgov" || true
> 
> I guess this is where you actually hit the above mentioned difference.

I used a different kernel on a different SoC which did not have CPUfreq
at all.

> 
> ...
> 
> > +while true; do
> > +       case "$1" in
> > +       -c|--cpu) initcpu="$2"; shift 2;;
> > +       -d|--duration-us) duration="$2"; shift 2;;
> > +       -h|--help) print_help; exit 0;;
> > +       -i|--instance) lasysfsdir="$sysfsdir/$2"; shift 2;;
> > +       -k|--kernel-debug-dir) debugdir="$2"; shift 2;;
> > +       -n|--num_samples) numsamples="$2"; shift 2;;
> > +       -o|--output-dir) outputdir="$2"; shift 2;;
> > +       -s|--sample_freq) samplefreq="$2"; shift 2;;
> > +       -t|--trigger) triggerdat="$2"; shift 2;;
> > +       --)     shift; break;;
> > +       *)      fail "error parsing commandline: $*";;
> > +       esac
> 
> I would prefer to have a clear shift here instead of doing shift 2
> everywhere above (less error prone).

If we ever support binary arguments (toggles), then a generic 'shift 2'
won't work?

> 
> > +done
> 
> ...
> 
> I think usage of SI units makes sense to be less error prone in case
> you are using them more than once.

SI would be useful, for sure. But I need to move on right now, so it
needs to be done incrementally.

All the best,

   Wolfram


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-09-06  9:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 19:45 [PATCH 0/1] gpio: add simple logic analyzer using polling Wolfram Sang
2021-09-01 19:45 ` [PATCH 1/1] gpio: add sloppy " Wolfram Sang
2021-09-05 11:20   ` Andy Shevchenko
2021-09-06  9:04     ` Wolfram Sang [this message]
2021-09-06 10:15       ` Andy Shevchenko
2021-09-06 12:21         ` Wolfram Sang
     [not found]   ` <CAHp75VdNnvUfMEL3gMrJOFix3AATL8LAiU18LXJJVL77feBRow@mail.gmail.com>
2021-09-06  7:38     ` Wolfram Sang
2021-09-06  7:47       ` 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=YTXZgNQJj0aI4zuC@kunai \
    --to=wsa+renesas@sang-engineering.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@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;
as well as URLs for NNTP newsgroup(s).