All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Alex Dubov <oakad@yahoo.com>, Takashi Iwai <tiwai@suse.de>
Subject: Re: [PATCH 1/2] memstick: add support for legacy memorysticks
Date: Thu, 9 Dec 2010 13:09:36 -0800	[thread overview]
Message-ID: <20101209130936.5c62ac10.akpm@linux-foundation.org> (raw)
In-Reply-To: <1291862546-10064-1-git-send-email-maximlevitsky@gmail.com>

On Thu,  9 Dec 2010 04:42:25 +0200
Maxim Levitsky <maximlevitsky@gmail.com> wrote:

> +/*
> + * Advance scatterlist by 'consumed' bytes
> + * Returns new scatterlist, or NULL if can't advance that much
> + */
> +static struct scatterlist *sg_advance(struct scatterlist *sg, int consumed)
> +{
> +	while (consumed >= sg->length) {
> +		consumed -= sg->length;
> +
> +		sg = sg_next(sg);
> +		if (!sg)
> +			break;
> +	}
> +
> +	WARN_ON(!sg && consumed);
> +
> +	if (!sg)
> +		return NULL;
> +
> +	sg->offset += consumed;
> +	sg->length -= consumed;
> +
> +	if (sg->offset >= PAGE_SIZE) {
> +		struct page *page =
> +			nth_page(sg_page(sg), sg->offset / PAGE_SIZE);
> +		sg_set_page(sg, page, sg->length, sg->offset % PAGE_SIZE);
> +	}
> +
> +	return sg;
> +}
> +
> +/* Calculate number of sg entries in sg list */
> +static int sg_nents(struct scatterlist *sg)
> +{
> +	int nents = 0;
> +	while (sg) {
> +		nents++;
> +		sg = sg_next(sg);
> +	}
> +
> +	return nents;
> +}
> +
> +/* Calculate total lenght of scatterlist */

(typo)

> +static int sg_total_len(struct scatterlist *sg)
> +{
> +	int len = 0;
> +	while (sg) {
> +		len += sg->length;
> +		sg = sg_next(sg);
> +	}
> +	return len;
> +}
> +
> +/* Compare contents of an sg to a buffer */
> +static bool sg_compare_to_buffer(struct scatterlist *sg, u8 *buffer, size_t len)
> +{
> +	unsigned long flags;
> +	int retval = 0;
> +	struct sg_mapping_iter miter;
> +
> +	if (sg_total_len(sg) < len)
> +		return 1;
> +
> +	local_irq_save(flags);
> +	sg_miter_start(&miter, sg, sg_nents(sg),
> +				SG_MITER_ATOMIC | SG_MITER_FROM_SG);
> +
> +	while (sg_miter_next(&miter) && len > 0) {
> +
> +		int cmplen = min(miter.length, len);
> +		if (memcmp(miter.addr, buffer, cmplen)) {
> +			retval = 1;
> +			break;
> +		}
> +
> +		buffer += cmplen;
> +		len -= cmplen;
> +	}
> +
> +	sg_miter_stop(&miter);
> +	local_irq_restore(flags);
> +	return retval;
> +}

I think I mentioned this before, but ...  it's really bad that the
above functions appear in a particular device driver.  They are, to
varying degrees, independent of that driver and should be provided by
the sglist core code.

Also, the local_irq_save/restore in sg_compare_to_buffer() is quite
mysterious and should have a comment explaining why it is there.  Once
that's done, I might understand why it isn't a bug on SMP machines ;)


  parent reply	other threads:[~2010-12-09 21:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-09  2:39 MEMSTICK: Add my 2 drivers Maxim Levitsky
2010-12-09  2:42 ` [PATCH 1/2] memstick: add support for legacy memorysticks Maxim Levitsky
2010-12-09  7:19   ` Takashi Iwai
2010-12-09 11:56     ` Takashi Iwai
2010-12-09 15:44       ` Takashi Iwai
2010-12-10 22:34         ` Maxim Levitsky
2010-12-09 21:09   ` Andrew Morton [this message]
2010-12-10 22:27     ` Maxim Levitsky
2010-12-09  2:42 ` [PATCH 2/2] memstick: Add driver for Ricoh R5C592 card reader Maxim Levitsky
2010-12-09  2:44 ` MEMSTICK: Add my 2 drivers Alex Dubov
2010-12-09  2:48   ` Maxim Levitsky
2010-12-09  7:15   ` Takashi Iwai
2010-12-10 22:23     ` Maxim Levitsky
     [not found] <s5hsjy4bqxi.wl%tiwai@suse.de>
2010-12-12  4:13 ` [PATCH 1/2] memstick: add support for legacy memorysticks Alex Dubov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101209130936.5c62ac10.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maximlevitsky@gmail.com \
    --cc=oakad@yahoo.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.