Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1857458ybm; Thu, 23 May 2019 07:46:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwK/W8v+9C1jmfwInFCzFhPKnBr7IYcxYgs1KlhZTj5aiqUXmqvyZg68+RU0MBXNWOqb6rJ X-Received: by 2002:a17:902:22:: with SMTP id 31mr98449432pla.15.1558622773542; Thu, 23 May 2019 07:46:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558622773; cv=none; d=google.com; s=arc-20160816; b=y+NPsv/dXD+IuAwqarwbL4HzcKEZuekmGGeqqtkWAOES9uU9VWk3wttr3Y983wiabh 80OVVXDQHfoKCk7nUkffyJA3orNXI5JwyNSDRRRxGECC0mPomOAI3AvfsiETeukIJVei +WDtlyMSpeNsmKBcZC/suwIYX1GfvC4S6p+e0X+NdVKyZ5wY9Rac23K1bvE3K6TI3HI+ 9tJTV0DdTbAVJGCNF1MxcVg+Ls0ndiQSjhe1t2WyKhl3htJmwB8gZeJEr1tTbDzTyEBb hBLWu5uUbWrDSxettQeEKH5opr9nUzdnRGlMhz4aDuLShX8kXxDkpGlTuYlM2mf6BRX5 VznQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=trLF/Pu76tcs2yNpJEmVVGLKJPxzPf+7/LopwlS1ci8=; b=bXinFEQeGX0RMyj5GpXMkyfB0UDpo5XrLjNR23BiuywJQnGlPoa6ufzslUMnYfNiqI 1XdISYDkSg6tOTv8lrrtlvLiOICXTtuEaHEoZFmtsZPcAZbAhmUgYggRIDvDp5kUwL3S MgxeQ3rzud77o3hbQdEyvPmX/RWvFKK6Kd6RF3AwEpOkzorEXsmIxdYYFNDHOH9gnB5C IeVaJ34QuiP2FAOTXiSwAEDTHyVbQfVERKBLh5YrFaE1Hcn4bFZFGqausDwJQ4KiYFq4 MT9ud1HjaMo+q/Wt29Og3UjzG8YqMvQ+UJ+cxFhgAykZauYfyhZkhPuFfn70vgG/HIeN YSbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sf4PXYXe; 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=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 x3si8174175pff.279.2019.05.23.07.45.56; Thu, 23 May 2019 07:46:13 -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=@gmail.com header.s=20161025 header.b=sf4PXYXe; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730902AbfEWOom (ORCPT + 99 others); Thu, 23 May 2019 10:44:42 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:33281 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730709AbfEWOol (ORCPT ); Thu, 23 May 2019 10:44:41 -0400 Received: by mail-pf1-f196.google.com with SMTP id z28so3381622pfk.0; Thu, 23 May 2019 07:44:41 -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:mime-version:content-disposition :user-agent; bh=trLF/Pu76tcs2yNpJEmVVGLKJPxzPf+7/LopwlS1ci8=; b=sf4PXYXeAQSFyn0UVZTTW2ciZr/ivjcuG5sp5GStckkZgxCyuav/So+HN6AeqF2+Uc nA2qq6zG1nYL+fCcfs9sDtvvZniacIHuvyBkk5kKq5XAzEpRRikrZeczPUXmSo5RusWg Vt9krzTu2EUS8SbY3x+ZUlhF5Fo4sT6eVvBIre3nN3PzAwL+hmmTWhnWqvazYVGiaOxS v257kAIWtsYx4eIcnZ+pzmI7Vp8+J1/JS2AuG2NX5f/SHs5U3szZ9QMvIqyuDMT2saD4 zHYxtj95orWKnwBRtPaMsdifgQLK3YegNcMf/NU/hvlzQ/EQElhwesRZIuMi8IUUMQzm 4bJw== 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:mime-version :content-disposition:user-agent; bh=trLF/Pu76tcs2yNpJEmVVGLKJPxzPf+7/LopwlS1ci8=; b=Rjul+5lbuwnu715oVdcNt7U02jpBae4yk+QkGvMkwEikiUS0X6x1hjhhb4cJnRrj4C hikx+b+gxf9SzUSeP4228YDHV+tkBqo3c7UTiaeqo/t11mpmHrEOiI7AT93RNsQ2FQBo rWbcU4PW299HmxqaNNgTzQY6KONBI9ZON93tOvFQsKXiufEmdRvENRHEUF0j6sAAiWQ4 xq4mHzScBsFJaH4R6LFQ2UrAAbHnffKUb358wYpZ6K4ab8Sg1Ljd44hPDBWeemNizO/l LU4AjWMqUtTmrocCkT3FJCi9yd0G5PwHgouCfSDOT944EhH89zbG7MtytL+Y4QoNX6Xm 4vtg== X-Gm-Message-State: APjAAAWcEHBGnmOutXRzNDgEIecXuwxIW3JZWuDJFAsISiOQkyO03IyQ XLoEcSPRmlMTGx8K2+w7rAM= X-Received: by 2002:a17:90a:b890:: with SMTP id o16mr1669701pjr.60.1558622680943; Thu, 23 May 2019 07:44:40 -0700 (PDT) Received: from zhanggen-UX430UQ ([66.42.35.75]) by smtp.gmail.com with ESMTPSA id h6sm42913471pfk.188.2019.05.23.07.44.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 07:44:40 -0700 (PDT) Date: Thu, 23 May 2019 22:44:25 +0800 From: Gen Zhang To: kvalo@codeaurora.org, eyalreizer@gmail.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] sdio: Fix a memory leaking bug in wl1271_probe() Message-ID: <20190523144425.GA26766@zhanggen-UX430UQ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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..232ce5f 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,11 +382,20 @@ static int wl1271_probe(struct sdio_func *func, dev_err(glue->dev, "can't add platform device\n"); goto out_dev_put; } + platform_device_put(glue->core); + devm_kfree(&func->dev, glue); + devm_kfree(&func->dev, pdev_data); return 0; out_dev_put: platform_device_put(glue->core); +out_free2: + devm_kfree(&func->dev, glue); + +out_free1: + devm_kfree(&func->dev, pdev_data); + out: return ret; } ---