Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4475920ybx; Mon, 4 Nov 2019 14:04:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxnAWNM/iyOFmXVyG9dxauoXDADeYheXl/5Dbvh46LPBlyq5sNsevB/g7xOoM5FjNxQcb8h X-Received: by 2002:aa7:c453:: with SMTP id n19mr4739873edr.103.1572905039970; Mon, 04 Nov 2019 14:03:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905039; cv=none; d=google.com; s=arc-20160816; b=YX4kuiquLUViIv53z/k9ETWzi064dprpGzsBTWOdzi5WPaXlWi6TMdOwC+L6CwkpgA JuxDhm6AHZGcufoH6I/K4kbBVb3HJPpkP4Z4TYL2jSurTVZcglY6i7uWVl37L5uhptcm OX7Dd/hfOcOLfD20/WgZjx7gADUSLYLFh44socfmY+iOlzl/hL4my5qKpaEavWZ52kWL gbSmB0Qwx1We6FW6+6zOiDJTxYnFuiaWyi3xSByw+BgG9+a7GHMNOSfTHEDfd+cMERU0 O0Al5LAu2hWVFiOJ9a/OJgyEuIXUK3eeWZHlSLDqj521vdfkHu19sgAjc6yj6q+X3vGx +0uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nhol15o713+pThUV6bY1ohQh/m0tgftd7F6xCHnrsOQ=; b=0cgzBJ0QUBtwYcsl27E09TMWf4Ola6K43CEMA5nBXG5yrjEvRT8olSmqXDFYV/v0hk 43JYgXPGkSPHj6k6sIqKL/RUDYr5fERJ0QFr6lU9jd9UD3NtJkc+NIKF6JRRLMFLLfGn pgB0DmHjYU5DqQ9dI8ytEVxR25nWSFvr2479uTKgI+NUiwpbRZ21DSilePMPFwheyQlq Q88H+ie9G/hU4PlLkJaYRuqVHhRLWjfhye2n6TP4pQrbd0y2lWhKV4CCR1IGHivZCk4J +epD0xH7DXMU3JuOdQcICQpX/V/9zNohwPrh1BtolMcQibP2cRtts6EMe2jXpXu/Q5Pd 6Mfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FCiHyt+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8si8491777edb.57.2019.11.04.14.03.36; Mon, 04 Nov 2019 14:03:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=FCiHyt+N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388787AbfKDWAA (ORCPT + 99 others); Mon, 4 Nov 2019 17:00:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:57386 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388362AbfKDV77 (ORCPT ); Mon, 4 Nov 2019 16:59:59 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EBA3C214E0; Mon, 4 Nov 2019 21:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904798; bh=RKoO/50WWCrVLJkafaQkr4EOtCU9gOnnE+awNfgmwaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FCiHyt+N1isHd3qCTzIMP4w2ZSHkUdo3OHz56dwhN1gEfy04QduVcT8Y3y/Tgu2pa uY88f0yV4+FSK35mfcNeexFwHI2B13o0GDqxpXU8/AvQiChu5gBcTbBT02fu3d4XWy 81lBjilYmSlXUCEuRpIw+R/3DvMOUQUbUk7BPRfs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Jiri Kosina , Sasha Levin Subject: [PATCH 4.19 073/149] HID: hyperv: Use in-place iterator API in the channel callback Date: Mon, 4 Nov 2019 22:44:26 +0100 Message-Id: <20191104212141.806741875@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212126.090054740@linuxfoundation.org> References: <20191104212126.090054740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui [ Upstream commit 6a297c90efa68b2864483193b8bfb0d19478600c ] Simplify the ring buffer handling with the in-place API. Also avoid the dynamic allocation and the memory leak in the channel callback function. Signed-off-by: Dexuan Cui Acked-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-hyperv.c | 56 +++++++--------------------------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/drivers/hid/hid-hyperv.c b/drivers/hid/hid-hyperv.c index 704049e62d58a..4d1496f60071f 100644 --- a/drivers/hid/hid-hyperv.c +++ b/drivers/hid/hid-hyperv.c @@ -322,60 +322,24 @@ static void mousevsc_on_receive(struct hv_device *device, static void mousevsc_on_channel_callback(void *context) { - const int packet_size = 0x100; - int ret; struct hv_device *device = context; - u32 bytes_recvd; - u64 req_id; struct vmpacket_descriptor *desc; - unsigned char *buffer; - int bufferlen = packet_size; - - buffer = kmalloc(bufferlen, GFP_ATOMIC); - if (!buffer) - return; - - do { - ret = vmbus_recvpacket_raw(device->channel, buffer, - bufferlen, &bytes_recvd, &req_id); - - switch (ret) { - case 0: - if (bytes_recvd <= 0) { - kfree(buffer); - return; - } - desc = (struct vmpacket_descriptor *)buffer; - - switch (desc->type) { - case VM_PKT_COMP: - break; - - case VM_PKT_DATA_INBAND: - mousevsc_on_receive(device, desc); - break; - - default: - pr_err("unhandled packet type %d, tid %llx len %d\n", - desc->type, req_id, bytes_recvd); - break; - } + foreach_vmbus_pkt(desc, device->channel) { + switch (desc->type) { + case VM_PKT_COMP: break; - case -ENOBUFS: - kfree(buffer); - /* Handle large packet */ - bufferlen = bytes_recvd; - buffer = kmalloc(bytes_recvd, GFP_ATOMIC); - - if (!buffer) - return; + case VM_PKT_DATA_INBAND: + mousevsc_on_receive(device, desc); + break; + default: + pr_err("Unhandled packet type %d, tid %llx len %d\n", + desc->type, desc->trans_id, desc->len8 * 8); break; } - } while (1); - + } } static int mousevsc_connect_to_vsp(struct hv_device *device) -- 2.20.1