Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2541600ybm; Thu, 23 May 2019 19:44:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGzoI86B8A8idQ5tPtx13kRsLB8Xc66zuPy0pnIZeaWPml1PJ8L9y9PiSvtHZpm25TjNZT X-Received: by 2002:a62:2b82:: with SMTP id r124mr101349364pfr.235.1558665896996; Thu, 23 May 2019 19:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558665896; cv=none; d=google.com; s=arc-20160816; b=jiUfc3j7TvnJYOxwycE2xPOyMykvtp6Om5orDCs3qwFjCpWjISwWFAwJ+01ZDXwe5K yPfsPkN1NA60v1c4w/SaJO+DfXrw7fzZmqfKF82L9rUtqP/MaPTy9t4ewxNrpJSAyt3d zXrvksp64BJxM0nCw84F7HGeu6mpCQiNrzotGy3rIDE/MTyf4n6cSG3kazpvyfYh9Dtp gXQqRACt8ibtbh/+n5W1vhRjDIksZoZtqrXFdZ7FMBv/ADZsjcAEGqGMqwyVrxSgVStM M8u/YpansOgF9gMeN+X9hnKvSPPOug858nmZRKueYVTdZhpIfHBqttekcW0zJX8nviiX 4DYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FL96OWjGjcZazAQC1Z3siZkSXdl0SwuUzJLZikcp/Hw=; b=j5uTcAakXDUP16/YSM/vTKhxXiCGv9VVzyBmRKCbOHVwxg3J1T3Z2GyW+8MWPv5JGH z/UdD8tmUhwBGOGrYGHAw85NgT3nRlgISYpEqHwwSG25Vc07gAj+1JkvB8i2GuE7EiSR CNZLMJGsucu8MDj2IR7tlxbiMWNPK0n8kuCyXPl0YzshM8x2ljbr7CophoNUriA9uo1/ /zuOhi4X5QPKiBCpr9dPzq0S54Pl7LIfXJOT4XDX1ci6Yrrg/slIJpLAoHZgnY8BDx4d RNV9Z3ShqFdallrzpI6mynrwKn4lyd+bh8xOwGMrwUllZjkwGf03Ir/2z2yzC/wnVxIG jM8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tjePZEjM; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1si2174872pfi.234.2019.05.23.19.44.23; Thu, 23 May 2019 19:44:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=@gmail.com header.s=20161025 header.b=tjePZEjM; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388064AbfEXCnZ (ORCPT + 99 others); Thu, 23 May 2019 22:43:25 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37592 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387921AbfEXCnY (ORCPT ); Thu, 23 May 2019 22:43:24 -0400 Received: by mail-pl1-f193.google.com with SMTP id p15so3535082pll.4; Thu, 23 May 2019 19:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=FL96OWjGjcZazAQC1Z3siZkSXdl0SwuUzJLZikcp/Hw=; b=tjePZEjMOCilcX+1AimSHAvkEpIIKcT32GMGbPNHoHaZcEJO8pSPzwX/lV+4h4ttyX 6j9g8Dhqvu7nxpTNQcwvdkzmcKWYS4sGLfeeG7qDuxf7m415pvnWXoYxie9fsbnOlGTr SBkvpqOxdMOKtZobvDBVTB1tE8RXvgg6WmFqSUpedADnfhrhDDXtxL1o6puhJ5Vjr3LT +TtRVSqeXxA2IByIYDmrpKUxyCgbou3Cx9gv/OXQfIJBAH0t8xFAxgnxIz5l4hdbuOdR TXHcNHzvtIVUN32sMZHL8yXVktbzv6BtHkcdY7ghPngXX2h9b3pNDVz8Ac2+zDTtbh8A tAJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=FL96OWjGjcZazAQC1Z3siZkSXdl0SwuUzJLZikcp/Hw=; b=PU9F6DvHHZW02gDbVruFTjT+36lBm8bw0OUO1v7TuZT/tFf1fKOe2U7afIB7WRCrw4 jsA4kFckMStRB3CUQT5z4bsIs/eT1Fu1OAbIK/D6ic4XGFmybW2eEdMFx2DB9bBqjy7b /iqw460xCojbDmbOHpHtIgfMSTDl4N0+OHDMMQdrWoj5sGosYICbTvUg37ISGvEQIhOB 9vVSYC58z5LTPeAdtsiTzCOBaKt/syTr6UxrTufdru2V/SQdqT82VF7LySiMfPjV181M llXpsCtwX4G6eDVtfKdDFiUg8hjli7s+QLH5EZ/g55KtXHH8I58aM4GQHqHKEXdX2x3T b43Q== X-Gm-Message-State: APjAAAUI2f/6T0qXKiD0Xvq8jBCR0JSr8BYF80/hHRu9tLibshSMcjtF Mr+1CEtdfQzus+1lxWvzPvTZqoOYFxQ= X-Received: by 2002:a17:902:8ec3:: with SMTP id x3mr47512107plo.340.1558665802696; Thu, 23 May 2019 19:43:22 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id r77sm645844pgr.93.2019.05.23.19.43.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 19:43:22 -0700 (PDT) Date: Fri, 24 May 2019 10:43:07 +0800 From: Gen Zhang To: Kalle Valo Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] wlcore: sdio: Fix a memory leaking bug in wl1271_probe() Message-ID: <20190524024307.GA5639@zhanggen-UX430UQ> References: <20190523144425.GA26766@zhanggen-UX430UQ> <87d0k9b4hm.fsf@kamboji.qca.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87d0k9b4hm.fsf@kamboji.qca.qualcomm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In wl1271_probe(), 'glue->core' is allocated by platform_device_alloc(), when this allocation fails, ENOMEM is returned. However, 'pdev_data' and 'glue' are allocated by devm_kzalloc() before 'glue->core'. When platform_device_alloc() returns NULL, we should also free 'pdev_data' and 'glue' before wl1271_probe() ends to prevent leaking memory. Similarly, we should free 'pdev_data' when 'glue' is NULL. And we should free 'pdev_data' and 'glue' when 'ret' is error. Further, we shoulf free 'glue->dev', 'pdev_data' and 'glue' when this function normally ends to prevent memory leaking. Signed-off-by: Gen Zhang --- diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c index 4d4b0770..9110891 100644 --- a/drivers/net/wireless/ti/wlcore/sdio.c +++ b/drivers/net/wireless/ti/wlcore/sdio.c @@ -298,8 +298,10 @@ static int wl1271_probe(struct sdio_func *func, pdev_data->if_ops = &sdio_ops; glue = devm_kzalloc(&func->dev, sizeof(*glue), GFP_KERNEL); - if (!glue) - return -ENOMEM; + if (!glue) { + ret = -ENOMEM; + goto out_free1; + } glue->dev = &func->dev; @@ -311,7 +313,7 @@ static int wl1271_probe(struct sdio_func *func, ret = wlcore_probe_of(&func->dev, &irq, &wakeirq, pdev_data); if (ret) - goto out; + goto out_free2; /* if sdio can keep power while host is suspended, enable wow */ mmcflags = sdio_get_host_pm_caps(func); @@ -340,7 +342,7 @@ static int wl1271_probe(struct sdio_func *func, if (!glue->core) { dev_err(glue->dev, "can't allocate platform_device"); ret = -ENOMEM; - goto out; + goto out_free2; } glue->core->dev.parent = &func->dev; @@ -380,12 +382,17 @@ static int wl1271_probe(struct sdio_func *func, dev_err(glue->dev, "can't add platform device\n"); goto out_dev_put; } - return 0; + ret = 0; out_dev_put: platform_device_put(glue->core); -out: +out_free2: + devm_kfree(&func->dev, glue); + +out_free1: + devm_kfree(&func->dev, pdev_data); + return ret; } ---