[PATCH v4 1/1] RISC-V: Create unique identification for SoC PMU

Geert Uytterhoeven geert at linux-m68k.org
Mon Jun 20 00:50:14 PDT 2022


Hi Nikita,

On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin <nikita.shubin at maquefel.me> wrote:
> From: Nikita Shubin <n.shubin at yadro.com>
>
> Provide RISC-V SBI PMU id to distinguish different cores or SoCs via
> "devices/platform/riscv-pmu/id" sysfs entry.
>
> The identification is generated as string of marchid, mimpid, mvendorid
> in hex format separated by coma - "0x70032,0x70032,0x0".
>
> The CSRs are detailed in the RISC-V privileged spec [1].
> [1] https://github.com/riscv/riscv-isa-manual
>
> Inspired-by: João Mário Domingos <joao.mario at tecnico.ulisboa.pt>
> Signed-off-by: Nikita Shubin <n.shubin at yadro.com>

Thanks for your patch!

> --- a/arch/riscv/kernel/sbi.c
> +++ b/arch/riscv/kernel/sbi.c

> --- a/drivers/perf/riscv_pmu_sbi.c
> +++ b/drivers/perf/riscv_pmu_sbi.c
> @@ -693,6 +693,28 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde
>         return 0;
>  }
>
> +static ssize_t id_show(struct device *dev,
> +                               struct device_attribute *attr, char *buf)
> +{
> +       int len;
> +       struct riscv_pmu *pmu = container_of(dev_get_drvdata(dev), struct riscv_pmu, pmu);
> +
> +       len = sprintf(buf, "%s\n", pmu->pmuid);
> +       if (len <= 0)
> +               dev_err(dev, "invalid sprintf len: %d\n", len);

How can this fail?

Please use sysfs_emit() instead of sprintf(), and drop the error
message.

> +
> +       return len;
> +}

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds



More information about the linux-riscv mailing list