Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1416591

Re: [RESEND/PATCHv4 v4 1/3] firmware: Consolidate kmap/read/write logic

From Andrew Morton <akpm@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: [RESEND/PATCHv4 v4 1/3] firmware: Consolidate kmap/read/write logic
Date 2016-06-07 22:30 +0200
Message-ID <rHvNo-7ix-17@gated-at.bofh.it> (permalink)
References <rHsmu-56I-27@gated-at.bofh.it> <rHsmu-56I-45@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue,  7 Jun 2016 09:47:39 -0700 Stephen Boyd <stephen.boyd@linaro.org> wrote:

> 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.
> 
> ...
>
> --- 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]);

fwiw, we could switch the code to kmap_atomic() here.  It is faster.

> +		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;
> +	}
> +}

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[RESEND/PATCHv4 v4 0/3] request_firmware() into pre-allocated buffers Stephen Boyd <stephen.boyd@linaro.org> - 2016-06-07 18:50 +0200
  [RESEND/PATCHv4 v4 2/3] firmware: Provide infrastructure to make fw caching optional Stephen Boyd <stephen.boyd@linaro.org> - 2016-06-07 18:50 +0200
  [RESEND/PATCHv4 v4 3/3] firmware: Support loading into a pre-allocated buffer Stephen Boyd <stephen.boyd@linaro.org> - 2016-06-07 18:50 +0200
  [RESEND/PATCHv4 v4 1/3] firmware: Consolidate kmap/read/write logic Stephen Boyd <stephen.boyd@linaro.org> - 2016-06-07 18:50 +0200
    Re: [RESEND/PATCHv4 v4 1/3] firmware: Consolidate kmap/read/write  logic Andrew Morton <akpm@linux-foundation.org> - 2016-06-07 22:30 +0200

csiph-web