Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4408409pxb; Mon, 21 Feb 2022 20:37:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfI6fR1BzzkH2leIT83a3lj1GAOl52RHAxb8QTUwd61/KtXEVip3l3pH9Lr/spTrO2AutB X-Received: by 2002:a17:903:18e:b0:14d:d208:58d3 with SMTP id z14-20020a170903018e00b0014dd20858d3mr21833746plg.57.1645504654990; Mon, 21 Feb 2022 20:37:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645504654; cv=none; d=google.com; s=arc-20160816; b=ev2j3gmuevSCjVRE89n0W9qK7yqLfn8FuCt7F+w9DO3vT3tc9b5B7hZrf9ja7RZv9X Vnpxl5ZCD7v5vYNUa23jKBlyX4DfsYvR/zuCGB04uo1Te6H9cHlFiD3lcFM7VIxfltzP YiWtauDtggb483o/WEHCjDYRgs9XO5B1HQDsr82jWaLhaOUDJ5votrw81NvKZSm1wh5T QLRCunNgXyogiMiTEdjuWZdp4jgB4lzIwRP6Hiqep0A6kdrCXQNEh01pUod+5Ic87fDT Hy+2CHc1AVY/SoaxIbTiK7Hwf/d5M5T/+ZZ87KSD1NeO6vaw54fO6xHzUF7opLfsVYKu pjoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dKz9kHB9Za5FYiUZ2P3qDeIZQ4OXdVM/hPa1fCMk6/0=; b=LOlQbElobr7hnGSZ3SmaSvNCZLxAj6I9PTEDVl3UM4nPQU3bB9olSKsx7Cw2BnVFbV Hqq0ThoXLJOOKu+74RvwjxLu3WrUKRC/lRPy8t9osHAmbxfygR7VT6cS2JThExEIR7m+ aqurgJjpdKFguvwVsBHkKEa7IoAWQFYL3I/XN1xFpdJ8ArFaFzy1pOpedMU9Ym4THXW/ ysdI321ewlTagJbm5jbndqEMsgAKUZU+59OyJz3nXCJXB8wN+hvS2ajom3jKuN2HDv+1 R5A0UiWUySZqu6fiYY+WnunTUaM5Gcx4NPp4jt51AgmZp69o0qmz1t22hKb07WNwa4Oj EveQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xwxlS6l8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id w141si10296292pfc.374.2022.02.21.20.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:37:34 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xwxlS6l8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF7D395A32; Mon, 21 Feb 2022 20:25:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353797AbiBUKLe (ORCPT + 99 others); Mon, 21 Feb 2022 05:11:34 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353502AbiBUJ53 (ORCPT ); Mon, 21 Feb 2022 04:57:29 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB748D; Mon, 21 Feb 2022 01:26:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4B49B60F8C; Mon, 21 Feb 2022 09:26:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 337A0C340E9; Mon, 21 Feb 2022 09:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435588; bh=42zi/zigIyIUQ1oqsPKN7CLx5IlCRHcYsWZ5A3UZKvg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xwxlS6l8PdgXLhcc7De8Y+jd5TpTkWUAz7INUaaKoR40P/6z2o/f3B0oDkCl54j7E iRmgcYO3EeEijY1UgnKWc2SySWAercv4qzGfb5lk47JvOwfGKfmqbip8QIFcDYJYL4 LDwXDCtBvGY652G2X5IObxm7TGajO7N2Mxt0Pil0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vladimir Zapolskiy , Robert Foss , Bjorn Andersson , Wolfram Sang Subject: [PATCH 5.16 184/227] i2c: qcom-cci: dont put a device tree node before i2c_add_adapter() Date: Mon, 21 Feb 2022 09:50:03 +0100 Message-Id: <20220221084940.937091035@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vladimir Zapolskiy commit 02a4a69667a2ad32f3b52ca906f19628fbdd8a01 upstream. There is a minor chance for a race, if a pointer to an i2c-bus subnode is stored and then reused after releasing its reference, and it would be sufficient to get one more reference under a loop over children subnodes. Fixes: e517526195de ("i2c: Add Qualcomm CCI I2C driver") Signed-off-by: Vladimir Zapolskiy Reviewed-by: Robert Foss Reviewed-by: Bjorn Andersson Signed-off-by: Wolfram Sang Signed-off-by: Greg Kroah-Hartman --- drivers/i2c/busses/i2c-qcom-cci.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) --- a/drivers/i2c/busses/i2c-qcom-cci.c +++ b/drivers/i2c/busses/i2c-qcom-cci.c @@ -558,7 +558,7 @@ static int cci_probe(struct platform_dev cci->master[idx].adap.quirks = &cci->data->quirks; cci->master[idx].adap.algo = &cci_algo; cci->master[idx].adap.dev.parent = dev; - cci->master[idx].adap.dev.of_node = child; + cci->master[idx].adap.dev.of_node = of_node_get(child); cci->master[idx].master = idx; cci->master[idx].cci = cci; @@ -643,8 +643,10 @@ static int cci_probe(struct platform_dev continue; ret = i2c_add_adapter(&cci->master[i].adap); - if (ret < 0) + if (ret < 0) { + of_node_put(cci->master[i].adap.dev.of_node); goto error_i2c; + } } pm_runtime_set_autosuspend_delay(dev, MSEC_PER_SEC); @@ -656,8 +658,10 @@ static int cci_probe(struct platform_dev error_i2c: for (--i ; i >= 0; i--) { - if (cci->master[i].cci) + if (cci->master[i].cci) { i2c_del_adapter(&cci->master[i].adap); + of_node_put(cci->master[i].adap.dev.of_node); + } } error: disable_irq(cci->irq); @@ -673,8 +677,10 @@ static int cci_remove(struct platform_de int i; for (i = 0; i < cci->data->num_masters; i++) { - if (cci->master[i].cci) + if (cci->master[i].cci) { i2c_del_adapter(&cci->master[i].adap); + of_node_put(cci->master[i].adap.dev.of_node); + } cci_halt(cci, i); }