From patchwork Sun Jul 26 21:48:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Zapolskiy X-Patchwork-Id: 500174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-la0-x237.google.com (mail-la0-x237.google.com [IPv6:2a00:1450:4010:c03::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 79A8A14032A for ; Mon, 27 Jul 2015 07:48:50 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=XfbXhyLW; dkim-atps=neutral Received: by laef2 with SMTP id f2sf29748156lae.1 for ; Sun, 26 Jul 2015 14:48:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :reply-to:content-type:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe; bh=oqkUHKxByzo0q28thr0pmboSExtfXdLpWO9+5azVDzs=; b=XfbXhyLWa2gW4/nrRgaQ6RabEbZkQxhkOtrikeioJvvQV01537SjkY/hLmW0emp1tw DGX6+1YLfc8Cr15/Ma3eYUt1vZ1uA+IAhZZb5SNWRQZJWLFL6uO47ayC09iMPdzVAfKR 0qgxLuoH3U6KntcPDs5fXBCKaDfewfY6SSa6b74vJMkwgwQJAkM6GfAVNC7/iNhwpxhM q4s2ApqgJJ97AV0Bta7aInJ8qJbz8CdGOSp+ZLiNzNyfnrLZRB1slhjHhCa1A7kH6fy5 S7Xvnbq9lqys2ayZZsWSZk7JoXstKaiF3CLNqpUPg5cpHAMSTIlmz6M37PrC4JgeQjBc OJyw== X-Received: by 10.153.4.37 with SMTP id cb5mr133489lad.7.1437947328100; Sun, 26 Jul 2015 14:48:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: rtc-linux@googlegroups.com Received: by 10.152.179.39 with SMTP id dd7ls601530lac.60.gmail; Sun, 26 Jul 2015 14:48:47 -0700 (PDT) X-Received: by 10.112.99.37 with SMTP id en5mr10745875lbb.7.1437947327569; Sun, 26 Jul 2015 14:48:47 -0700 (PDT) Received: from mail.mleia.com (li271-223.members.linode.com. [178.79.152.223]) by gmr-mx.google.com with ESMTPS id q10si280079wiz.0.2015.07.26.14.48.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jul 2015 14:48:47 -0700 (PDT) Received-SPF: neutral (google.com: 178.79.152.223 is neither permitted nor denied by best guess record for domain of vz@mleia.com) client-ip=178.79.152.223; Received: from mail.mleia.com (localhost [127.0.0.1]) by mail.mleia.com (Postfix) with ESMTP id 945E1101211; Sun, 26 Jul 2015 22:53:59 +0100 (BST) Received: from localhost.localdomain (a91-152-106-128.elisa-laajakaista.fi [91.152.106.128]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mleia.com (Postfix) with ESMTPSA id 12CBA101214; Sun, 26 Jul 2015 22:53:59 +0100 (BST) From: Vladimir Zapolskiy To: Alessandro Zummo , Alexandre Belloni Cc: rtc-linux@googlegroups.com, Greg Kroah-Hartman Subject: [rtc-linux] [PATCH 08/11] rtc: m48t59: clean up m48t59_nvram_read()/m48t59_nvram_write() Date: Mon, 27 Jul 2015 00:48:33 +0300 Message-Id: <1437947316-5652-9-git-send-email-vz@mleia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437947316-5652-1-git-send-email-vz@mleia.com> References: <1437947316-5652-1-git-send-email-vz@mleia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-49551924 X-CRM114-CacheID: sfid-20150726_225359_629113_E4268DDD X-CRM114-Status: GOOD ( 15.71 ) X-Original-Sender: vz@mleia.com X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 178.79.152.223 is neither permitted nor denied by best guess record for domain of vz@mleia.com) smtp.mail=vz@mleia.com Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: rtc-linux@googlegroups.com X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The change removes redundant sysfs binary file boundary checks, since this task is already done on caller side in fs/sysfs/file.c Spinlock acquisition/release is moved out of the loop body to get atomic states of NVRAM reading and writing operations. Signed-off-by: Vladimir Zapolskiy --- drivers/rtc/rtc-m48t59.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c index 90abb5b..512c44b 100644 --- a/drivers/rtc/rtc-m48t59.c +++ b/drivers/rtc/rtc-m48t59.c @@ -345,11 +345,12 @@ static ssize_t m48t59_nvram_read(struct file *filp, struct kobject *kobj, ssize_t cnt = 0; unsigned long flags; - for (; size > 0 && pos < pdata->offset; cnt++, size--) { - spin_lock_irqsave(&m48t59->lock, flags); + spin_lock_irqsave(&m48t59->lock, flags); + + for (; cnt < size; cnt++) *buf++ = M48T59_READ(cnt); - spin_unlock_irqrestore(&m48t59->lock, flags); - } + + spin_unlock_irqrestore(&m48t59->lock, flags); return cnt; } @@ -365,11 +366,10 @@ static ssize_t m48t59_nvram_write(struct file *filp, struct kobject *kobj, ssize_t cnt = 0; unsigned long flags; - for (; size > 0 && pos < pdata->offset; cnt++, size--) { - spin_lock_irqsave(&m48t59->lock, flags); + spin_lock_irqsave(&m48t59->lock, flags); + + for (; cnt < size; cnt++) M48T59_WRITE(*buf++, cnt); - spin_unlock_irqrestore(&m48t59->lock, flags); - } return cnt; }