Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1934796imm; Thu, 24 May 2018 03:11:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo75lPwgquDjXJeYW9N7Eq/PlT0DuROKqHz8Zp7X4LZ8nQbpiUi8G2z89cPSEdm1UBVmz0G X-Received: by 2002:a17:902:b60b:: with SMTP id b11-v6mr6802805pls.330.1527156698244; Thu, 24 May 2018 03:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527156698; cv=none; d=google.com; s=arc-20160816; b=E0lU5PaYrlUPzHNUzR7XOOUGHuyaab0wDOc9E7hdIIuJx6uRisXIDJng+d5VhLJt7e Aym+JvdR2n9UpXtou7e5r8s/pUPime5vdaqiVnKvFGoepe3C2Ui4SXDYAYYFSF4TqNXv /kFbno/QczMff4gd9PCOit+MgkrtAtx6o/CC3Cqd+1062xh0/XPe5kQ3QMGunLhi7fuO lMn8FveCfednVXfviLcJqUSyjNFCn0ziMx1ibqM1vTRuDKCJ88Bf4HMtwLXR3lqvIesW 3Es3hrgAlEGtRmgfrT24ScNNttNbbKqU4Bb+O+DPv4Mca5JbfZIc/VTbPtbnr45vNozj PGcw== 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=RL4D6LLXsF0e7ICbSRkNxPzuxzKbVEA+ljofZbYtZzQ=; b=Yfp/9jH+NnZDZ7cNwOl+LItAtAMcXuTEgZcPiDqmlZxWLjzSPJX9wGdmNXyaowgzEP HtMM19OF8ltr52/x8Z2Jd3KmuSx6xVZ4yAaoS60h8m/h7iIUm1DK5RJvJOSupfv5ocm1 Ff0kzzyOzDphENXr3+IVcuQzA83xfm1gEVwCh0DrMTs07E4n9jv7iIPgE0HVF7qWcDRU Khn2QyTN2pF6sd9uUWAEcp0G0shhNcmNMrgwCj+E7iPEappSkVi5LcZYQPUsbGPAnafG KZD2C3CijEC+UHz65g3dG5qyK9Q0oNXF7U8gUwvLlNQB72isLl2uc+Hi6ym4I9kkAeMg ybMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mGEOPlhp; 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 j15-v6si329749pga.252.2018.05.24.03.11.23; Thu, 24 May 2018 03:11:38 -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=mGEOPlhp; 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 S1031797AbeEXKJV (ORCPT + 99 others); Thu, 24 May 2018 06:09:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:54988 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031645AbeEXKF4 (ORCPT ); Thu, 24 May 2018 06:05:56 -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 BB8B620897; Thu, 24 May 2018 10:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527156356; bh=gxIqPn0xifsqlowpDSETFBjOxBVUgKITjpuPnovisvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mGEOPlhpMwcR+BNRZYMjsWGLSaSDTq0qvvSHVueEqNsuxPqY4lErUY66O2AB/qtFp tEvrrTv1JPnGUaYruv4cJRWxhem60kpeF4BLsvKADA7QGetpTCnANDJU2UKZrbLDl5 gw9fIJqvkkqg0rXhOBMHQyxPI9Ziu7/4Z86mlC5g= 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 157/161] rtc: rk808: fix possible race condition Date: Thu, 24 May 2018 11:39:42 +0200 Message-Id: <20180524093037.019031273@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 201fac95e799c3d0304ec724d555e1251b9f6e84 ] 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-rk808.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/drivers/rtc/rtc-rk808.c +++ b/drivers/rtc/rtc-rk808.c @@ -416,12 +416,11 @@ static int rk808_rtc_probe(struct platfo device_init_wakeup(&pdev->dev, 1); - rk808_rtc->rtc = devm_rtc_device_register(&pdev->dev, "rk808-rtc", - &rk808_rtc_ops, THIS_MODULE); - if (IS_ERR(rk808_rtc->rtc)) { - ret = PTR_ERR(rk808_rtc->rtc); - return ret; - } + rk808_rtc->rtc = devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(rk808_rtc->rtc)) + return PTR_ERR(rk808_rtc->rtc); + + rk808_rtc->rtc->ops = &rk808_rtc_ops; rk808_rtc->irq = platform_get_irq(pdev, 0); if (rk808_rtc->irq < 0) { @@ -438,9 +437,10 @@ static int rk808_rtc_probe(struct platfo if (ret) { dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n", rk808_rtc->irq, ret); + return ret; } - return ret; + return rtc_register_device(rk808_rtc->rtc); } static struct platform_driver rk808_rtc_driver = {