From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751763AbdHaPWu (ORCPT ); Thu, 31 Aug 2017 11:22:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58268 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbdHaPWt (ORCPT ); Thu, 31 Aug 2017 11:22:49 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 192507E44C Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=hdegoede@redhat.com From: Hans de Goede To: Peter Rosin Cc: Hans de Goede , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Subject: [PATCH] mux: core: Fix double get_device() Date: Thu, 31 Aug 2017 17:22:45 +0200 Message-Id: <20170831152245.14502-1-hdegoede@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 31 Aug 2017 15:22:49 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org class_find_device already does a get_device on the returned device. So the device returned by of_find_mux_chip_by_node is already referenced and we should not reference it again (and unref it on error). Also rename of_find_mux_chip_by_node to of_get_mux_chip_by_node to make it clear that it returns a reference. Signed-off-by: Hans de Goede --- drivers/mux/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/mux/core.c b/drivers/mux/core.c index 7aa656ac8fb5..8864cc745506 100644 --- a/drivers/mux/core.c +++ b/drivers/mux/core.c @@ -433,7 +433,7 @@ static int of_dev_node_match(struct device *dev, const void *data) return dev->of_node == data; } -static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) +static struct mux_chip *of_get_mux_chip_by_node(struct device_node *np) { struct device *dev; @@ -471,7 +471,7 @@ static struct mux_control *of_mux_control_get(struct device *dev, return ERR_PTR(ret); } - mux_chip = of_find_mux_chip_by_node(args.np); + mux_chip = of_get_mux_chip_by_node(args.np); of_node_put(args.np); if (!mux_chip) return ERR_PTR(-EPROBE_DEFER); @@ -480,6 +480,7 @@ static struct mux_control *of_mux_control_get(struct device *dev, (!args.args_count && (mux_chip->controllers > 1))) { dev_err(dev, "%pOF: wrong #mux-control-cells for %pOF\n", np, args.np); + put_device(&mux_chip->dev); return ERR_PTR(-EINVAL); } @@ -490,10 +491,10 @@ static struct mux_control *of_mux_control_get(struct device *dev, if (controller >= mux_chip->controllers) { dev_err(dev, "%pOF: bad mux controller %u specified in %pOF\n", np, controller, args.np); + put_device(&mux_chip->dev); return ERR_PTR(-EINVAL); } - get_device(&mux_chip->dev); return &mux_chip->mux[controller]; } -- 2.13.4