Re: [PATCH 1/4] dmaengine: dw: Add peripheral bus width verification
From: Andy Shevchenko
Date: Thu Apr 18 2024 - 05:45:01 EST
On Wed, Apr 17, 2024 at 10:54:42PM +0300, Serge Semin wrote:
> On Tue, Apr 16, 2024 at 09:00:50PM +0300, Andy Shevchenko wrote:
> > On Tue, Apr 16, 2024 at 07:28:55PM +0300, Serge Semin wrote:
..
> > > + if (reg_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
> > > + reg_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
> > > + else if (!is_power_of_2(reg_width) || reg_width > max_width)
> > > + return -EINVAL;
> > > + else /* bus width is valid */
> > > + return 0;
> > > +
> > > + /* Update undefined addr width value */
> > > + if (dwc->dma_sconfig.direction == DMA_MEM_TO_DEV)
> > > + dwc->dma_sconfig.dst_addr_width = reg_width;
> > > + else /* DMA_DEV_TO_MEM */
> > > + dwc->dma_sconfig.src_addr_width = reg_width;
> >
>
> > So, can't you simply call clamp() for both fields in dwc_config()?
>
> Alas I can't. Because the addr-width is the non-memory peripheral
> setting. We can't change it since the client drivers calculate it on
> the application-specific basis (CSR widths, transfer length, etc). So
> we must make sure that the specified value is supported.
What I meant is to convert this "update" part to the clamping, so
we will have the check as the above like
_verify_()
{
if (reg_width == DMA_SLAVE_BUSWIDTH_UNDEFINED)
return -E...;
if (!is_power_of_2(reg_width) || reg_width > max_width)
return -EINVAL;
/* bus width is valid */
return 0;
}
dwc_config()
{
err = ...
if (err = ...)
clamp?
else if (err)
return err;
}
But it's up to you to choose the better variant. I just share the idea.
> > > + return 0;
> > > +}
..
> > > + int err;
>
> > Hmm... we have two functions one of which is using different name for this.
>
> Right, the driver uses both variants (see of.c, platform.c, pci.c too).
>
> > Can we have a patch to convert to err the other one?
>
> To be honest I'd prefer to use the "ret" name instead. It better
> describes the variable usage context (Although the statements like "if
> (err) ..." look a bit more readable). So I'd rather convert the "err"
> vars to "ret". What do you think?
I'm fine with any choice, just my point is to get it consistent across
the driver.
--
With Best Regards,
Andy Shevchenko