Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2196390iof; Tue, 7 Jun 2022 22:54:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoFN2SPeFxJgYWLDQU3qxYjuMN/RNTEVla1MVyAVXsKDmZqskF6dVBYUv11J4zJEwjREzu X-Received: by 2002:a63:e5d:0:b0:3aa:3c53:537e with SMTP id 29-20020a630e5d000000b003aa3c53537emr28535099pgo.622.1654667645164; Tue, 07 Jun 2022 22:54:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654667645; cv=none; d=google.com; s=arc-20160816; b=QPwY8X6htPGJFIa4ofxoYy0ur8VZmMDLacsoSu45jjjQgaiv8lhD5t7HVhWguwXKl5 xAP7igW0nC+9OHLg/LTBa00y9RWw72EAu78RCVB9eK4MyTVVUKkTruf+b4toDCpfBe61 1VzdtApqEKhdg7hh4ckAUG1WjMJdTLNHjQt20vXyQHK9iL4hP6x8hwjDuh6PFwgRhpR9 nAHJGFt6dWI+b7069Oe26C0KM9BpvT8l8WTRZd/k7V9+LDAcg/secGSHg+mX+BjYWAag 8PTScMLr/UmIJmcTJx0GtzidAdEfmbQnYzQSEUFTGmyHrhxh3EjJLdrzXlTiLolNyOF4 7odQ== 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=iNTyP42LyCnP1yIb9p/UhAD6NuJ3xA8HD+Hua0uELCw=; b=OhZkfQMPLBC+0Vix1b4xrD/TVGsilVeRjBnPXzSROA47GGBXCnhaa74yuQCJfj/dz4 06sIdS804QCRThLjXrdE044J8iZETYI/wJ9GHnbx0I6HBd2o48JDhjypQzV7J/Os4bQY 7/+gfYCTZ1w44+a2S6VpO1k7gPepkunw1xeoeReU9T7LRXfqr8kSxGGXAoxr/7GAcsTm oewb2BFgzg0R/uqVuWIY/2H04XsEMISkz5IGRcdaK/o1SXPHXEo8x/J8aML2Ioq/9PQu 5VZRSwdmLr19zdUccqxLnXr1s8UbDSrHXmAmcHEO3jPZM4LHzdYjf2WgULLRMLXcVr12 VCIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wf4PPsOe; 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 ik30-20020a170902ab1e00b0015f371008edsi25775296plb.396.2022.06.07.22.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:54:05 -0700 (PDT) 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=Wf4PPsOe; 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 67BD04AADD6; Tue, 7 Jun 2022 22:20:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234302AbiFHAss (ORCPT + 99 others); Tue, 7 Jun 2022 20:48:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382341AbiFGVzs (ORCPT ); Tue, 7 Jun 2022 17:55:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C74224CC82; Tue, 7 Jun 2022 12:13:46 -0700 (PDT) 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 42DBD6191A; Tue, 7 Jun 2022 19:13:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B6BBC385A2; Tue, 7 Jun 2022 19:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629202; bh=z7AVenX/X9Jsutgao0sLOigp9cSo+2vLYkPsboRwK6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wf4PPsOeFRzlSfMOqZgRFm1T4j+he0fueEb4CHn6rIr0ZHlpHHPkPN+zwnwnc/grb qCg3zKthwD6Cst9/y5BP1VIBfXpFdUKizmfkae8WtoFlmEUXn1F1/MlpewVKsmLajO bup4WBEMIbbW8ikwlb+IeAyXGoKvBlPod76u80Io= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Yingliang , Geert Uytterhoeven , Sasha Levin Subject: [PATCH 5.18 606/879] pinctrl: renesas: core: Fix possible null-ptr-deref in sh_pfc_map_resources() Date: Tue, 7 Jun 2022 19:02:04 +0200 Message-Id: <20220607165020.440730483@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 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=unavailable 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: Yang Yingliang [ Upstream commit 5376e3d904532e657fd7ca1a9b1ff3d351527b90 ] It will cause null-ptr-deref when using 'res', if platform_get_resource() returns NULL, so move using 'res' after devm_ioremap_resource() that will check it to avoid null-ptr-deref. And use devm_platform_get_and_ioremap_resource() to simplify code. Fixes: c7977ec4a336 ("pinctrl: sh-pfc: Convert to platform_get_*()") Signed-off-by: Yang Yingliang Link: https://lore.kernel.org/r/20220429082637.1308182-1-yangyingliang@huawei.com Signed-off-by: Geert Uytterhoeven Signed-off-by: Sasha Levin --- drivers/pinctrl/renesas/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/pinctrl/renesas/core.c b/drivers/pinctrl/renesas/core.c index d0d4714731c1..3d8bf521c3e7 100644 --- a/drivers/pinctrl/renesas/core.c +++ b/drivers/pinctrl/renesas/core.c @@ -71,12 +71,11 @@ static int sh_pfc_map_resources(struct sh_pfc *pfc, /* Fill them. */ for (i = 0; i < num_windows; i++) { - res = platform_get_resource(pdev, IORESOURCE_MEM, i); - windows->phys = res->start; - windows->size = resource_size(res); - windows->virt = devm_ioremap_resource(pfc->dev, res); + windows->virt = devm_platform_get_and_ioremap_resource(pdev, i, &res); if (IS_ERR(windows->virt)) return -ENOMEM; + windows->phys = res->start; + windows->size = resource_size(res); windows++; } for (i = 0; i < num_irqs; i++) -- 2.35.1