Re: [PATCH] bus: mhi: ep: Use kcalloc() instead of kzalloc()

From: Erick Archer
Date: Fri Feb 02 2024 - 12:49:05 EST


Hi Dan,

On Mon, Jan 29, 2024 at 08:20:26AM +0300, Dan Carpenter wrote:
> On Sun, Jan 28, 2024 at 11:29:33AM +0100, Erick Archer wrote:
> > > It's a bit concerning that ->event_rings is set multiple times, but only
> > > allocated one time. It's either unnecessary or there is a potential
> > > memory corruption bug. If it's really necessary then there should be a
> > > check that the new size is <= the size of the original buffer that we
> > > allocated.
> >
> > The ->event_rings is set twice. In the mhi_ep_mmio_init function and in
> > the mhi_ep_mmio_update_ner function.
> >
>
> It's not about the type.
>
> The event_rings struct member is the number of elements in the
> mhi_cntrl->mhi_event array. However, we ->event_rings without
> re-allocating mhi_cntrl->mhi_event so those are not in sync any more.
> So since we don't know the number of elements in the mhi_cntrl->mhi_event
> array leading to memory corruption.

Thanks for this clarification. Now I understand what you are explaining
to me.

Regards,
Erick