From patchwork Tue Aug 29 00:43:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 9926553 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B8A9560329 for ; Tue, 29 Aug 2017 00:45:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D3A5287C3 for ; Tue, 29 Aug 2017 00:45:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 90D2A287C8; Tue, 29 Aug 2017 00:45:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C1A3287C3 for ; Tue, 29 Aug 2017 00:45:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751291AbdH2ApQ (ORCPT ); Mon, 28 Aug 2017 20:45:16 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:48298 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751209AbdH2ApO (ORCPT ); Mon, 28 Aug 2017 20:45:14 -0400 Received: from linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id mUdYdfkhbuGJpmUdYdhrPZ; Mon, 28 Aug 2017 17:44:12 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv.com with local (Exim 4.89) (envelope-from ) id 1dmUdY-0007RI-Ln; Mon, 28 Aug 2017 17:44:12 -0700 From: Long Li To: "K . Y . Srinivasan" , Haiyang Zhang , "James E . J . Bottomley" , devel@linuxdriverproject.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [PATCH] storvsc: fix memory leak on ring buffer busy Date: Mon, 28 Aug 2017 17:43:59 -0700 Message-Id: <20170829004359.28526-1-longli@exchange.microsoft.com> X-Mailer: git-send-email 2.14.0 X-CMAE-Envelope: MS4wfKeZQqgsfchguwpz5LWKjRAFJHpSYbiX837egU6zeNS8hJT06xEYSKaWK/QljL2W2/1oU7gn4n0qMtSvN9A8UXCfFqSK4SIj33OwABv0oMC1Vog1Ryly WNNUuY3qmYJGJ+wCFUlBX0olmB13vIENZ3WrsDDHVj354xfS6WrLIloZfk9ZJzw30gyeglqkd7j9Bk0JYLQA7hvvx9hqyWh1dKXh5O6csvbEviUC9gji+j90 rkZF4XmP6JVAbj4xYVw0/kGcmXNoX21r9TBQfT4jXk+pSE4R3wjL0T3ExWqhYhcV/xWKotsyQbGAnnBO0AbvuCSqSse/eNroU+twEt7BLQ3ACWmqEOrvybTu PMXYVUeCwgtUiEO5XY822OGf+Xx/l4kWZt055LaMgWZLIXsFFpY= Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Long Li When storvsc is sending I/O to Hyper-v, it may allocate a bigger buffer descriptor for large data payload that can't fit into a pre-allocated buffer descriptor. This bigger buffer is freed on return path. If I/O request to Hyper-v fails due to ring buffer busy, the storvsc allocated buffer descriptor should also be freed. Signed-off-by: Long Li --- drivers/scsi/storvsc_drv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 009adb0..db52882 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1657,6 +1657,8 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd) ret = storvsc_do_io(dev, cmd_request, smp_processor_id()); if (ret == -EAGAIN) { + if (payload_sz > sizeof(cmd_request->mpb)) + kfree(payload); /* no more space */ return SCSI_MLQUEUE_DEVICE_BUSY; }