RE: [PATCH] spi: Fix invalid sgs value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Geert,

> Subject: Re: [PATCH] spi: Fix invalid sgs value
> 
> Hi Biju,
> 
> On Mon, Mar 7, 2022 at 7:17 PM Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> wrote:
> > > Subject: Re: [PATCH] spi: Fix invalid sgs value On Mon, Mar 7, 2022
> > > at 7:01 PM Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> > > wrote:
> > > > max_seg_size is unsigned int and it can have a value up to 2^32
> > > > (for eg:-RZ_DMAC driver sets dma_set_max_seg_size as U32_MAX) When
> > > > this value is used in min_t() as an integer type, it becomes
> > > > -1 and the value of sgs becomes 0.
> > > >
> > > > Fix this issue by replacing the 'int' data type with 'unsigned int'
> > > > in min_t().
> > > >
> > > > Signed-off-by: Biju Das <biju.das.jz@xxxxxxxxxxxxxx>
> > > > Reviewed-by: Lad Prabhakar
> > > > <prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx>
> > >
> > > Thanks for your patch!
> > >
> > > > --- a/drivers/spi/spi.c
> > > > +++ b/drivers/spi/spi.c
> > > > @@ -1019,10 +1019,10 @@ int spi_map_buf(struct spi_controller
> > > > *ctlr,
> > > struct device *dev,
> > > >         int i, ret;
> > > >
> > > >         if (vmalloced_buf || kmap_buf) {
> > > > -               desc_len = min_t(int, max_seg_size, PAGE_SIZE);
> > > > +               desc_len = min_t(unsigned int, max_seg_size,
> > > > + PAGE_SIZE);
> > > >                 sgs = DIV_ROUND_UP(len + offset_in_page(buf),
> desc_len);
> > > >         } else if (virt_addr_valid(buf)) {
> > > > -               desc_len = min_t(int, max_seg_size, ctlr-
> >max_dma_len);
> > > > +               desc_len = min_t(unsigned int, max_seg_size,
> > > > + (unsigned int)ctlr->max_dma_len);
> > >
> > > The cast of the last parameter is not needed.
> >
> > OK. I thought since last param is size_t, casting is required.
> 
> That's exactly what min_t() does, but using an easier-to-grep-for
> notation:
> "min_t(type, a, b)" is equivalent to "min((type)a, (type)b)".

Thanks for clarification.

Cheers,
Biju




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux