Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2155123iof; Tue, 7 Jun 2022 21:35:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCqG5cPJibBZqsnfiOxZ18yb13kvDBSRnuNPoE3HU74IqiFAtM/MWGkcA20j8wDjr/WZnn X-Received: by 2002:a63:5706:0:b0:3fc:a31b:9083 with SMTP id l6-20020a635706000000b003fca31b9083mr27879196pgb.333.1654662958640; Tue, 07 Jun 2022 21:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654662958; cv=none; d=google.com; s=arc-20160816; b=mnTdvImntOlcHsNrt71YevGie5pqDHqsepoxSjZqvX3Nb/+sLFQ+9d3IMk79WRy5AY vf1OIfpJEmFngGPcjnsih/L7PGFM6tBr8PQaIYv30Qnr/x4B9AilOfmy5U4xK89sI7xu cpRVBhMOIGU2Duv2dQhpw8EkAbp40n3IeHqSu4Nh0s7AbVJlYCZDxqe2LhACvjQ/n4p5 t9COJaNGqdWAXB7Lx3HGKxLCLWuUYw3TZGW8OQCkW6ZSaej8m1zsES8cWxeaNy8EWcHN vQ+MEGxjPTgP+Bk6UbNQZi6g7yBMalOxbZ0kvmmotTPtiWb0MuNBtQIr1A+Bq351ph2e YTXw== 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=5eJGruq1wk96nrqvt1xlTXiFYzpTZVMEtUltUaIfxv8=; b=kILd3StiSBnLIscisd6ePGspOwKYckCsRHCHKJRlMGhTsMYvP5hwdc5uW3b3oVPG6f Eo2xb1gfdkqUT8OseX9eXzrBOL9nxdt6+tKsjQSNLRIq9Y6v2mOkzJj1mbYx84HNmNnp ePmT9Yj6u9iEP6H5v+O8xpCAD4K7GOTh7XThtlPI6ylxShCN14qphpdJZ8Ge3EGpCVWe l6jbkXdFjFEDWUcIj29GeHcKiEhQ33PSF+VfWKmQmBz35yT8xvdVUu95XbS8oYaBW9OF gnNlNahl3i2JTm8K6hQDXVwAoMzpFJ2aeyxsP6vyyXFc3/F0tuFeXEpNpApSVqobp7mU cn3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YXLIIL7F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l192-20020a6391c9000000b003fd87529fcesi5370994pge.642.2022.06.07.21.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YXLIIL7F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 580A01D5027; Tue, 7 Jun 2022 21:04:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349248AbiFGR77 (ORCPT + 99 others); Tue, 7 Jun 2022 13:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348216AbiFGRkl (ORCPT ); Tue, 7 Jun 2022 13:40:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 711E36D3AE; Tue, 7 Jun 2022 10:33:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id 6359EB822B4; Tue, 7 Jun 2022 17:33:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6592C34115; Tue, 7 Jun 2022 17:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623214; bh=fvqtBcjkHl2wfnU3dwlKLPAsMA4RiLi7gEH+8xIRx/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YXLIIL7FW/XG3zMTifq0FIV+KeNzforC6W9XuqOsY/c8wukJcMQ8Hp6aNmCPWnqlC KNEUD6SEc+PJfzT8C/fsbOC/ku8lIUuJnXEtZQG0grOPsWnEW4cs+tKLlLKVsBurD4 X2u3SIMFsf3fYWQFNGpqYz3Eip5b8VmM0ifXOwak= 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.10 295/452] pinctrl: renesas: core: Fix possible null-ptr-deref in sh_pfc_map_resources() Date: Tue, 7 Jun 2022 19:02:32 +0200 Message-Id: <20220607164917.345838911@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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 258972672eda..54f1a7334027 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