[PATCH] nvme-tcp: fix signedness bug in nvme_tcp_init_connection()

Christoph Hellwig hch at lst.de
Wed Mar 5 06:25:54 PST 2025


On Fri, Feb 28, 2025 at 12:39:41PM +0300, Dan Carpenter wrote:
> index 8a9131c95a3d..361b04ec5b5d 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -1495,7 +1495,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
>  	msg.msg_flags = MSG_WAITALL;
>  	ret = kernel_recvmsg(queue->sock, &msg, &iov, 1,
>  			iov.iov_len, msg.msg_flags);
> -	if (ret < sizeof(*icresp)) {
> +	if (ret < (int)sizeof(*icresp)) {
>  		pr_warn("queue %d: failed to receive icresp, error %d\n",
>  			nvme_tcp_queue_id(queue), ret);
>  		if (ret >= 0)

I hate these magic casts.  What about something like:

	if (ret >= 0 && ret < sizeof(*icresp))
		ret = -ECONNRESET;
	if (ret < 0) {
		...




More information about the Linux-nvme mailing list