2 * Copyright (c) 2011 Maxim Levitsky
4 * This file is part of linux cryptodev.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <crypto/scatterwalk.h>
23 #include <linux/scatterlist.h>
26 /* These were taken from Maxim Levitsky's patch to lkml.
28 struct scatterlist
*sg_advance(struct scatterlist
*sg
, int consumed
)
30 while (consumed
>= sg
->length
) {
31 consumed
-= sg
->length
;
38 WARN_ON(!sg
&& consumed
);
43 sg
->offset
+= consumed
;
44 sg
->length
-= consumed
;
46 if (sg
->offset
>= PAGE_SIZE
) {
48 nth_page(sg_page(sg
), sg
->offset
/ PAGE_SIZE
);
49 sg_set_page(sg
, page
, sg
->length
, sg
->offset
% PAGE_SIZE
);
56 * sg_copy - copies sg entries from sg_from to sg_to, such
57 * as sg_to covers first 'len' bytes from sg_from.
59 int sg_copy(struct scatterlist
*sg_from
, struct scatterlist
*sg_to
, int len
)
61 while (len
> sg_from
->length
) {
62 len
-= sg_from
->length
;
64 sg_set_page(sg_to
, sg_page(sg_from
),
65 sg_from
->length
, sg_from
->offset
);
67 sg_to
= sg_next(sg_to
);
68 sg_from
= sg_next(sg_from
);
70 if (len
&& (!sg_from
|| !sg_to
))
75 sg_set_page(sg_to
, sg_page(sg_from
),
76 len
, sg_from
->offset
);