From patchwork Tue Jun 7 16:47:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 69555 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2074824qgf; Tue, 7 Jun 2016 09:48:50 -0700 (PDT) X-Received: by 10.98.30.133 with SMTP id e127mr369303pfe.112.1465318130183; Tue, 07 Jun 2016 09:48:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fj5si33886322pad.96.2016.06.07.09.48.44; Tue, 07 Jun 2016 09:48:50 -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=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422712AbcFGQsB (ORCPT + 31 others); Tue, 7 Jun 2016 12:48:01 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:34775 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161848AbcFGQr7 (ORCPT ); Tue, 7 Jun 2016 12:47:59 -0400 Received: by mail-pa0-f47.google.com with SMTP id bz2so47560828pad.1 for ; Tue, 07 Jun 2016 09:47:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6QpFn2uQoGHtzeMFinR6scJkIhnehU3fIXaXUjzAMWY=; b=GTNaSCdYLZEtwZSmuDSCWcEsweuzD+fbOwZeMgBPhSEx9AABVhPHi5YqQywQ6s6jyI ZY88OFuX/chpSEANe3uBNwTqupAt0APVYrytt8vISoPbcnWUMWJuovPxqCQaUGSa6N0F j+cOTDLE15KJ2vIT8NlTwm83UmHV6r/SSUvlU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6QpFn2uQoGHtzeMFinR6scJkIhnehU3fIXaXUjzAMWY=; b=LPHKS4h3cUAXNuxIusmEiHVUT7JfHElsHSUvUeBA48oNsSZn2zadADyASQvQQod75N th+tfZdlDMX+iMtTYTzVnJlph388fPk7ats5tye5HIb1Ah8OLU57iAWrr00WMsPExxaz jToV2SE6CGvIXoMaIdOjBFdvReTs4BJf5PiQV36wOC95uvG91YTySNVpPrzAbkiOH7+H 8mkeAbhVELvULLIm80pb9PCEZvdq/7LgEdiEU4Dad75z7u8ml55u+K3I1FxHTNt08xJm qMvBYinPHaoGvp4UrNruwq8gBKspR+8D44EuRqYJbjq2ORyzlrpJb7oVnD6c/9HMYDsz 6+yQ== X-Gm-Message-State: ALyK8tI9FvLuaX2+J7WkF7wpHEkg/O34N5V8qaYCOkKiknFBHPdt+mekFLRF9GScbIV/djRb X-Received: by 10.66.132.103 with SMTP id ot7mr394919pab.60.1465318078023; Tue, 07 Jun 2016 09:47:58 -0700 (PDT) Received: from localhost.localdomain (ip68-101-172-78.sd.sd.cox.net. [68.101.172.78]) by smtp.gmail.com with ESMTPSA id fd8sm34342567pac.23.2016.06.07.09.47.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Jun 2016 09:47:57 -0700 (PDT) From: Stephen Boyd To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Mimi Zohar , Andrew Morton , Mark Brown , Ming Lei , Vikram Mulukutla Subject: [RESEND/PATCHv4 v4 1/3] firmware: Consolidate kmap/read/write logic Date: Tue, 7 Jun 2016 09:47:39 -0700 Message-Id: <20160607164741.31849-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.9.0-rc1 In-Reply-To: <20160607164741.31849-1-stephen.boyd@linaro.org> References: <20160607164741.31849-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We use similar structured code to read and write the kmapped firmware pages. The only difference is read copies from the kmap region and write copies to it. Consolidate this into one function to reduce duplication. Cc: Vikram Mulukutla Signed-off-by: Stephen Boyd --- drivers/base/firmware_class.c | 57 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 31 deletions(-) -- 2.9.0-rc1 diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 773fc3099769..01d55723d82c 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -691,6 +691,29 @@ out: static DEVICE_ATTR(loading, 0644, firmware_loading_show, firmware_loading_store); +static void firmware_rw(struct firmware_buf *buf, char *buffer, + loff_t offset, size_t count, bool read) +{ + while (count) { + void *page_data; + int page_nr = offset >> PAGE_SHIFT; + int page_ofs = offset & (PAGE_SIZE-1); + int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count); + + page_data = kmap(buf->pages[page_nr]); + + if (read) + memcpy(buffer, page_data + page_ofs, page_cnt); + else + memcpy(page_data + page_ofs, buffer, page_cnt); + + kunmap(buf->pages[page_nr]); + buffer += page_cnt; + offset += page_cnt; + count -= page_cnt; + } +} + static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj, struct bin_attribute *bin_attr, char *buffer, loff_t offset, size_t count) @@ -715,21 +738,8 @@ static ssize_t firmware_data_read(struct file *filp, struct kobject *kobj, ret_count = count; - while (count) { - void *page_data; - int page_nr = offset >> PAGE_SHIFT; - int page_ofs = offset & (PAGE_SIZE-1); - int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count); - - page_data = kmap(buf->pages[page_nr]); - - memcpy(buffer, page_data + page_ofs, page_cnt); + firmware_rw(buf, buffer, offset, count, true); - kunmap(buf->pages[page_nr]); - buffer += page_cnt; - offset += page_cnt; - count -= page_cnt; - } out: mutex_unlock(&fw_lock); return ret_count; @@ -809,24 +819,9 @@ static ssize_t firmware_data_write(struct file *filp, struct kobject *kobj, goto out; retval = count; + firmware_rw(buf, buffer, offset, count, false); - while (count) { - void *page_data; - int page_nr = offset >> PAGE_SHIFT; - int page_ofs = offset & (PAGE_SIZE - 1); - int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count); - - page_data = kmap(buf->pages[page_nr]); - - memcpy(page_data + page_ofs, buffer, page_cnt); - - kunmap(buf->pages[page_nr]); - buffer += page_cnt; - offset += page_cnt; - count -= page_cnt; - } - - buf->size = max_t(size_t, offset, buf->size); + buf->size = max_t(size_t, offset + count, buf->size); out: mutex_unlock(&fw_lock); return retval;