Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1965519imm; Thu, 24 May 2018 03:43:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpwgbSCpsHbn2kCq2RgOYQM9L1tybyxJtggcIrxMSEO8uLoKBHc4qcQBDr8qmt2k25ioN5O X-Received: by 2002:a65:5bcc:: with SMTP id o12-v6mr5403079pgr.449.1527158581596; Thu, 24 May 2018 03:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158581; cv=none; d=google.com; s=arc-20160816; b=uwCKuh9Z6YGiSDQUjouaAFyr4utWsKrtm6flKXBcwhJjVQnnl3fepDWT0Yk1Efw84o AODelioPkEAWufMfz8qcXlsAycbAK+FooccEAsoJl/TuKux/zAmUIqWz+0h7fJfBc69V 2u7lb11EyJ+sk35mPgSo2hHlP82jRfOaqm9d8DvHb///bbshn/267OvJTJAHb9yV8lCS tHpfhRKULnT8EsbvHBS5BRLTMUJzpqFWOOnlamsqdAMXccRBZmDnJcwF4uPrUBNU/mCx 0DUID1PplMqbIXUda0uETOQJ2DKVP8P1WjBv0GbiivXV0iyF78Bwss3q7GZajBaVCUEh 5EfA== 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=RXdlK55z/YpvHNIC1VAfFqByY2tjb65mPt/jYQxpHL4=; b=SmYPnFRgYGY61ROvf0A2QYJrEt+RHNIi+J62IdF94K5eAS4Go0A5jeLIhWN4pfXCia jEF2j4AQzUS6PVElakyNclW4gAr/6I1oAbrC1kWQ3J/zYg68cmIMVBb43KbuvF46etyv C7oZG5QjlT2iuK8pVGcXXYXdZ0GViFJ+BN8MhACDjDdj6fv7MC6Z5UGEOGBzU8LS8A/a cQ0kv3q81jrS1IMb77f+3CQ0q/zjiM5rAFxiNzFb7+Up6T5Kcqys2yF+5D3Rj5hqK0yx /IRz6aeBVbdnXsr73noN5106gz95bsL5tO9opmx8wDrrnoDGZ5ZGYw6dirK8yZjZ+5sp Nkiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RaQQgiH/; 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 u23-v6si22034129plk.487.2018.05.24.03.42.47; Thu, 24 May 2018 03:43:01 -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=RaQQgiH/; 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 S1030641AbeEXJ6f (ORCPT + 99 others); Thu, 24 May 2018 05:58:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:38324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030612AbeEXJ61 (ORCPT ); Thu, 24 May 2018 05:58:27 -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 4C80120890; Thu, 24 May 2018 09:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155906; bh=/MsYtIbQk7vIlsLypgoOWHpO2yChOjbxd9ojRl5fEKc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RaQQgiH/ItZEGge/C7Gzwt7NAhtXUM9EcJdRysmUo1sit3ysvW9gE1hay6GxO/awh T2Eta+Y0QY6GRTdOdp0LesFWoHEGUrRz/hqncM7aSOn1SU/TyImpk+ATNgETA+72bI /XmjCP6IudzUo+bR0Kdezy/XZPrflca0mgNbt6MU= 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 161/165] rtc: rk808: fix possible race condition Date: Thu, 24 May 2018 11:39:27 +0200 Message-Id: <20180524093628.599295043@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093621.979359379@linuxfoundation.org> References: <20180524093621.979359379@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 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 = {