Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4784242yba; Tue, 30 Apr 2019 04:27:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/B/cXbHmfYOGqEcACaPdMicAbfuKrOi51lfIvjGbn4b/CqhSA3cZ0qjazSldx0eZD0egN X-Received: by 2002:a63:9a52:: with SMTP id e18mr20002626pgo.335.1556623627392; Tue, 30 Apr 2019 04:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556623627; cv=none; d=google.com; s=arc-20160816; b=I/91ewCC5ZVT+VajeBYZgyWHOe62Nj+BLeEyZ1RczmVAMWg7l/B81d2CL2VEFoakQG kEmq2Cgeusifp9ZIZfZU57q1T/QoVqn23VhtSoiRIuVh2giUiGSIoeVyegyYVXgzI21a zAZzofOGfdSDeamFyrCU19FHK79JjGidNHL5S/nJGQE6nABYoswe/aXXRfu7tMM+tfi9 lAt3fy4zfjYR5bc9F8TCMXNz80CqH/FmFaB4PSqZnaVhUdOg2x4ztxkydA47qADa+9pU FnL7wnrrd+2Yy81UCwRipswQCB6s4n+yZrojLgfTbqh56eevaDHuimSHdrirBHCGoVdf x33g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references; bh=P7w7gLKi1Hke0+61GHDPTlhVVwxnswA7qeKpcAUXNZw=; b=iVaht/wIX3S6kpZh2G/638EXSJAqrx+5PmqNtaM3Pxj9XzQLofZEFubtKRC2ijOsq3 BizFOnZ7rlt1o9xzWQSCCrNhnud635Ugedqo9OGsmswPIWe7TV2rKUIsYxfdReGjfT1u RcNwuYlAMsuAzXhj6oAQcDO0MDO2x/o9KzcXVbQkXmq3YWC1eOd7S3J8iBd74dNirZPw 6LFuJoJBHNf1Jar/Wd/SG16PELs7+iQwHpaorFo/3yrw/aq58AIdVCqkUMoMA/J201/6 DaHBflHvPXZ2wCtYVFDSnKPiu6NhX894UqmbgmbBp/WSCUxkMISpNjtQLUWmRb+1uOqL TqpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si30370876plq.240.2019.04.30.04.26.52; Tue, 30 Apr 2019 04:27:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727253AbfD3LZs (ORCPT + 99 others); Tue, 30 Apr 2019 07:25:48 -0400 Received: from guitar.tcltek.co.il ([192.115.133.116]:58371 "EHLO mx.tkos.co.il" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726129AbfD3LZr (ORCPT ); Tue, 30 Apr 2019 07:25:47 -0400 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 mx.tkos.co.il (Postfix) with ESMTPS id C72FE44028D; Tue, 30 Apr 2019 14:25:43 +0300 (IDT) References: <20190430093212.28425-1-alexandre.belloni@bootlin.com> User-agent: mu4e 1.0; emacs 26.1 From: Baruch Siach To: Alexandre Belloni Cc: linux-rtc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/4] rtc: digicolor: fix possible race condition In-reply-to: <20190430093212.28425-1-alexandre.belloni@bootlin.com> Date: Tue, 30 Apr 2019 14:25:43 +0300 Message-ID: <878svru43s.fsf@tarshish> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandre, On Tue, Apr 30 2019, Alexandre Belloni wrote: > The IRQ is requested before the struct rtc is allocated and registered, but > this struct is used in the IRQ handler. This may lead to a NULL pointer > dereference. > > Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc > struct before requesting the IRQ. > > Signed-off-by: Alexandre Belloni Acked-by: Baruch Siach baruch > --- > drivers/rtc/rtc-digicolor.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/rtc/rtc-digicolor.c b/drivers/rtc/rtc-digicolor.c > index b253bf1b3531..5bb14c56bc9a 100644 > --- a/drivers/rtc/rtc-digicolor.c > +++ b/drivers/rtc/rtc-digicolor.c > @@ -192,6 +192,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) > if (IS_ERR(rtc->regs)) > return PTR_ERR(rtc->regs); > > + rtc->rtc_dev = devm_rtc_allocate_device(&pdev->dev); > + if (IS_ERR(rtc->rtc_dev)) > + return PTR_ERR(rtc->rtc_dev); > + > irq = platform_get_irq(pdev, 0); > if (irq < 0) > return irq; > @@ -200,12 +204,10 @@ static int __init dc_rtc_probe(struct platform_device *pdev) > return ret; > > platform_set_drvdata(pdev, rtc); > - rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, pdev->name, > - &dc_rtc_ops, THIS_MODULE); > - if (IS_ERR(rtc->rtc_dev)) > - return PTR_ERR(rtc->rtc_dev); > > - return 0; > + rtc->rtc_dev->ops = &dc_rtc_ops; > + > + return rtc_register_device(rtc->rtc_dev); > } > > static const struct of_device_id dc_dt_ids[] = { -- http://baruch.siach.name/blog/ ~. .~ Tk Open Systems =}------------------------------------------------ooO--U--Ooo------------{= - baruch@tkos.co.il - tel: +972.52.368.4656, http://www.tkos.co.il -