From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757058AbdJLWEv (ORCPT ); Thu, 12 Oct 2017 18:04:51 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:52702 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756214AbdJLWEu (ORCPT ); Thu, 12 Oct 2017 18:04:50 -0400 From: Alexandre Belloni To: linux-rtc@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Alexandre Belloni Subject: [PATCH 2/2] rtc: abx80x: solve race condition Date: Fri, 13 Oct 2017 00:04:47 +0200 Message-Id: <20171012220447.7940-2-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171012220447.7940-1-alexandre.belloni@free-electrons.com> References: <20171012220447.7940-1-alexandre.belloni@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is a race condition that can happen if abx80x_probe() fails after the rtc registration succeeded. Solve that by moving the registration at the end of the probe function. Signed-off-by: Alexandre Belloni --- drivers/rtc/rtc-abx80x.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/rtc/rtc-abx80x.c b/drivers/rtc/rtc-abx80x.c index 442e62a3c9a9..b033bc556f5d 100644 --- a/drivers/rtc/rtc-abx80x.c +++ b/drivers/rtc/rtc-abx80x.c @@ -620,10 +620,6 @@ static int abx80x_probe(struct i2c_client *client, rtc->ops = &abx80x_rtc_ops; - err = rtc_register_device(rtc); - if (err) - return err; - i2c_set_clientdata(client, rtc); if (client->irq > 0) { @@ -650,10 +646,14 @@ static int abx80x_probe(struct i2c_client *client, err = devm_add_action_or_reset(&client->dev, rtc_calib_remove_sysfs_group, &client->dev); - if (err) + if (err) { dev_err(&client->dev, "Failed to add sysfs cleanup action: %d\n", err); + return err; + } + + err = rtc_register_device(rtc); return err; } -- 2.14.2