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

From: Nikita Shubin
Date: Mon Jun 20 2022 - 11:07:14 EST


Hello Geert!

On Mon, 20 Jun 2022 09:50:14 +0200
Geert Uytterhoeven <geert@xxxxxxxxxxxxxx> wrote:

> Hi Nikita,
>
> On Sun, Jun 19, 2022 at 1:11 PM Nikita Shubin
> <nikita.shubin@xxxxxxxxxxx> wrote:
> > From: Nikita Shubin <n.shubin@xxxxxxxxx>
> >
> > 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@xxxxxxxxxxxxxxxxxx>
> > Signed-off-by: Nikita Shubin <n.shubin@xxxxxxxxx>
>
> 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.

Indeed, thank you for your comments.

Also i missed some explicit free:

> > +out_free_pmuid:
> > + kfree(pmu->pmuid);

This is not needed.

>
> > +
> > + return len;
> > +}
>
> Gr{oetje,eeting}s,
>
> Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 --
> geert@xxxxxxxxxxxxxx
>
> 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