Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2514076yba; Fri, 17 May 2019 19:34:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzesGujbk0WZPSxReMlpMSqJ2BXmDiE1s7zwFSTl3Q+WrZOWz5A3DeRasCnc7/mkeRcscSo X-Received: by 2002:aa7:9e51:: with SMTP id z17mr63871014pfq.212.1558146897604; Fri, 17 May 2019 19:34:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558146897; cv=none; d=google.com; s=arc-20160816; b=x0v1w0E2GuJm5MOzZt6FP3Ickec7u8tyyInS2e3uzCFHryFXe6u9nyhPjM6C196TWc SGE2mQ9dm8wo0wh6WYBm6BSvwcm13YG7ad9KZLnQcoJIu7rQAukDzewrTMzv65u6EIS1 xMkjBfF6LG/vm/u+92y8FXkOYTpVTm7juLmDcgz6Ye4SvdM9ZikApCmbhWAAPB0ynurO uxbT1FCELOQZREISrHsgxOwyNJBd9ymkF0rh0VT3M2/LOI/29LO/DLPEuuESZXx8ju1a mQfpwJ9rVHioDqW6miHOELG3b7SiEvgjU4jC1c1+DnSMrsh0H0TU0b4V+hu3f+J+x827 W+rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Aqqb8fq9rk5ariT5pZi1gMWAA/hlm63uYollEoNQ9/o=; b=KGxbwzbwccYMH76m6s9e4pRIiy8mMtj8Nu00OCZ1aPkAGB/mAy4gyut9zh7P/ZwxKU ZmgGItlGOHInWZBXPJ37NhRJ4x+gL2FcvnxPt5cr2+YU0yHye+UwKgcT9xairwwee/8e wvN/O83ZpaHCzaOf7+bMVH0CEMzl6q1j09Mfj6++FT8YeODdSfL0BpQgidEtGWKfopvi dyH+FGYkpUFOGmqTGeA1jg0yuCn3qx4FjXIPyP69Eu+PfXnxm715DDhtT415gExlfAg4 f6zoniyl/DPegRB0CEho08NBdKxJdD/OvzzK0tw7P5h+6ttpLLellxYv9mB1YQ7e+LKp NMAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NX2oIG20; 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 d21si8859230pgl.591.2019.05.17.19.34.42; Fri, 17 May 2019 19:34:57 -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=NX2oIG20; 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 S1728105AbfERCbL (ORCPT + 99 others); Fri, 17 May 2019 22:31:11 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:45456 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727537AbfERCbK (ORCPT ); Fri, 17 May 2019 22:31:10 -0400 Received: by mail-qk1-f195.google.com with SMTP id j1so5611778qkk.12 for ; Fri, 17 May 2019 19:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Aqqb8fq9rk5ariT5pZi1gMWAA/hlm63uYollEoNQ9/o=; b=NX2oIG20JAoVtNLysGBZjgsCPWyGlNz8/o0M4HyjPOaevISxddvGsVTvEBqlHvjEYA +R++OHTjqL5/hfHhbKUsvnY2VjnihuEscKAVmcGz1zv7sNFTecNnlY0lzObmPb/dU7Ss bpdoEBh7Qsq7JxPdm7mbtP1+X47V5ItemL7W35UMSqcuU2IfO6KZ1yPfSB2xfigQLglw iYxeweDBAx5e1ioXQKkY4tPe4HFh3uKzU/nKQfIry6RccfwwciNRIaOwwwQpbAP6PiDp DJrAZdzykHjhlWKCvhbDS/2pQsCo4btzHZkRmTmChzbdnkSBJT4gNgT04mmwlKcgmAHo FjqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Aqqb8fq9rk5ariT5pZi1gMWAA/hlm63uYollEoNQ9/o=; b=dCIvNAXeJrpbtChiqPkWM5dMhslB0A5Bcb35W67K8aRVfqkkysWQ4a3MlezuQgYyLg EP3+2eVHcPhz1++ITewSnB6kp9qmfWjXqS1iKyt72vnxsCyk7xHyhyZQO0y6ofTePnFV zQow1d9YsdrHBhOWv61we1ixd9T4H6K4LoI4d8lQZf/I0ecVtcvls+P3zBks890XO4L9 cA5OUTSddxuqutxD01EhYJKc79dTOYKIXZQFOw9aRszwhB1eyC65o6EZguI34L8Xo3aK xw4xic82te69DCYx2bwfZdfc28NnDtjDKCwQzVidTvm033XbaAgivGPa+pL4FvbGSIqD KuFA== X-Gm-Message-State: APjAAAWJbTnk4kDwAPUCqtZq8R8fjqURCjvf7t03of3LoaKBUZmPKi+u VMiNfsxGPTCaEXqrtNgRM4g= X-Received: by 2002:a37:680c:: with SMTP id d12mr47915959qkc.202.1558146669664; Fri, 17 May 2019 19:31:09 -0700 (PDT) Received: from arch-01.home (c-73-132-202-198.hsd1.dc.comcast.net. [73.132.202.198]) by smtp.gmail.com with ESMTPSA id n66sm5210322qke.6.2019.05.17.19.31.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 May 2019 19:31:09 -0700 (PDT) From: Geordan Neukum To: gneukum1@gmail.com, Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] staging: kpc2000: kpc_i2c: prevent memory leak in probe() error case Date: Sat, 18 May 2019 02:29:58 +0000 Message-Id: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The probe() function performs a kzalloc to dynamically allocate memory at runtime. If the allocation succeeds, yet invoking the function i2c_add_adapter fails, the dynamically allocated memory is never freed. Change the allocation to use the managed allocation API instead and remove the manual freeing of the memory in the remove() function. Signed-off-by: Geordan Neukum --- drivers/staging/kpc2000/kpc_i2c/i2c_driver.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c b/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c index 6cb63d20b00f..9b9de81c8548 100644 --- a/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c +++ b/drivers/staging/kpc2000/kpc_i2c/i2c_driver.c @@ -628,7 +628,7 @@ int pi2c_probe(struct platform_device *pldev) dev_dbg(&pldev->dev, "pi2c_probe(pldev = %p '%s')\n", pldev, pldev->name); - priv = kzalloc(sizeof(struct i2c_device), GFP_KERNEL); + priv = devm_kzalloc(&pldev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) { return -ENOMEM; } @@ -685,10 +685,6 @@ int pi2c_remove(struct platform_device *pldev) //pci_set_drvdata(dev, NULL); //cdev_del(&lddev->cdev); - if(lddev != 0) { - kfree(lddev); - pldev->dev.platform_data = 0; - } return 0; } -- 2.21.0