Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1110270imm; Wed, 1 Aug 2018 10:20:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfJEzxwKJq/ukYiBeNjTif96tCeJm6MRorrc4wF6F9BXR4Tn+I0nWFc6gUF4YZ6B96eu1Kj X-Received: by 2002:a63:a619:: with SMTP id t25-v6mr24937937pge.288.1533144040985; Wed, 01 Aug 2018 10:20:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533144040; cv=none; d=google.com; s=arc-20160816; b=UuKpxvO3BXx+GUanFmaSBxQLzf8dwhy6HBZgZfnP9B/6o+p/BiNgpfIkh2ECevxkqe lbeMvO9SWGH/P9sI7mdaFcKz3703qs/i3PlsB4ZmXVabg+h3qPp6lvxVhWEg1HZRb8VR rDl9PcQAdaU68qNgppPOJpc+6Mmib+Zx5Njtb7/4sZl78PH7/g7yKLG2xBBG3Yq2TRnI P1QWrQWaVqmvgrgzwAr6FDOrOKBiVzFr6ws3YWwLOl3rk2Ia2WnbG2//6cb8m1NzUohH dwGT4+c/5VWut3z1hK+E17tK0Mie6Il+9IwZXnl6kdcoYYrtFiXsxknE2yfKIEUvEXwx qDjQ== 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 :arc-authentication-results; bh=wR7enrGK2mhcUVyfCM3em8ThpHbvy24vGX2i3yi/WIc=; b=JbKGiv13Zg3HaQdEs6lGtW6YF30+gsDkBCxxdAczvQnSrnr0vclG8MLR/vm9cxERw2 /HMwcb7HYqvvhUNe7AU3FU+9HEm7dDtXtzm0W+KiTQj/PFV7VDO8aIDYRN2vZsSdLrsQ 48Y1nmQp5o1fHiPNU74YIbTP+NRhOQ5AJ1RBeyqgd8jNzfTktuoxxsTzNp+gyZHP/2zU OfjtA4sYTKSp0QYDEd0JCgI0ICzSd0DRsfgFbJMrKMcB0cJ8N6PVOF+RosKb811MuYDL vvHRSmBoQX1iZAsy4bFB86triaOPMH4PBZboZ3f76vfrCefLgCJkalXPFo1UN7ZVlnFq z6Lg== 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 n10-v6si17532895pfb.316.2018.08.01.10.20.26; Wed, 01 Aug 2018 10:20:40 -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 S2404796AbeHATEb (ORCPT + 99 others); Wed, 1 Aug 2018 15:04:31 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46526 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404073AbeHATEb (ORCPT ); Wed, 1 Aug 2018 15:04:31 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A16DBC96; Wed, 1 Aug 2018 17:17:50 +0000 (UTC) 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.14 122/246] rtc: tps6586x: fix possible race condition Date: Wed, 1 Aug 2018 18:50:32 +0200 Message-Id: <20180801165017.557005824@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexandre Belloni [ Upstream commit 63d22063073b0ab46d1e06fe633fb5de8f5c58e1 ] The probe function is not allowed to fail after the RTC is registered 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* */ Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-tps6586x.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/drivers/rtc/rtc-tps6586x.c +++ b/drivers/rtc/rtc-tps6586x.c @@ -276,14 +276,15 @@ static int tps6586x_rtc_probe(struct pla device_init_wakeup(&pdev->dev, 1); platform_set_drvdata(pdev, rtc); - rtc->rtc = devm_rtc_device_register(&pdev->dev, dev_name(&pdev->dev), - &tps6586x_rtc_ops, THIS_MODULE); + rtc->rtc = devm_rtc_allocate_device(&pdev->dev); if (IS_ERR(rtc->rtc)) { ret = PTR_ERR(rtc->rtc); - dev_err(&pdev->dev, "RTC device register: ret %d\n", ret); + dev_err(&pdev->dev, "RTC allocate device: ret %d\n", ret); goto fail_rtc_register; } + rtc->rtc->ops = &tps6586x_rtc_ops; + ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, tps6586x_rtc_irq, IRQF_ONESHOT, @@ -294,6 +295,13 @@ static int tps6586x_rtc_probe(struct pla goto fail_rtc_register; } disable_irq(rtc->irq); + + ret = rtc_register_device(rtc->rtc); + if (ret) { + dev_err(&pdev->dev, "RTC device register: ret %d\n", ret); + goto fail_rtc_register; + } + return 0; fail_rtc_register: