Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5113437ybi; Sat, 20 Jul 2019 12:56:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPZqncewlOTJsfjaj5fyxeiMI3u8FoiChZO4Vyp5Sh1z/jt5SM5Hntnz1ba9Z0NutOXcCI X-Received: by 2002:a17:90a:7787:: with SMTP id v7mr66096570pjk.143.1563652591287; Sat, 20 Jul 2019 12:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563652591; cv=none; d=google.com; s=arc-20160816; b=kORC4DxJSflOZ5TV+l+pGv4dWIGBNIZnh9F2bnCxhUIWIhEzG3Ca+N9D8PUXv3ZZ0m G4DANpr99vcWjvUpIDYfIj+6KiCmKfO1vvNadRzZkvDcjERXB4yRwrVL/8DgOdztyzzQ QXIj8yj+YV2fIoUCH3JitpFz4Y9qjO3xAHyy8SpMwemTLucp3RPEql7y6Cm5juexERw+ iVY9ayZf549U2PRooa7MOKjOhG3LZKLpYojh2N05wiuh/QeOJvVLzhZJiK3k4f2QBw1n Cu/IpwU9d54nsl3KYJ0rwfgfFaK9f3MzbgrI9XGe2NBkgOolU+dNJxPcG/8YIBlqL8GU crIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=CtHfY6fdPxF732q6vlm8NQaExD6qpgpdM0SDXO2/oTY=; b=ZJ6xuoMVTc0zMDCKym+O26WHKBe/uVtWGagqoPcZIM1p4g2gF9aFCawldavtXBsahC xUelYePMkVFq2IQR47X6N2bQ1Nc4Jx7z/5vW1UIkmqUjs+hiCgNtXlFF5kYSV4j5jnwe 8o00ka285XI47fWg0YP5eWeDvA5Ri6LB5NH1bc0Wynm2HdqpFAE1TfFCs0ZPl6txZOeo 2u1DoihZov8CObfCzll74VoPiMo0vFpfFcqPTwBJBlcbG+iwoLThaQnMORSt8CL9PGC5 xbYancfKvLUIB9Xk8YjwaXn954DlwXa5+p5K7IqZrGx1Nbe3vjXJJnlP1yGp571F9JH7 7zbg== 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 24si6587501pgu.501.2019.07.20.12.56.14; Sat, 20 Jul 2019 12:56:31 -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 S1726223AbfGTTzy (ORCPT + 99 others); Sat, 20 Jul 2019 15:55:54 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:50237 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfGTTzy (ORCPT ); Sat, 20 Jul 2019 15:55:54 -0400 X-Originating-IP: 90.65.161.137 Received: from localhost (lfbn-1-1545-137.w90-65.abo.wanadoo.fr [90.65.161.137]) (Authenticated sender: alexandre.belloni@bootlin.com) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id AA0DC60005; Sat, 20 Jul 2019 19:55:51 +0000 (UTC) Date: Sat, 20 Jul 2019 21:55:51 +0200 From: Alexandre Belloni To: Trent Piepho Cc: "linux-rtc@vger.kernel.org" , "anson.huang@nxp.com" , "a.zummo@towertech.it" , "linux-kernel@vger.kernel.org" , "aisheng.dong@nxp.com" , "linux-imx@nxp.com" Subject: Re: [PATCH] rtc: snvs: fix possible race condition Message-ID: <20190720195551.GB3271@piout.net> References: <20190716071858.36750-1-Anson.Huang@nxp.com> <1563467526.2343.80.camel@impinj.com> <1563563060.2343.88.camel@impinj.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1563563060.2343.88.camel@impinj.com> User-Agent: Mutt/1.12.0 (2019-05-25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/07/2019 19:04:21+0000, Trent Piepho wrote: > On Fri, 2019-07-19 at 02:57 +0000, Anson Huang wrote: > > > > > I do worry that handling the irq before the rtc device is registered could still > > > result in a crash. From what I saw, the irq path in snvs only uses driver state > > > members that are fully initialized for the most part, and the allocated but > > > unregistered data->rtc is only used in one call to rtc_update_irq(), which > > > appears to be ok with this. > > > > > > But it is not that hard to imagine that something could go into the rtc core > > > that assumes call like rtc_update_irq() are only made on registered devices. > > > > > > If there was a way to do it, I think allocating the irq in a masked state and > > > then unmasking it as part of the final registration call to make the device go > > > live would be a safer and more general pattern. > > > > It makes sense, I think we can just move the devm_request_irq() to after rtc_register_device(), > > It will make sure everything is ready before IRQ is enabled. Will send out a V2 patch. > > That will mean registering the rtc, then unregistering it if the irq > request fails. More of a pain to write this failure path. > > Alexandre, is it part of rtc core design that rtc_update_irq() might be > called on a rtc device that is properly allocated, but not registered > yet? Yes, the main reason of the change of API was exactly to handle this. -- Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com