Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3378061iob; Sat, 7 May 2022 03:44:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUNqlOAlB1z+Y53p0ur3EUmoUpb+m28rv2Zw6djVpgVyJWQaj9V5maBibvBJZSALX6nzZk X-Received: by 2002:aa7:d751:0:b0:425:d38c:41a1 with SMTP id a17-20020aa7d751000000b00425d38c41a1mr7966971eds.162.1651920248899; Sat, 07 May 2022 03:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651920248; cv=none; d=google.com; s=arc-20160816; b=kRdPD884UQzThL+KtRRIPLPgRMaTKWVtk179leWFLXJ0o9/fWxj/jYMuepeqVimaSo wAlF0JzmJzRU7VcHiBKIf4Bvi2iA1VMyR9WZm6LQR265PwH8x5tKMPiQHvVBHWWKP9hL 3y8ojnxZEusnP2aO13NzRaitgVYaoLVCXc+HQNeILy2k6nV/bCvvHwDEwiKhrbMyYRBd TEUO+UkdB4JJ1HeLFPv0o5llpTZ4Es0s1QDzRDIdNmrfZlTXnSDg0BbN26ApQvJqmstM UHeHVsZZvRHeuvYBsNdrZNibdzucNlpz6FKH0AGKvLfgQz2fOOdJGNc2agjHSKn6oIMw s5iA== 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 :message-id:date:subject:cc:to:from; bh=YDKaO2jyOvsfEWzyr2q9Tx9GxmwSsNwCVaLQQCsMz2U=; b=LBQGTrVKEMTIUutmMvuPvjfebbNfXq/pJfkBytxwQ1HPE5czG2W+9N8eNpm5P0PM1+ lf9jwrYkdIM/dqwM2ULgJ5dQd+hfFXCstl7JTlNmYfM2VVl/RYdlx5SowvjAUrCTWkA5 +/WvZFr0KhWeOxuxIczOaRsDRgmoGulbCZzcuHHFJSejmt5JWB7cSDhj81xP+9vUokh0 JPQjryi20RukZnftwt2/ZnzczrZ2AmfhE25716u0Ms9uW35xLZxuVJ0U6Bgh9UUNcqnb cIWwmZ7cILO8PVpZ5sqbtXDSmcNCvLJJK+f1zuF9RlOiq+QOtWRCRqSV0qlR3MXEbPLp CTKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a170906564d00b006e89718a80csi7663685ejr.507.2022.05.07.03.43.45; Sat, 07 May 2022 03:44:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354722AbiEEMiV (ORCPT + 99 others); Thu, 5 May 2022 08:38:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239317AbiEEMiT (ORCPT ); Thu, 5 May 2022 08:38:19 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E05BC5520D; Thu, 5 May 2022 05:34:39 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KvCh50J3ZzHnV3; Thu, 5 May 2022 20:29:57 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 5 May 2022 20:34:38 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 5 May 2022 20:34:37 +0800 From: Yang Yingliang To: , , CC: , , Subject: [PATCH] tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe() Date: Thu, 5 May 2022 20:46:21 +0800 Message-ID: <20220505124621.1592697-1-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 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: 5930cb3511df ("serial: driver for Conexant Digicolor USART") Signed-off-by: Yang Yingliang --- drivers/tty/serial/digicolor-usart.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c index 6d70fea76bb3..e37a917b9dbb 100644 --- a/drivers/tty/serial/digicolor-usart.c +++ b/drivers/tty/serial/digicolor-usart.c @@ -471,11 +471,10 @@ static int digicolor_uart_probe(struct platform_device *pdev) if (IS_ERR(uart_clk)) return PTR_ERR(uart_clk); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - dp->port.mapbase = res->start; - dp->port.membase = devm_ioremap_resource(&pdev->dev, res); + dp->port.membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res); if (IS_ERR(dp->port.membase)) return PTR_ERR(dp->port.membase); + dp->port.mapbase = res->start; irq = platform_get_irq(pdev, 0); if (irq < 0) -- 2.25.1