From patchwork Fri Mar 16 12:10:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 10287007 X-Patchwork-Delegate: andy.shevchenko@gmail.com 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 B687F602C2 for ; Fri, 16 Mar 2018 12:10:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A79E628E3B for ; Fri, 16 Mar 2018 12:10:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 969E928E50; Fri, 16 Mar 2018 12:10:52 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham 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 81B5728E15 for ; Fri, 16 Mar 2018 12:10:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751976AbeCPMKv (ORCPT ); Fri, 16 Mar 2018 08:10:51 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:57122 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751414AbeCPMKu (ORCPT ); Fri, 16 Mar 2018 08:10:50 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2GBk3rg049435; Fri, 16 Mar 2018 12:10:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=1tQNkdPoiXXV4ZI8Ma40jf/ZwaH3ZKHqFFE6quXrvHw=; b=rpHIijrZSdCiBWXaAzQgSNEsCT8Y4CzXoFkdZ18ora4EQz6O0zBIJU0VnM6M9YKj3jyO 32wXYJ6KKHJZ3d+g2eOnXXFsNr+n1fWNxd32BI2wfpoGQtIwk/Fjj/a4vu+rLYFFSC2G eP7gnP0WIaQYVgIrrr/FdZAQHuYbDb1xagqObLYo/wH1Ki+YyMrnaD2jjLRfO9HxEeHd lgOzcjY8/TftLjgRsc65oXQSSj8rXSfQ2I3JqOA3JaCR2hKrZSUnNiueF91wngSEqEKo DbFPcjuBE0FGoHkADGPAwZz6AxbTj5xBXRxCcYSWQvcA4V+0dmS3Ne3H3J3VSAXoSwMr fg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2grdavr2uq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Mar 2018 12:10:25 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w2GCAO2R010400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Mar 2018 12:10:24 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2GCAOnC024927; Fri, 16 Mar 2018 12:10:24 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Mar 2018 05:10:23 -0700 Date: Fri, 16 Mar 2018 15:10:15 +0300 From: Dan Carpenter To: Darren Hart , Pali =?iso-8859-1?Q?Roh=E1r?= , Mario Limonciello Cc: Andy Shevchenko , platform-driver-x86@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH v2] platform/x86: Fix memory leaks in build_tokens_sysfs() Message-ID: <20180316121015.GA14282@mwanda> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180118104503.GA30055@mwanda> X-Mailer: git-send-email haha only kidding User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8833 signatures=668690 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=912 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803160005 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We're freeing "value_name" which is NULL, so that's a no-op, but we intended to free "location_name" instead. And then we don't free the names in token_location_attrs[0] and token_value_attrs[0]. Fixes: 33b9ca1e53b4 ("platform/x86: dell-smbios: Add a sysfs interface for SMBIOS tokens") Signed-off-by: Dan Carpenter --- v2: style changes (move from a for loop to a while loop) and this driver has been renamed. diff --git a/drivers/platform/x86/dell-smbios-base.c b/drivers/platform/x86/dell-smbios-base.c index 2485c80a9fdd..ec31d149f82e 100644 --- a/drivers/platform/x86/dell-smbios-base.c +++ b/drivers/platform/x86/dell-smbios-base.c @@ -514,7 +514,7 @@ static int build_tokens_sysfs(struct platform_device *dev) continue; loop_fail_create_value: - kfree(value_name); + kfree(location_name); goto out_unwind_strings; } smbios_attribute_group.attrs = token_attrs; @@ -525,7 +525,7 @@ static int build_tokens_sysfs(struct platform_device *dev) return 0; out_unwind_strings: - for (i = i-1; i > 0; i--) { + while (--i >= 0) { kfree(token_location_attrs[i].attr.name); kfree(token_value_attrs[i].attr.name); }