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

Nikita Shubin nikita.shubin at maquefel.me
Mon Jun 20 07:44:02 PDT 2022


Hello Geert!

On Mon, 20 Jun 2022 09:50:14 +0200
Geert Uytterhoeven <geert at linux-m68k.org> wrote:

> 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.

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 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-arm-kernel mailing list