1

staging: rtl8712: remove unnecessary alignment of pxmitpriv->pxmitbuf

This driver wants pxmitpriv->pxmitbuf to be 4-byte aligned. This is ensured
by allocating 4 more bytes than required with kmalloc(), then do the
p = p + 4 - (p & 3) trick to make sure the pointer is 4-byte aligned.

This is unnecessary. Pointers from kmalloc() are already at least
8-byte-aligned.

Remove this alignment trick to simplify the code, and also to stop wasting
4 extra bytes of dynamic memory allocator.

This also gets rid of a (false) warning from kmemleak. This 4-byte-aligned
buffer is used to store pointers from kmalloc(). For 64-bit platforms,
pointer size is 8 bytes and kmemleak only scans for pointers in 8-byte
blocks, thus it misses the pointers stored in this 4-byte-aligned buffer
and thinks that these pointers have been leaked. This is just a false
warning, not a real problem. But still, it would be nice to get rid of
these warnings.

Reported-and-tested-by: syzbot+83763e624cfec6b462cb@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-staging/000000000000809328060a8a4c1c@google.com
Signed-off-by: Nam Cao <namcao@linutronix.de>
Link: https://lore.kernel.org/r/20240525073229.4144612-1-namcao@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Nam Cao 2024-05-25 09:32:29 +02:00 committed by Greg Kroah-Hartman
parent 8bcb9afc5d
commit 9ed3e0a0e1
2 changed files with 5 additions and 9 deletions

View File

@ -117,12 +117,9 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
/*init xmit_buf*/ /*init xmit_buf*/
_init_queue(&pxmitpriv->free_xmitbuf_queue); _init_queue(&pxmitpriv->free_xmitbuf_queue);
_init_queue(&pxmitpriv->pending_xmitbuf_queue); _init_queue(&pxmitpriv->pending_xmitbuf_queue);
pxmitpriv->pallocated_xmitbuf = pxmitpriv->pxmitbuf = kmalloc(NR_XMITBUFF * sizeof(struct xmit_buf), GFP_ATOMIC);
kmalloc(NR_XMITBUFF * sizeof(struct xmit_buf) + 4, GFP_ATOMIC); if (!pxmitpriv->pxmitbuf)
if (!pxmitpriv->pallocated_xmitbuf)
goto clean_up_frame_buf; goto clean_up_frame_buf;
pxmitpriv->pxmitbuf = pxmitpriv->pallocated_xmitbuf + 4 -
((addr_t)(pxmitpriv->pallocated_xmitbuf) & 3);
pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf; pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmitbuf;
for (i = 0; i < NR_XMITBUFF; i++) { for (i = 0; i < NR_XMITBUFF; i++) {
INIT_LIST_HEAD(&pxmitbuf->list); INIT_LIST_HEAD(&pxmitbuf->list);
@ -165,8 +162,8 @@ clean_up_alloc_buf:
for (k = 0; k < 8; k++) /* delete xmit urb's */ for (k = 0; k < 8; k++) /* delete xmit urb's */
usb_free_urb(pxmitbuf->pxmit_urb[k]); usb_free_urb(pxmitbuf->pxmit_urb[k]);
} }
kfree(pxmitpriv->pallocated_xmitbuf); kfree(pxmitpriv->pxmitbuf);
pxmitpriv->pallocated_xmitbuf = NULL; pxmitpriv->pxmitbuf = NULL;
clean_up_frame_buf: clean_up_frame_buf:
kfree(pxmitpriv->pallocated_frame_buf); kfree(pxmitpriv->pallocated_frame_buf);
pxmitpriv->pallocated_frame_buf = NULL; pxmitpriv->pallocated_frame_buf = NULL;
@ -193,7 +190,7 @@ void _free_xmit_priv(struct xmit_priv *pxmitpriv)
pxmitbuf++; pxmitbuf++;
} }
kfree(pxmitpriv->pallocated_frame_buf); kfree(pxmitpriv->pallocated_frame_buf);
kfree(pxmitpriv->pallocated_xmitbuf); kfree(pxmitpriv->pxmitbuf);
free_hwxmits(padapter); free_hwxmits(padapter);
} }

View File

@ -244,7 +244,6 @@ struct xmit_priv {
int cmdseq; int cmdseq;
struct __queue free_xmitbuf_queue; struct __queue free_xmitbuf_queue;
struct __queue pending_xmitbuf_queue; struct __queue pending_xmitbuf_queue;
u8 *pallocated_xmitbuf;
u8 *pxmitbuf; u8 *pxmitbuf;
uint free_xmitbuf_cnt; uint free_xmitbuf_cnt;
}; };