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


Groups > linux.kernel > #1228285

Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained

From Tony Battersby <tonyb@cybernetics.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained
Date 2015-09-18 23:30 +0200
Message-ID <qaboe-67e-17@gated-at.bofh.it> (permalink)
References <qa3qG-33F-7@gated-at.bofh.it> <qa3qH-33F-29@gated-at.bofh.it> <qa6ye-7HP-29@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 09/18/2015 12:19 PM, Tony Battersby wrote:
> But why do drivers even need this at all?  Here is a typical usage:
>
> int qce_mapsg(struct device *dev, struct scatterlist *sg, int nents,
>           enum dma_data_direction dir, bool chained)
> {
>     int err;
>
>     if (chained) {
>         while (sg) {
>             err = dma_map_sg(dev, sg, 1, dir);
>             if (!err)
>                 return -EFAULT;
>             sg = sg_next(sg);
>         }
>     } else {
>         err = dma_map_sg(dev, sg, nents, dir);
>         if (!err)
>             return -EFAULT;
>     }
>
>     return nents;
> }
>
> Here is another:
>
> static int talitos_map_sg(struct device *dev, struct scatterlist *sg,
>               unsigned int nents, enum dma_data_direction dir,
>               bool chained)
> {
>     if (unlikely(chained))
>         while (sg) {
>             dma_map_sg(dev, sg, 1, dir);
>             sg = sg_next(sg);
>         }
>     else
>         dma_map_sg(dev, sg, nents, dir);
>     return nents;
> }
>
> Can anyone clarify why you can't just use dma_map_sg(dev, sg, nents,
> dir) always?  It should be able to handle chained scatterlists just fine.

After further investigation, it looks like this was a remnant of
scatterwalk_sg_next() which was removed by commit 5be4d4c94b1f ("crypto:
replace scatterwalk_sg_next with sg_next").  Apparently crypto
scatterlists used to be chained differently than normal scatterlists, so
functions like dma_map_sg() would not work on a chained crypto
scatterlist, but that is no longer the case.

So instead of adding a new function sg_nents_len_chained(), a better
cleanup would be:
1) replace the driver-specific functions with calls to sg_nents_for_len()
2) get rid of the "chained" variables
3) always call dma_map_sg()/dma_unmap_sg() for the entire scatterlist
regardless of whether or not the scatterlist is chained

Would someone more familiar with the crypto API please confirm that my
suggestions are correct?

Tony Battersby
Cybernetics

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

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


Thread

[PATCH v2] crypto: Remove duplicate code of SG helpers functions LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-09-18 15:00 +0200
  [PATCH v2 4/8] s390: replace zfcp_qdio_sbale_count by sg_nents LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-09-18 15:00 +0200
  [PATCH v2 5/8] lib: introduce sg_nents_len_chained LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-09-18 15:00 +0200
    Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained Tony Battersby <tonyb@cybernetics.com> - 2015-09-18 18:20 +0200
      Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained Tony Battersby <tonyb@cybernetics.com> - 2015-09-18 23:30 +0200
        Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained Herbert Xu <herbert@gondor.apana.org.au> - 2015-09-21 16:30 +0200
          Re: [PATCH v2 5/8] lib: introduce sg_nents_len_chained LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-09-21 17:10 +0200
  [PATCH v2 3/8] crypto: sahara: replace sahara_sg_length with sg_nents_for_len LABBE Corentin <clabbe.montjoie@gmail.com> - 2015-09-18 15:00 +0200
  Re: [PATCH v2] crypto: Remove duplicate code of SG helpers functions Herbert Xu <herbert@gondor.apana.org.au> - 2015-09-21 17:10 +0200

csiph-web