Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4061874yba; Wed, 17 Apr 2019 03:52:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzY/1q8KIiRgJWo3Z0sCEsRgrduWDp6qLuWXCsVPSWFTPb7XAAQIkoELC6b2ZAahwsDRRA7 X-Received: by 2002:a65:6645:: with SMTP id z5mr57380112pgv.251.1555498377054; Wed, 17 Apr 2019 03:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555498377; cv=none; d=google.com; s=arc-20160816; b=xCUmY3jHG/3LofaZ9reD1sy5wXehK0ZJzf023aDjQfid4ulaSB02ry1A34M7WIpJob RFQqq9XZQzrRBypwSxUV0GsXfi5rkqAkQj79nClRItiv+5O3AX6sAkKjX4JLDvV+tXoc vEbEePV01AXYEjatmqzx03jv40Yyff5xPKs1GpAsXWGR4Dr2F/i88SDnAE1mQvXdfUlk CZKx55nAmpTmTIxWAIie6vKvH9HmZ0TywhBYJ/4pLXAzsODItaOMBxGT4qAwDE3+4B/y 0q/XU39kiAuNtXcTNzCdJsFoAnFbPtTvEjdf0P78iT1x4Q5u4EnUyvc+34uupoyXhGe/ s5ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=P+wHLlGQH14iL5T25+wCorAAqXLtofaYnTroz8AWOvw=; b=s0kzHuwhGtWyNdmlorgqMxmSpJa0opsBoe1QABhLKaIxne6ikBwwt37DjVu7FZ4BBM OVYefQpsaL2tXoLsSaKKtTjVnZhGxcUNKEHu7wHCwv90NgJpqYsZFMLAgdrJr17OI31b FBx7821JCIed0QIyWZZklI17qdAq8s2aAHSH2WCcYXoojrIkuB1uTP8/6JDtLG+MLBN0 kfGtuE2FXTl+Jb2CMspKpZMb68XKRPktfmVH4FiL9Bkl11rJwO9pdBlW89GrOAGyQhb3 N7a4zr8HHF7tPTQIOOXZVFdYU23XAjfU4h4Aov3+Dh+vTwmprmlUHRBg3+a9/WP1MocZ ibdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=qcIiL2Ei; 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=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k11si50490355pga.257.2019.04.17.03.52.41; Wed, 17 Apr 2019 03:52: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=@163.com header.s=s110527 header.b=qcIiL2Ei; 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=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731724AbfDQKtm (ORCPT + 99 others); Wed, 17 Apr 2019 06:49:42 -0400 Received: from m50-134.163.com ([123.125.50.134]:54822 "EHLO m50-134.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725792AbfDQKtl (ORCPT ); Wed, 17 Apr 2019 06:49:41 -0400 X-Greylist: delayed 906 seconds by postgrey-1.27 at vger.kernel.org; Wed, 17 Apr 2019 06:49:41 EDT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=P+wHLlGQH14iL5T25+ wCorAAqXLtofaYnTroz8AWOvw=; b=qcIiL2EiQas+VoPpz4h9C42XumfvF8hp6N YqwJ4/rkUWsqqN/3n0B+lYij02jZuqI8mKFgcQjpHsKVXEoLEecz1RGuiPgKaI5k zakaMv5FNW0XEsru243/bjakOYeqzBKxAp84J8fQ6Xc6MOXjQjyk+RB/scfHBM31 IodNWOeaw= Received: from bp.localdomain (unknown [218.106.182.174]) by smtp4 (Coremail) with SMTP id DtGowADXfTMMAbdcTctsAA--.203S3; Wed, 17 Apr 2019 18:34:32 +0800 (CST) From: Pan Bian To: Johannes Thumshirn Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: mcb: correct error handling in mcb_alloc_bus Date: Wed, 17 Apr 2019 18:33:44 +0800 Message-Id: <1555497224-72490-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: DtGowADXfTMMAbdcTctsAA--.203S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7JF15Ary5tF13AryUGry3urg_yoWktwb_Ga 4jvrW7WrW8tw1UWayfJr4xZ34xKrn29r95urnrta93C3yUG34DurZIqws8WrWxXay29FyU Xa4kZr4xZr12qjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUUfb15UUUUU== X-Originating-IP: [218.106.182.174] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBzxmZclaD2Np+WQAAsN Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two issues in the error handling code. First, if ID allocation fails, the reference count of carrier is decremented, which has not been incremented yet. Second, if device_add fails, the allocated ID will not be released. This patches fixes them. Signed-off-by: Pan Bian --- drivers/mcb/mcb-core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c index bb5c569..b5c6a1b 100644 --- a/drivers/mcb/mcb-core.c +++ b/drivers/mcb/mcb-core.c @@ -280,8 +280,8 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier) bus_nr = ida_simple_get(&mcb_ida, 0, 0, GFP_KERNEL); if (bus_nr < 0) { - rc = bus_nr; - goto err_free; + kfree(bus); + return ERR_PTR(bus_nr); } bus->bus_nr = bus_nr; @@ -296,12 +296,11 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier) dev_set_name(&bus->dev, "mcb:%d", bus_nr); rc = device_add(&bus->dev); if (rc) - goto err_free; + goto err_put; return bus; -err_free: - put_device(carrier); - kfree(bus); +err_put: + put_device(&bus->dev); return ERR_PTR(rc); } EXPORT_SYMBOL_GPL(mcb_alloc_bus); -- 2.7.4