[Pdbg] [PATCH 5/7] libpdbg: Rescan fsi bus only once

Joel Stanley joel at jms.id.au
Tue Jun 9 17:28:57 AEST 2020


On Tue, 26 May 2020 at 05:13, Amitay Isaacs <amitay at ozlabs.org> wrote:
>
> On rescan, kernel driver re-creates all the slave devices.  This
> invalidates all the slave deviced opened before the scan.
>
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
>  libpdbg/kernel.c | 37 +++++++++++++++++++++----------------
>  1 file changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c
> index 2cc81f2..912895a 100644
> --- a/libpdbg/kernel.c
> +++ b/libpdbg/kernel.c
> @@ -116,6 +116,15 @@ static void kernel_fsi_scan_devices(void)
>         const char *kernel_path = kernel_get_fsi_path();
>         char *path;
>         int rc, fd;
> +       static bool scanned = false;
> +
> +       /*
> +        * On fsi bus rescan, kernel re-creates all the slave device entries.
> +        * It means any currently open devices will be invalid and need to be
> +        * re-opened.  So avoid scanning multiple times.
> +        */
> +       if (scanned)
> +               return;
>
>         if (!kernel_path)
>                 return;
> @@ -139,12 +148,13 @@ static void kernel_fsi_scan_devices(void)
>
>         free(path);
>         close(fd);
> +
> +       scanned = true;
>  }
>
>  int kernel_fsi_probe(struct pdbg_target *target)
>  {
>         struct fsi *fsi = target_to_fsi(target);
> -       int tries = 5;
>         int rc;
>         const char *kernel_path = kernel_get_fsi_path();
>         const char *fsi_path;
> @@ -162,24 +172,19 @@ int kernel_fsi_probe(struct pdbg_target *target)
>                 return rc;
>         }
>
> -       while (tries) {
> -               /* Open first raw device */
> -               fsi->fd = open(path, O_RDWR | O_SYNC);
> -               if (fsi->fd >= 0) {
> -                       free(path);
> -                       return 0;
> -               }
> -               tries--;
> -
> -               /* Scan */
> -               kernel_fsi_scan_devices();
> -               sleep(1);
> -       }
> -       if (fsi->fd < 0) {
> -               PR_ERROR("Unable to open %s\n", path);
> +       /* Always scan the fsi bus once */
> +       kernel_fsi_scan_devices();

As your comment says, this changes the behavior to always scan even if
the sysfs hierarchy is present. Previously it would try to open the
"raw" file on the first master and if it was present it wouldn't
disturb the setup.

Is there any reason you need to force a scan?

> +       sleep(1);
> +
> +       /* Open first raw device */
> +       fsi->fd = open(path, O_RDWR | O_SYNC);
> +       if (fsi->fd >= 0) {
>                 free(path);
> +               return 0;
>         }
>
> +       PR_ERROR("Unable to open %s\n", path);
> +       free(path);
>         return -1;
>  }
>
> --
> 2.26.2
>
> --
> Pdbg mailing list
> Pdbg at lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/pdbg


More information about the Pdbg mailing list