mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@armlinux.org.uk>
To: Geliang Tang <geliangtang@gmail.com>
Cc: Joerg Roedel <jroedel@suse.de>,
	Robin Murphy <Robin.Murphy@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm/dma-mapping: use for_each_sg
Date: Fri, 24 Mar 2017 14:48:39 +0000	[thread overview]
Message-ID: <20170324144838.GH7909@n2100.armlinux.org.uk> (raw)
In-Reply-To: <e9923f7ea2c0fd866efb48be52ffe91d25dd0290.1490326970.git.geliangtang@gmail.com>

On Fri, Mar 24, 2017 at 10:12:23PM +0800, Geliang Tang wrote:
> Use for_each_sg() instead of open-coding it.
> 
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>

No.

> diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> index 63eabb0..e551351 100644
> --- a/arch/arm/mm/dma-mapping.c
> +++ b/arch/arm/mm/dma-mapping.c
> @@ -1720,7 +1720,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
>  	if (iova == DMA_ERROR_CODE)
>  		return -ENOMEM;
>  
> -	for (count = 0, s = sg; count < (size >> PAGE_SHIFT); s = sg_next(s)) {
> +	for_each_sg(sg, s, size >> PAGE_SHIFT, count) {

This is _not_ equivalent.

#define for_each_sg(sglist, sg, nr, __i)        \
        for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next(sg))

Putting the arguments into that gives:

        for (count = 0, s = sg; count < (size >> PAGE_SHIFT); count++, s = sg_next(s))

whereas the old code is:

	for (count = 0, s = sg; count < (size >> PAGE_SHIFT); s = sg_next(s))

Spot the difference?  "count++".

This is because "size >> PAGE_SHIFT" is not the number of scatterlist
entries, it's the number of pages to map.

Please be more careful in the future to ensure that, when cleaning up
code, that the code is indeed equivalent.  Subtle errors like this are
sometimes incredibly difficult to spot.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

      parent reply	other threads:[~2017-03-24 14:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-24 14:12 Geliang Tang
2017-03-24 14:12 ` [PATCH] [media] ivtv: " Geliang Tang
2017-03-24 14:48 ` Russell King - ARM Linux [this message]

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=20170324144838.GH7909@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=Robin.Murphy@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=geliangtang@gmail.com \
    --cc=jroedel@suse.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=will.deacon@arm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®