From patchwork Tue Feb 28 16:45:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatolij Gustschin X-Patchwork-Id: 143502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-we0-f184.google.com (mail-we0-f184.google.com [74.125.82.184]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 8EDBDB6FA2 for ; Wed, 29 Feb 2012 03:45:29 +1100 (EST) Received: by werm1 with SMTP id m1sf1223977wer.11 for ; Tue, 28 Feb 2012 08:45:26 -0800 (PST) Received-SPF: pass (google.com: domain of rtc-linux+bncCAAQpIm0-gQaBLifVXM@googlegroups.com designates 10.180.99.65 as permitted sender) client-ip=10.180.99.65; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rtc-linux+bncCAAQpIm0-gQaBLifVXM@googlegroups.com designates 10.180.99.65 as permitted sender) smtp.mail=rtc-linux+bncCAAQpIm0-gQaBLifVXM@googlegroups.com; dkim=pass header.i=rtc-linux+bncCAAQpIm0-gQaBLifVXM@googlegroups.com Received: from mr.google.com ([10.180.99.65]) by 10.180.99.65 with SMTP id eo1mr6415225wib.0.1330447526250 (num_hops = 1); Tue, 28 Feb 2012 08:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=mime-version:x-beenthere:received-spf:x-auth-info:from:to:cc :subject:date:message-id:x-mailer:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=BEvDEq2lFgXJiLiQhJLaaCV6cNrOoAMWPrfgHRRB7EA=; b=ke1VHj3AwLJS4zgQk3F3R3raI4+X2UXBae3zL7KJty4eG6HDB3os6Z3n2kq+W4OvXD r8ElJ6I1D7lEP9XZtNwOGZ/lkzGD3CaA69cGkmjdCp+39wyKiNfsSccjIYSwOv1R1K19 7uPO32UBzpj/SsO/9bXNnb/30xC1hI/mNVv48= Received: by 10.180.99.65 with SMTP id eo1mr1803952wib.0.1330447524900; Tue, 28 Feb 2012 08:45:24 -0800 (PST) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.14.96.203 with SMTP id r51ls3405527eef.3.gmail; Tue, 28 Feb 2012 08:45:24 -0800 (PST) Received: by 10.213.20.140 with SMTP id f12mr2533199ebb.6.1330447524211; Tue, 28 Feb 2012 08:45:24 -0800 (PST) Received: by 10.213.20.140 with SMTP id f12mr2533197ebb.6.1330447524194; Tue, 28 Feb 2012 08:45:24 -0800 (PST) Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id f9si13965467eea.2.2012.02.28.08.45.24 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 28 Feb 2012 08:45:24 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of agust@denx.de) client-ip=212.18.0.9; Received: from frontend1.mail.m-online.net (unknown [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3Ty5PG6ylPz4Kh16; Tue, 28 Feb 2012 17:45:22 +0100 (CET) X-Auth-Info: 9hOj2CdmvWd0O5b/4AWq714eR6hIZWriZGRTaCaLP6c= Received: from localhost (p4FDE6F88.dip.t-dialin.net [79.222.111.136]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA id 3Ty5PG5LHRz4KKC4; Tue, 28 Feb 2012 17:45:22 +0100 (CET) From: Anatolij Gustschin To: rtc-linux@googlegroups.com Cc: Alessandro Zummo Subject: [rtc-linux] [PATCH] rtc: r9701: fix crash in r9701_remove() Date: Tue, 28 Feb 2012 17:45:22 +0100 Message-Id: <1330447522-7076-1-git-send-email-agust@denx.de> X-Mailer: git-send-email 1.7.1 X-Original-Sender: agust@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of agust@denx.de) smtp.mail=agust@denx.de Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: Sender: rtc-linux@googlegroups.com List-Subscribe: , List-Unsubscribe: , If probing the RTC didn't succeed due to failed RTC register access, the RTC device will be unregistered. Then, when removing the module r9701_remove() causes kernel crash while trying to unregister not registered RTC device. Fix this by doing RTC register access test before RTC device registration. Signed-off-by: Anatolij Gustschin Cc: Alessandro Zummo --- drivers/rtc/rtc-r9701.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c index 931f95c..7f8e6c2 100644 --- a/drivers/rtc/rtc-r9701.c +++ b/drivers/rtc/rtc-r9701.c @@ -125,6 +125,13 @@ static int __devinit r9701_probe(struct spi_device *spi) unsigned char tmp; int res; + tmp = R100CNT; + res = read_regs(&spi->dev, &tmp, 1); + if (res || tmp != 0x20) { + dev_err(&spi->dev, "cannot read RTC register\n"); + return -ENODEV; + } + rtc = rtc_device_register("r9701", &spi->dev, &r9701_rtc_ops, THIS_MODULE); if (IS_ERR(rtc)) @@ -132,13 +139,6 @@ static int __devinit r9701_probe(struct spi_device *spi) dev_set_drvdata(&spi->dev, rtc); - tmp = R100CNT; - res = read_regs(&spi->dev, &tmp, 1); - if (res || tmp != 0x20) { - rtc_device_unregister(rtc); - return res; - } - return 0; }