Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2673041ybl; Thu, 29 Aug 2019 11:16:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+ja6wU0yVYih9biwbgrz5zkieakTN+sekbRPB5PFnu6QoIfIk3GCey+4KVtTGQLLFpd+S X-Received: by 2002:a63:2744:: with SMTP id n65mr9464500pgn.277.1567102610012; Thu, 29 Aug 2019 11:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567102610; cv=none; d=google.com; s=arc-20160816; b=apT0kBKrIYtW8ioBpMKSBIR4pL8sgHkP1fBZXw1Xe8hletxZFxqcL3ARpN0CHEaYOG oC6coVxQOgHskrEjmzPR1UraiTh44sQrKJauTi8s7D5ytVpqziNlxGY4PrRwxubg20Y3 qf22cycAapfti0au9+kFyWTZqqi6MzBBVYFp6kJcbzugrmxa0hDm53xd66vzsk7f/oPX E2xJfpuBRjoR+xcTJpw0HdG3FtjwOCAWNIrmBQx2sMtjoCFMnV4/GA4vqmaQkIf9rT6S A8zYVCwYkIZa9KNI/gFGRn0dowcFbSdQC+Algc7z+L5E03YSxxy7pATpcCyQ6sXNKo4O x2bA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8HupdMzGXql0lAKoMEGf2e+ptSs3wdLYE6AMT0G2s5k=; b=uPZI7KRuZx6HSC1xc04rc+D90cVVK0xg+OVj6E4vAOGRPlxtaijEDxbqMCoiPLFxGe nrcthwXJT1uNKQwA/WbqjiwiXBLIlZrIV1M6ZgE0DXb0GWk8Xuc9bkkrnIRIyX/kssRG mM7kDQNg6LL08KldqfEKPTGX50XkVBHJOy/d7wdVSM6g1OwVwcnawJZOQL6WHwXg4lpg eChNv/oekB47lqh9SgOYHnIyCPETw6Q6lDH4d1NV0wIcGc/Y6naqzAm5s6eV45yle5++ vxvacUsG2gUkREJbHYckOnlvB6jsgkdxSpwUgCeA7GB9cnqtGS7L1TIVddWU1i/m/+3t ax0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sSKpaIrL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si2594071pgv.164.2019.08.29.11.16.34; Thu, 29 Aug 2019 11:16:49 -0700 (PDT) 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=sSKpaIrL; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729166AbfH2SPH (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:56714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729127AbfH2SPD (ORCPT ); Thu, 29 Aug 2019 14:15:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E91DE23404; Thu, 29 Aug 2019 18:15:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102502; bh=vKFj8KBYs1QbT6Es0F/AQgyhoqk7688aZAwgJPlFsQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSKpaIrLMpSYGQTEZ88mXOT9d94S8tuYIojvpQGAa9k5vBCBf9wGJBGTDZk5JI4cq RCRqVUKV+FdoiBGX+MB69nDOlYKxb3TVT+Glcfst5MS6CB7U53A54jogyTx2FJyYJ0 ueduW2dYA4Xf5eZg0n4T6GxJeJGsNB7BEWWZ3exk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dexuan Cui , Dmitry Torokhov , Sasha Levin , linux-hyperv@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 53/76] Input: hyperv-keyboard: Use in-place iterator API in the channel callback Date: Thu, 29 Aug 2019 14:12:48 -0400 Message-Id: <20190829181311.7562-53-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 d09bc83640d524b8467a660db7b1d15e6562a1de ] 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: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/serio/hyperv-keyboard.c | 35 +++++---------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/drivers/input/serio/hyperv-keyboard.c b/drivers/input/serio/hyperv-keyboard.c index 8e457e50f837e..770e36d0c66fb 100644 --- a/drivers/input/serio/hyperv-keyboard.c +++ b/drivers/input/serio/hyperv-keyboard.c @@ -237,40 +237,17 @@ static void hv_kbd_handle_received_packet(struct hv_device *hv_dev, static void hv_kbd_on_channel_callback(void *context) { + struct vmpacket_descriptor *desc; struct hv_device *hv_dev = context; - void *buffer; - int bufferlen = 0x100; /* Start with sensible size */ u32 bytes_recvd; u64 req_id; - int error; - buffer = kmalloc(bufferlen, GFP_ATOMIC); - if (!buffer) - return; - - while (1) { - error = vmbus_recvpacket_raw(hv_dev->channel, buffer, bufferlen, - &bytes_recvd, &req_id); - switch (error) { - case 0: - if (bytes_recvd == 0) { - kfree(buffer); - return; - } - - hv_kbd_handle_received_packet(hv_dev, buffer, - bytes_recvd, req_id); - break; + foreach_vmbus_pkt(desc, hv_dev->channel) { + bytes_recvd = desc->len8 * 8; + req_id = desc->trans_id; - case -ENOBUFS: - kfree(buffer); - /* Handle large packet */ - bufferlen = bytes_recvd; - buffer = kmalloc(bytes_recvd, GFP_ATOMIC); - if (!buffer) - return; - break; - } + hv_kbd_handle_received_packet(hv_dev, desc, bytes_recvd, + req_id); } } -- 2.20.1