[PATCH 2/2] mei: vsc: Use struct vsc_tp_packet as vsc-tp tx_buf and rx_buf type

Hans de Goede posted 2 patches 9 months ago
[PATCH 2/2] mei: vsc: Use struct vsc_tp_packet as vsc-tp tx_buf and rx_buf type
Posted by Hans de Goede 9 months ago
vsc_tp.tx_buf and vsc_tp.rx_buf point to a struct vsc_tp_packet, use
the correct type instead of "void *" and use sizeof(*ptr) when allocating
memory for these buffers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 drivers/misc/mei/vsc-tp.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/misc/mei/vsc-tp.c b/drivers/misc/mei/vsc-tp.c
index fa553d4914b6..da26a080916c 100644
--- a/drivers/misc/mei/vsc-tp.c
+++ b/drivers/misc/mei/vsc-tp.c
@@ -71,8 +71,8 @@ struct vsc_tp {
 	u32 seq;
 
 	/* command buffer */
-	void *tx_buf;
-	void *rx_buf;
+	struct vsc_tp_packet *tx_buf;
+	struct vsc_tp_packet *rx_buf;
 
 	atomic_t assert_cnt;
 	wait_queue_head_t xfer_wait;
@@ -164,7 +164,7 @@ static int vsc_tp_xfer_helper(struct vsc_tp *tp, struct vsc_tp_packet *pkt,
 {
 	int ret, offset = 0, cpy_len, src_len, dst_len = sizeof(struct vsc_tp_packet_hdr);
 	int next_xfer_len = VSC_TP_PACKET_SIZE(pkt) + VSC_TP_XFER_TIMEOUT_BYTES;
-	u8 *src, *crc_src, *rx_buf = tp->rx_buf;
+	u8 *src, *crc_src, *rx_buf = (u8 *)tp->rx_buf;
 	int count_down = VSC_TP_MAX_XFER_COUNT;
 	u32 recv_crc = 0, crc = ~0;
 	struct vsc_tp_packet_hdr ack;
@@ -324,7 +324,7 @@ int vsc_tp_rom_xfer(struct vsc_tp *tp, const void *obuf, void *ibuf, size_t len)
 	guard(mutex)(&tp->mutex);
 
 	/* rom xfer is big endian */
-	cpu_to_be32_array(tp->tx_buf, obuf, words);
+	cpu_to_be32_array((u32 *)tp->tx_buf, obuf, words);
 
 	ret = read_poll_timeout(gpiod_get_value_cansleep, ret,
 				!ret, VSC_TP_ROM_XFER_POLL_DELAY_US,
@@ -340,7 +340,7 @@ int vsc_tp_rom_xfer(struct vsc_tp *tp, const void *obuf, void *ibuf, size_t len)
 		return ret;
 
 	if (ibuf)
-		be32_to_cpu_array(ibuf, tp->rx_buf, words);
+		be32_to_cpu_array(ibuf, (u32 *)tp->rx_buf, words);
 
 	return ret;
 }
@@ -494,11 +494,11 @@ static int vsc_tp_probe(struct spi_device *spi)
 	if (!tp)
 		return -ENOMEM;
 
-	tp->tx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE, GFP_KERNEL);
+	tp->tx_buf = devm_kzalloc(dev, sizeof(*tp->tx_buf), GFP_KERNEL);
 	if (!tp->tx_buf)
 		return -ENOMEM;
 
-	tp->rx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE, GFP_KERNEL);
+	tp->rx_buf = devm_kzalloc(dev, sizeof(*tp->rx_buf), GFP_KERNEL);
 	if (!tp->rx_buf)
 		return -ENOMEM;
 
-- 
2.48.1
RE: [PATCH 2/2] mei: vsc: Use struct vsc_tp_packet as vsc-tp tx_buf and rx_buf type
Posted by Usyskin, Alexander 9 months ago
> -----Original Message-----
> From: Hans de Goede <hdegoede@redhat.com>
> Sent: Tuesday, March 18, 2025 4:12 PM
> To: Wentong Wu <wentong.wu@intel.com>; Usyskin, Alexander
> <alexander.usyskin@intel.com>; Arnd Bergmann <arnd@arndb.de>; Greg
> Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Hans de Goede <hdegoede@redhat.com>; Sakari Ailus
> <sakari.ailus@linux.intel.com>; Stanislaw Gruszka
> <stanislaw.gruszka@linux.intel.com>; linux-kernel@vger.kernel.org
> Subject: [PATCH 2/2] mei: vsc: Use struct vsc_tp_packet as vsc-tp tx_buf and
> rx_buf type
> 
> vsc_tp.tx_buf and vsc_tp.rx_buf point to a struct vsc_tp_packet, use
> the correct type instead of "void *" and use sizeof(*ptr) when allocating
> memory for these buffers.
> 
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>

Reviewed-by: Alexander Usyskin <alexander.usyskin@intel.com>

> ---
>  drivers/misc/mei/vsc-tp.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/misc/mei/vsc-tp.c b/drivers/misc/mei/vsc-tp.c
> index fa553d4914b6..da26a080916c 100644
> --- a/drivers/misc/mei/vsc-tp.c
> +++ b/drivers/misc/mei/vsc-tp.c
> @@ -71,8 +71,8 @@ struct vsc_tp {
>  	u32 seq;
> 
>  	/* command buffer */
> -	void *tx_buf;
> -	void *rx_buf;
> +	struct vsc_tp_packet *tx_buf;
> +	struct vsc_tp_packet *rx_buf;
> 
>  	atomic_t assert_cnt;
>  	wait_queue_head_t xfer_wait;
> @@ -164,7 +164,7 @@ static int vsc_tp_xfer_helper(struct vsc_tp *tp, struct
> vsc_tp_packet *pkt,
>  {
>  	int ret, offset = 0, cpy_len, src_len, dst_len = sizeof(struct
> vsc_tp_packet_hdr);
>  	int next_xfer_len = VSC_TP_PACKET_SIZE(pkt) +
> VSC_TP_XFER_TIMEOUT_BYTES;
> -	u8 *src, *crc_src, *rx_buf = tp->rx_buf;
> +	u8 *src, *crc_src, *rx_buf = (u8 *)tp->rx_buf;
>  	int count_down = VSC_TP_MAX_XFER_COUNT;
>  	u32 recv_crc = 0, crc = ~0;
>  	struct vsc_tp_packet_hdr ack;
> @@ -324,7 +324,7 @@ int vsc_tp_rom_xfer(struct vsc_tp *tp, const void
> *obuf, void *ibuf, size_t len)
>  	guard(mutex)(&tp->mutex);
> 
>  	/* rom xfer is big endian */
> -	cpu_to_be32_array(tp->tx_buf, obuf, words);
> +	cpu_to_be32_array((u32 *)tp->tx_buf, obuf, words);
> 
>  	ret = read_poll_timeout(gpiod_get_value_cansleep, ret,
>  				!ret, VSC_TP_ROM_XFER_POLL_DELAY_US,
> @@ -340,7 +340,7 @@ int vsc_tp_rom_xfer(struct vsc_tp *tp, const void
> *obuf, void *ibuf, size_t len)
>  		return ret;
> 
>  	if (ibuf)
> -		be32_to_cpu_array(ibuf, tp->rx_buf, words);
> +		be32_to_cpu_array(ibuf, (u32 *)tp->rx_buf, words);
> 
>  	return ret;
>  }
> @@ -494,11 +494,11 @@ static int vsc_tp_probe(struct spi_device *spi)
>  	if (!tp)
>  		return -ENOMEM;
> 
> -	tp->tx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE,
> GFP_KERNEL);
> +	tp->tx_buf = devm_kzalloc(dev, sizeof(*tp->tx_buf), GFP_KERNEL);
>  	if (!tp->tx_buf)
>  		return -ENOMEM;
> 
> -	tp->rx_buf = devm_kzalloc(dev, VSC_TP_MAX_XFER_SIZE,
> GFP_KERNEL);
> +	tp->rx_buf = devm_kzalloc(dev, sizeof(*tp->rx_buf), GFP_KERNEL);
>  	if (!tp->rx_buf)
>  		return -ENOMEM;
> 
> --
> 2.48.1