Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4806333iob; Mon, 9 May 2022 02:00:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKjw/TIl4WHg6VbZgKJ7xq6xZ280MXlxlYF7GnK2MoLE/sPBz4Z3/81xiT+RFw4iAkMWEm X-Received: by 2002:a17:902:e2d4:b0:15e:e9f1:4d3e with SMTP id l20-20020a170902e2d400b0015ee9f14d3emr15024230plc.73.1652086805653; Mon, 09 May 2022 02:00:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652086805; cv=none; d=google.com; s=arc-20160816; b=oRouYwdYRqjT0LkFJmYbMTJvQkz7xDjqvKnlRXWFBQqoViojP7DSK5kUghN+7jNRHl 3HPg4B0ORt3MHAIrb5Y++LEHT88hIXlNMSGfN00uYfq1KQlj/ilbfWPt/Hnpb3bGFm9R 6MC0gkg283IairCdT9NftPVv3Nw0hH2xiyqY5+ZTnCqm5aBLNgMLmkbwKgx+WN8EQUua rdQxp+aIBDudpStw8PiBPdoU/PrEoQKwEmit089aV9fbvQG1WWSeBpjYU/JmN7DpR520 uDvdH7cjiBECN10dupPVsAa4+/61zM4mfT8JM4rNch2KxewxnKFkd9CyyvIyclubFGHM T1Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:in-reply-to:date:subject :cc:to:from:user-agent:references:dkim-signature; bh=DD1PW4oPo4t5OyhM7+2pmEQujcIm2KRLswaIhVpcZfw=; b=n+ycZInAVH+oYAHHz1iqLdDWbuwU5jPdYYWSX1E6G8RCAVL3FPbDjpRhDqM7iLmgSx WSVdSI/DyDeK/cNC29SFB924lF8pZDaDILBevp/J12tNR9D/z5juj0iYmjvizenvXX+m 6XoWO0Am2GEXPSqDJGVOK3OU3LoOABP7bA7YkujwpZHiR+JSlHRBhr01u4xAsxmDGGAr T0Y3GUsfEp0HbW2d79ROwPqoNcnklBbQVWwX+jJ5JH32xL+oFOwNjPCBkg+0NMKSCF1m qGByYSSwcR1to10QVmSRA0ejVV4pCf4fJjNgILDXMcDv54EJ88w9P5bTmdPwE3L/8of8 fEpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=nPsokUTe; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h187-20020a636cc4000000b003ab2952c596si13048507pgc.487.2022.05.09.02.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 May 2022 02:00: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=@tkos.co.il header.s=default header.b=nPsokUTe; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C1A3D165200; Mon, 9 May 2022 01:46:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242406AbiEEOlh (ORCPT + 99 others); Thu, 5 May 2022 10:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232677AbiEEOlf (ORCPT ); Thu, 5 May 2022 10:41:35 -0400 Received: from mail.tkos.co.il (golan.tkos.co.il [84.110.109.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC19853A43; Thu, 5 May 2022 07:37:55 -0700 (PDT) Received: from tarshish (unknown [10.0.8.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 4E558440F39; Thu, 5 May 2022 17:36:58 +0300 (IDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1651761418; bh=YKpQePxu2a+ZeS7IXYXOK7QZI9aPzC1QorvRu4TfF58=; h=References:From:To:Cc:Subject:Date:In-reply-to:From; b=nPsokUTenIiWaJ4S8OJO9pB/xvlgAdOVqNlCq5iThlZqza+uc/Ra2IUiG8gdjC0Sa I9BDG250OJq5Lauf8STOlphUvMZ15ZIsU/hR7H3FoLufpOFeaTtK+ZbSqcO8YEWdg7 DaF0tVIaihHhnL9YAYJl41CdakzPctGTYM/19F9BF4YQqyQSbNuGdw/JaGR2EubwDh KsEAiDnSLaJL75WaVxcsxMb8QR+452URXbM/+eE3MbhjFHiagxrsg6pVQw8lzn5zQg rgQ/BV2IxzCjoON5Ohvx3odPBAU6bLP/ed5DO41bMyin7kbEM29ymK0trVxCo5k/iv RA1Of6ec9AmuQ== References: <20220505124621.1592697-1-yangyingliang@huawei.com> User-agent: mu4e 1.6.10; emacs 27.1 From: Baruch Siach To: Yang Yingliang Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, jirislaby@kernel.org Subject: Re: [PATCH] tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe() Date: Thu, 05 May 2022 17:36:36 +0300 In-reply-to: <20220505124621.1592697-1-yangyingliang@huawei.com> Message-ID: <87h764hwow.fsf@tarshish> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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 Hi Yang, On Thu, May 05 2022, Yang Yingliang wrote: > 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 Reviewed-by: Baruch Siach Thanks, baruch > --- > 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) -- ~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -