Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1932642imm; Thu, 24 May 2018 03:09:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrWoxxuRQKtkGgzMzpccXf/f5XgcxghPEe5KKNoOvCH9vEZQ1UJb3T2xx4CbPVCFz8cXDKO X-Received: by 2002:a62:d717:: with SMTP id b23-v6mr6492930pfh.5.1527156572254; Thu, 24 May 2018 03:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527156572; cv=none; d=google.com; s=arc-20160816; b=tZY1ipwTPJI7ko2BDkI7mjiZ5mHdJemlyLkMwe9mpRjgqnJB4Fve0j/5OBCx9Iy9E+ Hj5OTyK4tWvhFkuFvLMHxy8zsVcZoHiUrsUzupjAGeazone8l6HR/ZvI1Afe1f5Psln9 b2PmlxCmtqLi1hEBqiE/hJsuwre5JBfOXqLDmdRWfHrOWIYVXHx5v7lr7tcrB2P5zBfx Zr+kSPrxvMHUNKylS7dn0G8KNVyvStOTkjhM2t7JJMZb6L03oi+SEo6XTyNK8DawhSgi K0Eoqyv/oIGenBP/QAw5eMJPPq7b56ikxF/80lt3wPW/NGdfqIEGtBLQVK+bhbGFbLo+ WptQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=oRc0IIRgHHCAlEBJD1ai8pc+RdWGSfQnp3amYbopjww=; b=W21kplwNKCtLY4IP1Hn/6C+isNwY9Ep+mm4MhQsyb5hn7uMyAKYThsxxDe0nn2oi0z Aun1VkyaFq7mi7IV540FrLbVxbM1DZ2jn9tgC7nHbP9o2l7qof+yS5DpATCa/InpCXon 8jsipvrX2YM84qujDsPh/fDGI29Qm6PmoC3rle9oud6kGhhded6gvEq26+8mliK260dp R5JpbUarySMUCJFeRiYtosqlWXz/JDELJkmMaSTOo81Gp+7h4VDax1ckvZTeXIWNh1Ya bBStlrN4KPt+OM5aCU+ke7jx4JYvYrMCRR9FHptbsJZcw+DtHflwKI69qufy/7HW9uzh Uz2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yipjeYuc; 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 e68-v6si21626127pfl.132.2018.05.24.03.09.17; Thu, 24 May 2018 03:09:32 -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; dkim=pass header.i=@kernel.org header.s=default header.b=yipjeYuc; 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 S1031782AbeEXKI2 (ORCPT + 99 others); Thu, 24 May 2018 06:08:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:55100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031229AbeEXKGF (ORCPT ); Thu, 24 May 2018 06:06:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1E38620870; Thu, 24 May 2018 10:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156364; bh=XOTYbEwZQFnUK3x55VCL33VfbLb1UZkc7Z3/Rdopvjk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yipjeYuc5Jq414j9C2upXw5ju3YP0jdR4Nfnrg5EHk9GJ0ICsNm0q4pduObUAjk8/ MOHeOKak4sYIzBA/l5LaJ7kEscxO6ZWGH+f5fSVfv+jzcyJCwm762q6PHv/VlMEVyc OgjAQcSvTMvhhFqAjHWFp8UpChcOMjZqeVr2lDkg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Belloni , Sasha Levin Subject: [PATCH 4.16 160/161] rtc: rp5c01: fix possible race condition Date: Thu, 24 May 2018 11:39:45 +0200 Message-Id: <20180524093037.431976454@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexandre Belloni [ Upstream commit bcdd559268039d8340d38fa58668393596e29fdc ] The probe function is not allowed to fail after registering the RTC because the following may happen: CPU0: CPU1: sys_load_module() do_init_module() do_one_initcall() cmos_do_probe() rtc_device_register() __register_chrdev() cdev->owner = struct module* open("/dev/rtc0") rtc_device_unregister() module_put() free_module() module_free(mod->module_core) /* struct module *module is now freed */ chrdev_open() spin_lock(cdev_lock) cdev_get() try_module_get() module_is_live() /* dereferences already freed struct module* */ Switch to devm_rtc_allocate_device/rtc_register_device to register the rtc as late as possible. Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-rp5c01.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) --- a/drivers/rtc/rtc-rp5c01.c +++ b/drivers/rtc/rtc-rp5c01.c @@ -249,16 +249,24 @@ static int __init rp5c01_rtc_probe(struc platform_set_drvdata(dev, priv); - rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops, - THIS_MODULE); + rtc = devm_rtc_allocate_device(&dev->dev); if (IS_ERR(rtc)) return PTR_ERR(rtc); + + rtc->ops = &rp5c01_rtc_ops; + priv->rtc = rtc; error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); if (error) return error; + error = rtc_register_device(rtc); + if (error) { + sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr); + return error; + } + return 0; }