lkml.org 
[lkml]   [2020]   [Jun]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    Subject[PATCH][next] dmaengine: ti: k3-udma: Use struct_size() in kzalloc()
    Make use of the struct_size() helper instead of an open-coded version
    in order to avoid any potential type mistakes.

    This code was detected with the help of Coccinelle and, audited and
    fixed manually.

    Addresses-KSPP-ID: https://github.com/KSPP/linux/issues/83
    Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
    ---
    drivers/dma/ti/k3-udma.c | 4 ++--
    1 file changed, 2 insertions(+), 2 deletions(-)

    diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
    index 0d5fb154b8e2..411c54b86ba8 100644
    --- a/drivers/dma/ti/k3-udma.c
    +++ b/drivers/dma/ti/k3-udma.c
    @@ -2209,7 +2209,7 @@ udma_prep_slave_sg_pkt(struct udma_chan *uc, struct scatterlist *sgl,
    u32 ring_id;
    unsigned int i;

    - d = kzalloc(sizeof(*d) + sglen * sizeof(d->hwdesc[0]), GFP_NOWAIT);
    + d = kzalloc(struct_size(d, hwdesc, sglen), GFP_NOWAIT);
    if (!d)
    return NULL;

    @@ -2525,7 +2525,7 @@ udma_prep_dma_cyclic_pkt(struct udma_chan *uc, dma_addr_t buf_addr,
    if (period_len >= SZ_4M)
    return NULL;

    - d = kzalloc(sizeof(*d) + periods * sizeof(d->hwdesc[0]), GFP_NOWAIT);
    + d = kzalloc(struct_size(d, hwdesc, periods), GFP_NOWAIT);
    if (!d)
    return NULL;

    --
    2.27.0
    \
     
     \ /
      Last update: 2020-06-20 00:38    [W:3.663 / U:0.268 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site