From patchwork Tue Jun 3 21:30:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rickard Strandqvist X-Patchwork-Id: 355659 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9547714009C for ; Wed, 4 Jun 2014 07:29:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965120AbaFCV3o (ORCPT ); Tue, 3 Jun 2014 17:29:44 -0400 Received: from mail-la0-f52.google.com ([209.85.215.52]:35898 "EHLO mail-la0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965063AbaFCV3m (ORCPT ); Tue, 3 Jun 2014 17:29:42 -0400 Received: by mail-la0-f52.google.com with SMTP id s18so1885077lam.39 for ; Tue, 03 Jun 2014 14:29:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=f4bYq+LiQkL8PKZeMA6xF7V0jAEljOyB/7CmsNjRnsg=; b=Ohr7O+zMp43Y327REpxdWSmFeu7ntNZQh+MnYXpLOUk57dprjMFxCbKwanw/fZHwEE SY4nRx6NqQKPmZvjkzVFTQdZotlHmzyhutCSYh/zWM29/0vJJJpBPXBXswiA8jOF/RrJ UUs80azARDWvusgsXOK1ykvJckySpeYg7Z2eQzD/lancwvj2NBMGohtZO699RyuFzl6A 3lxJDn8HcW5M8++LWn3d1LTTrAe/+Z23ZIYZ11+RZAt7tW969cHZ9pIkgB1VMLKEvwQN J7rBieOwIFM9vpektDOciODoEmeYtRbYgrYW/eWdIx2YMP7JrgJepkt4yhaZio3gSyiS toGw== X-Gm-Message-State: ALoCoQm0iu94kkoTwwfDNRaEAeYiRKRj0nRB4Qm0sWCVsZtUUMvgV0CjTjq5VObxqohOz72m/bYP X-Received: by 10.152.20.168 with SMTP id o8mr4168138lae.78.1401830980668; Tue, 03 Jun 2014 14:29:40 -0700 (PDT) Received: from localhost.localdomain (h-245-62.a218.priv.bahnhof.se. [85.24.245.62]) by mx.google.com with ESMTPSA id ar1sm396549lbc.3.2014.06.03.14.29.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jun 2014 14:29:39 -0700 (PDT) From: Rickard Strandqvist To: Wolfram Sang , Grant Likely Cc: Rickard Strandqvist , Rob Herring , Jingoo Han , Leilei Shang , Daniel Drake , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH] i2c: busses: i2c-pxa.c: Fix for possible null pointer dereferenc Date: Tue, 3 Jun 2014 23:30:34 +0200 Message-Id: <1401831034-30255-1-git-send-email-rickard_strandqvist@spectrumdigital.se> X-Mailer: git-send-email 1.7.10.4 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Fix for possible null pointer dereferenc, and there is a risk for memory leak in when something unexpected happens and the function returns. Signed-off-by: Rickard Strandqvist --- drivers/i2c/busses/i2c-pxa.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index bbe6dfb..948a3c7 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c @@ -1142,10 +1142,8 @@ static int i2c_pxa_probe(struct platform_device *dev) int ret, irq; i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); - if (!i2c) { - ret = -ENOMEM; - goto emalloc; - } + if (!i2c) + return -ENOMEM; /* Default adapter num to device id; i2c_pxa_probe_dt can override. */ i2c->adap.nr = dev->id; @@ -1154,11 +1152,16 @@ static int i2c_pxa_probe(struct platform_device *dev) if (ret > 0) ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); if (ret < 0) - goto eclk; + goto emalloc; res = platform_get_resource(dev, IORESOURCE_MEM, 0); + if (res == NULL) { + ret = -ENODEV; + goto emalloc; + } + irq = platform_get_irq(dev, 0); - if (res == NULL || irq < 0) { + if (irq < 0) { ret = -ENODEV; goto eclk; } @@ -1267,9 +1270,9 @@ ereqirq: eremap: clk_put(i2c->clk); eclk: - kfree(i2c); -emalloc: release_mem_region(res->start, resource_size(res)); +emalloc: + kfree(i2c); return ret; }