From patchwork Fri Jul 4 09:55:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 33082 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C1329203AC for ; Fri, 4 Jul 2014 10:01:56 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id n16sf7486841oag.6 for ; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=AQDH8faHR3HQfPUZncGE9qwRHhiA4v3wWz6eMzx2zGk=; b=f7P5S3hRdKL1EwT3utf6uPiNCdaq8mQ1z7U8gqSzXThwvEpZBPT11dGPmnR9l8/NqZ eWt63+gA7/OZM+/ezZpLXf/9EF8aJO/8reRfTh4kLVjDCBUgHzHi/2+weFn2MNTtV5LQ KdWBxihXIFSrY++UKp17k44IKDz5pwAl//1nHO903EtM9x0QgyvIGV0rVZGOnvDGBbzb nudjDEDLdjvgYDVxjABE/cS+Va2eshYgEr4cRDkLivpjSABUbjq6phwRrnxlcEcmvicg 8PLzVPALilM1OUQK/ncOib+cwoIsdbCimRoLz83HeaeKNHkJ1rpMJQgl1N3IQsfa/uzE 94MQ== X-Gm-Message-State: ALoCoQn4ZHyPnW/qjqcsQlr7G5sHsq6i/zizSG7TGm81nWLcgn66vkn2bnp6OBqFxpPFGS9T+yEb X-Received: by 10.182.209.37 with SMTP id mj5mr5332619obc.7.1404468116384; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.102.8 with SMTP id v8ls804393qge.15.gmail; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) X-Received: by 10.58.76.225 with SMTP id n1mr1063108vew.32.1404468116294; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id sk10si15336057vec.81.2014.07.04.03.01.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 04 Jul 2014 03:01:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.171 as permitted sender) client-ip=209.85.128.171; Received: by mail-ve0-f171.google.com with SMTP id jz11so1453646veb.2 for ; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) X-Received: by 10.52.253.131 with SMTP id aa3mr7457827vdd.25.1404468116224; Fri, 04 Jul 2014 03:01:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp453724vcb; Fri, 4 Jul 2014 03:01:55 -0700 (PDT) X-Received: by 10.68.252.41 with SMTP id zp9mr27239352pbc.65.1404468115476; Fri, 04 Jul 2014 03:01:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id no12si1794703pdb.457.2014.07.04.03.01.54; Fri, 04 Jul 2014 03:01:54 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758794AbaGDKBo (ORCPT + 27 others); Fri, 4 Jul 2014 06:01:44 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:33799 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965011AbaGDJ4F (ORCPT ); Fri, 4 Jul 2014 05:56:05 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s649u33U029418; Fri, 4 Jul 2014 04:56:03 -0500 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s649u28F018465; Fri, 4 Jul 2014 04:56:03 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Fri, 4 Jul 2014 04:56:01 -0500 Received: from localhost.localdomain (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s649tpYf017971; Fri, 4 Jul 2014 04:55:59 -0500 From: Roger Quadros To: , , CC: , , , , , , , Roger Quadros Subject: [PATCH v2 2/6] phy: core: Fix error path in phy_create() Date: Fri, 4 Jul 2014 12:55:44 +0300 Message-ID: <1404467748-12154-3-git-send-email-rogerq@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404467748-12154-1-git-send-email-rogerq@ti.com> References: <1404467748-12154-1-git-send-email-rogerq@ti.com> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: rogerq@ti.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Prevent resources from being freed twice in case device_add() call fails within phy_create(). Also use ida_simple_remove() instead of ida_remove() as we had used ida_simple_get() to allocate the ida. Signed-off-by: Roger Quadros --- drivers/phy/phy-core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index c64a2f3..49c4465 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -614,8 +614,9 @@ struct phy *phy_create(struct device *dev, const struct phy_ops *ops, return phy; put_dev: - put_device(&phy->dev); - ida_remove(&phy_ida, phy->id); + put_device(&phy->dev); /* calls phy_release() which frees resources */ + return ERR_PTR(ret); + free_phy: kfree(phy); return ERR_PTR(ret); @@ -799,7 +800,7 @@ static void phy_release(struct device *dev) phy = to_phy(dev); dev_vdbg(dev, "releasing '%s'\n", dev_name(dev)); - ida_remove(&phy_ida, phy->id); + ida_simple_remove(&phy_ida, phy->id); kfree(phy); }