From patchwork Sun Aug 11 18:33:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenwen Wang X-Patchwork-Id: 11089423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5958112C for ; Mon, 12 Aug 2019 08:04:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A373427F88 for ; Mon, 12 Aug 2019 08:04:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9689A27F85; Mon, 12 Aug 2019 08:04:19 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B40027F85 for ; Mon, 12 Aug 2019 08:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=mJJFfaPWUXZ5n5Bbki61+Ji/ztoLC+xfv+6PTXe8I4U=; b=JWV OWzQYRVYq3qyozlKFofe08OmaPg8sQgHm6qlEKkU9sOImAN9fj0UTQVFcGP01IcX5xn63WVFe5BP0 m1peQt3nWecVVUI5v+3wsLuy0azSzgCOxbEhLZz+aBiwj1ZE9/C2rtuRVz1FSiOKta3rbJC1aAbdC sX1YNiPSi12IUM4RAHcVg/Me5edLIRBIlzMU+Cr3b4PInqJipFyYbe1pSFURGi14RF+Pv9R268YdG 6/10pxsmVtDOG2ckegSstgGL9WsQCTfaexQxjGSNpDKk5xPdjbGwPgbYmJSmmBghYbkOk9ec8T/fQ K2aGOERtRdZulkNTTm87V2Uu+8A/ClQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hx5JS-0000Yi-UT; Mon, 12 Aug 2019 08:04:18 +0000 Received: from mail-yb1-f193.google.com ([209.85.219.193]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hwsed-0003eA-29 for linux-i3c@lists.infradead.org; Sun, 11 Aug 2019 18:33:20 +0000 Received: by mail-yb1-f193.google.com with SMTP id x10so388028ybs.13 for ; Sun, 11 Aug 2019 11:33:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ch+rXpu4FEjXRcLVZJZ1wzxNcCLlNLjg4OF4veGTZaE=; b=J6rokrs2ZVbAvsVfT77R6jObftTTVC9c7f2wimW1+WdZONe7Vyn0iDqL7B6d9q3PJq QG0y8mGYcrdlOkhOfrph7nbfmn0qyJ5VdDuj06FfDI2z+lyVt1mLZ32H20FLVChWUoCM uOdV1TmA4JyEo9iVkWsX2w6iuxwrJhKOf1VWAwoIKkRnR41RzsOcukOtq47FPFC1UYSq 9RioNlmy9m0jbd5hb4B8QOiGDDJ0PSL8kLb3C9QYPSUOUm8qQkWrX9xGD/b8Ykd/nhBg 6ZF/GISSJF2ro5T24kF4cya/SJXZtwCKlvgEfEfQ2/yTl+Ngbgqz/4drrSIBeEmOR4cr rY5A== X-Gm-Message-State: APjAAAWLpFQhkrV8UG7STfgkB9Sf6J67CgOKwKbfnElaPsQGGj08X/eg BxGahW2p6/+m3SzEh5wxsUE= X-Google-Smtp-Source: APXvYqyn//AFRNoWF1IJQh7tPm29GkwK4Jn+wbaWQaVwzSix5jqDcgDb8XYCLTcrCCIrsw3gqBsyMw== X-Received: by 2002:a25:9d09:: with SMTP id i9mr21373793ybp.103.1565548394282; Sun, 11 Aug 2019 11:33:14 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id v203sm23315484ywa.99.2019.08.11.11.33.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Aug 2019 11:33:13 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Subject: [PATCH] i3c: master: fix a memory leak bug Date: Sun, 11 Aug 2019 13:33:06 -0500 Message-Id: <1565548386-4485-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190811_113319_104557_8C5467C4 X-CRM114-Status: GOOD ( 11.52 ) X-Mailman-Approved-At: Mon, 12 Aug 2019 01:04:18 -0700 X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:I3C SUBSYSTEM" , open list , Boris Brezillon MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In i3c_master_getmwl_locked(), the buffer used for the dest payload data is allocated using kzalloc() in i3c_ccc_cmd_dest_init(). Later on, the length of the dest payload data is checked against 'sizeof(*mwl)'. If they are not equal, -EIO is returned to indicate the error. However, the allocated buffer is not deallocated on this path, leading to a memory leak. To fix the above issue, free the buffer before returning the error. Signed-off-by: Wenwen Wang --- drivers/i3c/master.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index d6f8b03..562f69f 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1084,8 +1084,10 @@ static int i3c_master_getmwl_locked(struct i3c_master_controller *master, if (ret) goto out; - if (dest.payload.len != sizeof(*mwl)) - return -EIO; + if (dest.payload.len != sizeof(*mwl)) { + ret = -EIO; + goto out; + } info->max_write_len = be16_to_cpu(mwl->len);