Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1921890imm; Thu, 24 May 2018 02:59:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqHOo+uyz5FV5rN5vIWBzNrYIzdeTzY7YSzsDpln/f17Gd6YnDo0RoNK1ShAy5qr+Rq0M+r X-Received: by 2002:a62:d605:: with SMTP id r5-v6mr6627638pfg.8.1527155988548; Thu, 24 May 2018 02:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527155988; cv=none; d=google.com; s=arc-20160816; b=Vnq84rmiZMtVvErNTgO0CpLL4nXVES9TSwNmCHY+2SoZcP1g/xbbLrNA2jiiTlfBCQ wltJhTchwZgLIYt6VEXb6ghOEu6OPXjGK7/WVvJkmZkGiABh+L4R1wWkGUHm1G69hF8/ BXHPBrHtENgQsSBkCnzdxoIvSyhP+wQ9a7I4il95cX63E9p2Jcsq2TwDXGN1u36ZWhez V4M/SpIuiZ1JdITfNr4FdOm8tGjoXj6Zp51HNYf+ZkaQtO8Ub2PISY7eI5zfA8fU0Ufd Qc2rqTlC6GEDwU0zN7JVzvCsDDyitiW6Q08mZZrG4fxXdBuu5VjyTT04Rl+GLDDgGS+H bcwQ== 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=JCo0rLwRgHp2WQ2mNJZ/LEIPF1Fdo8ulbo3ms5h4kaA=; b=YA02BOYHc1joAmdGKxgjfWu2zP6LJujNfeUH5Ef1ULV86nTcNSggEybMp+NCiktE6o gbUZQKv16qntAnxohu8OqO+jkHhnKMPIGG9ejeB20rF65UFqm0M9R4qs/EYsQVYK2xps c3al2yr2BzEDYKA6x6tTYL1Tzkvee6k3dZSE4OX1In3YBGJ7rSdNq2DtYIglYZe1A2EY ZkAnselL38lGNTkSVMZ+BrLIV4P2IhD5Ofuy0KqDcvDTGNE6V6Z9tNpDlS50vlREhcuu ewCb2DjvA+SLEsYYsXetskWZBIilFL8IfT7BVnPMPQm0oc+TMWEkFWAB/Xacjg1unmG0 0Rqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ltg/2dQM; 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 r13-v6si16399906pgt.8.2018.05.24.02.59.34; Thu, 24 May 2018 02:59:48 -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=ltg/2dQM; 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 S1030657AbeEXJ6j (ORCPT + 99 others); Thu, 24 May 2018 05:58:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:38576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030612AbeEXJ6f (ORCPT ); Thu, 24 May 2018 05:58:35 -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 CAA4420870; Thu, 24 May 2018 09:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155915; bh=Hi3I1TGvw6iyAAnVTxaaKe7xVwvNpimbxAonh4fvj4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ltg/2dQMGtOfXUSz8LLHC/aBcExxaJ+NY9yoqmwCKeLhgbmPGz4AEhy4CpF/TlMte s5LAy6NhGFbTtS9POGFg4iAifZC5eU6ZrI3jWHk75ls0A1LixT3cuNgVL77vdXWkMo spbLlI6GkW5Hscf0MxMIYqGvA1HlW8/vcZ85Sb0s= 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 164/165] rtc: rp5c01: fix possible race condition Date: Thu, 24 May 2018 11:39:30 +0200 Message-Id: <20180524093628.715081091@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 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; }