The patch titled

     Use sg_init_one where appropriate

has been added to the -mm tree.  Its filename is

     use-sg_init_one-where-appropriate.patch

Patches currently in -mm which might be from [EMAIL PROTECTED] are

use-sg_init_one-where-appropriate.patch



From: David Hardeman <[EMAIL PROTECTED]>

This patch uses sg_init_one in some places where it was duplicated.

(akpm: fixed up a bunch of rejects against crypto/tcrypt.c, added more
conversions to crypto/tcrypt.c.  Please check).

Signed-off-by: David Hardeman <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Cc: James Bottomley <[EMAIL PROTECTED]>
Cc: Greg KH <[EMAIL PROTECTED]>
Cc: "David S. Miller" <[EMAIL PROTECTED]>
Cc: Jeff Garzik <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
---

 crypto/hmac.c                         |   23 ++++++-----------------
 crypto/tcrypt.c                       |   34 ++++++++++------------------------
 drivers/md/dm-crypt.c                 |   11 ++++-------
 drivers/net/wireless/airo.c           |    5 ++---
 drivers/scsi/arm/scsi.h               |    6 ++----
 drivers/scsi/libata-core.c            |   10 ++--------
 drivers/scsi/sg.c                     |    5 ++---
 drivers/usb/misc/usbtest.c            |    6 ++----
 include/linux/scatterlist.h           |    3 ++-
 net/ipv6/addrconf.c                   |    9 +++------
 net/sunrpc/auth_gss/gss_krb5_crypto.c |   22 ++++++----------------
 11 files changed, 41 insertions(+), 93 deletions(-)

diff -puN crypto/hmac.c~use-sg_init_one-where-appropriate crypto/hmac.c
--- 25/crypto/hmac.c~use-sg_init_one-where-appropriate  Mon Aug 29 16:19:54 2005
+++ 25-akpm/crypto/hmac.c       Mon Aug 29 16:19:54 2005
@@ -19,17 +19,15 @@
 #include <linux/highmem.h>
 #include <linux/slab.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include "internal.h"
 
 static void hash_key(struct crypto_tfm *tfm, u8 *key, unsigned int keylen)
 {
        struct scatterlist tmp;
-       
-       tmp.page = virt_to_page(key);
-       tmp.offset = offset_in_page(key);
-       tmp.length = keylen;
+
+       sg_init_one(tmp, key, keylen);
        crypto_digest_digest(tfm, &tmp, 1, key);
-               
 }
 
 int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
@@ -69,10 +67,7 @@ void crypto_hmac_init(struct crypto_tfm 
        for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++)
                ipad[i] ^= 0x36;
 
-       tmp.page = virt_to_page(ipad);
-       tmp.offset = offset_in_page(ipad);
-       tmp.length = crypto_tfm_alg_blocksize(tfm);
-       
+       sg_init_one(tmp, ipad, crypto_tfm_alg_blocksize(tfm));
        crypto_digest_init(tfm);
        crypto_digest_update(tfm, &tmp, 1);
 }
@@ -103,17 +98,11 @@ void crypto_hmac_final(struct crypto_tfm
        for (i = 0; i < crypto_tfm_alg_blocksize(tfm); i++)
                opad[i] ^= 0x5c;
 
-       tmp.page = virt_to_page(opad);
-       tmp.offset = offset_in_page(opad);
-       tmp.length = crypto_tfm_alg_blocksize(tfm);
-
+       sg_init_one(tmp, opad, crypto_tfm_alg_blocksize(tfm));
        crypto_digest_init(tfm);
        crypto_digest_update(tfm, &tmp, 1);
        
-       tmp.page = virt_to_page(out);
-       tmp.offset = offset_in_page(out);
-       tmp.length = crypto_tfm_alg_digestsize(tfm);
-       
+       sg_init_one(tmp, out, crypto_tfm_alg_blocksize(tfm));
        crypto_digest_update(tfm, &tmp, 1);
        crypto_digest_final(tfm, out);
 }
diff -puN crypto/tcrypt.c~use-sg_init_one-where-appropriate crypto/tcrypt.c
--- 25/crypto/tcrypt.c~use-sg_init_one-where-appropriate        Mon Aug 29 
16:19:54 2005
+++ 25-akpm/crypto/tcrypt.c     Mon Aug 29 16:23:41 2005
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include <linux/string.h>
 #include <linux/crypto.h>
 #include <linux/highmem.h>
@@ -117,9 +118,7 @@ static void test_hash(char *algo, struct
                memset(result, 0, 64);
 
                p = hash_tv[i].plaintext;
-               sg[0].page = virt_to_page(p);
-               sg[0].offset = offset_in_page(p);
-               sg[0].length = hash_tv[i].psize;
+               sg_init_one(&sg[0], p, hash_tv[i].psize);
 
                crypto_digest_init(tfm);
                if (tfm->crt_u.digest.dit_setkey) {
@@ -155,9 +154,7 @@ static void test_hash(char *algo, struct
                                       hash_tv[i].tap[k]);
                                temp += hash_tv[i].tap[k];
                                p = &xbuf[IDX[k]];
-                               sg[k].page = virt_to_page(p);
-                               sg[k].offset = offset_in_page(p);
-                               sg[k].length = hash_tv[i].tap[k];
+                               sg_init_one(&sg[k], p, hash_tv[i].tap[k]);
                        }
 
                        crypto_digest_digest(tfm, sg, hash_tv[i].np, result);
@@ -212,9 +209,7 @@ static void test_hmac(char *algo, struct
 
                p = hmac_tv[i].plaintext;
                klen = hmac_tv[i].ksize;
-               sg[0].page = virt_to_page(p);
-               sg[0].offset = offset_in_page(p);
-               sg[0].length = hmac_tv[i].psize;
+               sg_init_one(&sg[0], p, hmac_tv[i].psize);
 
                crypto_hmac(tfm, hmac_tv[i].key, &klen, sg, 1, result);
 
@@ -244,9 +239,7 @@ static void test_hmac(char *algo, struct
                                       hmac_tv[i].tap[k]);
                                temp += hmac_tv[i].tap[k];
                                p = &xbuf[IDX[k]];
-                               sg[k].page = virt_to_page(p);
-                               sg[k].offset = offset_in_page(p);
-                               sg[k].length = hmac_tv[i].tap[k];
+                               sg_init_one(&sg[k], p, hmac_tv[i].tap[k]);
                        }
 
                        crypto_hmac(tfm, hmac_tv[i].key, &klen, sg,
@@ -331,9 +324,7 @@ static void test_cipher(char *algo, int 
                        }
 
                        p = cipher_tv[i].input;
-                       sg[0].page = virt_to_page(p);
-                       sg[0].offset = offset_in_page(p);
-                       sg[0].length = cipher_tv[i].ilen;
+                       sg_init_one(&sg[0], p, cipher_tv[i].ilen);
 
                        if (!mode) {
                                crypto_cipher_set_iv(tfm, cipher_tv[i].iv,
@@ -390,9 +381,7 @@ static void test_cipher(char *algo, int 
                                       cipher_tv[i].tap[k]);
                                temp += cipher_tv[i].tap[k];
                                p = &xbuf[IDX[k]];
-                               sg[k].page = virt_to_page(p);
-                               sg[k].offset = offset_in_page(p);
-                               sg[k].length = cipher_tv[i].tap[k];
+                               sg_init_one(&sk[k], p, cipher_tv[i].tap[k]);
                        }
 
                        if (!mode) {
@@ -439,6 +428,7 @@ static int test_cipher_jiffies(struct cr
        sg[0].page = virt_to_page(p);
        sg[0].offset = offset_in_page(p);
        sg[0].length = blen;
+       sg_init_one(&sk[0], p, blen);
 
        for (start = jiffies, end = start + sec * HZ, bcount = 0;
             time_before(jiffies, end); bcount++) {
@@ -464,9 +454,7 @@ static int test_cipher_cycles(struct cry
        int ret = 0;
        int i;
 
-       sg[0].page = virt_to_page(p);
-       sg[0].offset = offset_in_page(p);
-       sg[0].length = blen;
+       sg_init_one(&sk[0], p, blen);
 
        local_bh_disable();
        local_irq_disable();
@@ -709,9 +697,7 @@ static void test_crc32c(void)
        for (i = 0; i < NUMVEC; i++) {
                for (j = 0; j < VECSIZE; j++)
                        test_vec[i][j] = ++b;
-               sg[i].page = virt_to_page(test_vec[i]);
-               sg[i].offset = offset_in_page(test_vec[i]);
-               sg[i].length = VECSIZE;
+               sg_init_one(&sg[i], test_vec[i], VECSIZE);
        }
 
        seed = SEEDTESTVAL;
diff -puN drivers/md/dm-crypt.c~use-sg_init_one-where-appropriate 
drivers/md/dm-crypt.c
--- 25/drivers/md/dm-crypt.c~use-sg_init_one-where-appropriate  Mon Aug 29 
16:19:54 2005
+++ 25-akpm/drivers/md/dm-crypt.c       Mon Aug 29 16:19:54 2005
@@ -16,6 +16,7 @@
 #include <linux/workqueue.h>
 #include <asm/atomic.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include <asm/page.h>
 
 #include "dm.h"
@@ -164,9 +165,7 @@ static int crypt_iv_essiv_ctr(struct cry
                return -ENOMEM;
        }
 
-       sg.page = virt_to_page(cc->key);
-       sg.offset = offset_in_page(cc->key);
-       sg.length = cc->key_size;
+       sg_init_one(&sg, cc->key, cc->key_size);
        crypto_digest_digest(hash_tfm, &sg, 1, salt);
        crypto_free_tfm(hash_tfm);
 
@@ -207,14 +206,12 @@ static void crypt_iv_essiv_dtr(struct cr
 
 static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
 {
-       struct scatterlist sg = { NULL, };
+       struct scatterlist sg;
 
        memset(iv, 0, cc->iv_size);
        *(u64 *)iv = cpu_to_le64(sector);
 
-       sg.page = virt_to_page(iv);
-       sg.offset = offset_in_page(iv);
-       sg.length = cc->iv_size;
+       sg_init_one(&sg, iv, cc->iv_size);
        crypto_cipher_encrypt((struct crypto_tfm *)cc->iv_gen_private,
                              &sg, &sg, cc->iv_size);
 
diff -puN drivers/net/wireless/airo.c~use-sg_init_one-where-appropriate 
drivers/net/wireless/airo.c
--- 25/drivers/net/wireless/airo.c~use-sg_init_one-where-appropriate    Mon Aug 
29 16:19:54 2005
+++ 25-akpm/drivers/net/wireless/airo.c Mon Aug 29 16:19:54 2005
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/in.h>
 #include <linux/bitops.h>
+#include <linux/scatterlist.h>
 #include <asm/io.h>
 #include <asm/system.h>
 
@@ -1596,9 +1597,7 @@ static void emmh32_setseed(emmh32_contex
                aes_counter[12] = (u8)(counter >> 24);
                counter++;
                memcpy (plain, aes_counter, 16);
-               sg[0].page = virt_to_page(plain);
-               sg[0].offset = ((long) plain & ~PAGE_MASK);
-               sg[0].length = 16;
+               sg_init_one(&sg[0], plain, 16);
                crypto_cipher_encrypt(tfm, sg, sg, 16);
                cipher = kmap(sg[0].page) + sg[0].offset;
                for (j=0; (j<16) && (i< 
(sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
diff -puN drivers/scsi/arm/scsi.h~use-sg_init_one-where-appropriate 
drivers/scsi/arm/scsi.h
--- 25/drivers/scsi/arm/scsi.h~use-sg_init_one-where-appropriate        Mon Aug 
29 16:19:54 2005
+++ 25-akpm/drivers/scsi/arm/scsi.h     Mon Aug 29 16:19:54 2005
@@ -11,6 +11,7 @@
  */
 
 #define BELT_AND_BRACES
+#include <linux/scatterlist.h>
 
 /*
  * The scatter-gather list handling.  This contains all
@@ -22,10 +23,7 @@ static inline int copy_SCp_to_sg(struct 
 
        BUG_ON(bufs + 1 > max);
 
-       sg->page   = virt_to_page(SCp->ptr);
-       sg->offset = offset_in_page(SCp->ptr);
-       sg->length = SCp->this_residual;
-
+        sg_init_one(sg, SCp->ptr, SCp->this_residual);
        if (bufs)
                memcpy(sg + 1, SCp->buffer + 1,
                       sizeof(struct scatterlist) * bufs);
diff -puN drivers/scsi/libata-core.c~use-sg_init_one-where-appropriate 
drivers/scsi/libata-core.c
--- 25/drivers/scsi/libata-core.c~use-sg_init_one-where-appropriate     Mon Aug 
29 16:19:54 2005
+++ 25-akpm/drivers/scsi/libata-core.c  Mon Aug 29 16:19:54 2005
@@ -38,6 +38,7 @@
 #include <linux/completion.h>
 #include <linux/suspend.h>
 #include <linux/workqueue.h>
+#include <linux/scatterlist.h>
 #include <scsi/scsi.h>
 #include "scsi.h"
 #include "scsi_priv.h"
@@ -2270,19 +2271,12 @@ void ata_qc_prep(struct ata_queued_cmd *
 
 void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
 {
-       struct scatterlist *sg;
-
        qc->flags |= ATA_QCFLAG_SINGLE;
 
-       memset(&qc->sgent, 0, sizeof(qc->sgent));
        qc->sg = &qc->sgent;
        qc->n_elem = 1;
        qc->buf_virt = buf;
-
-       sg = qc->sg;
-       sg->page = virt_to_page(buf);
-       sg->offset = (unsigned long) buf & ~PAGE_MASK;
-       sg->length = buflen;
+       sg_init_one(qc->sg, buf, buflen);
 }
 
 /**
diff -puN drivers/scsi/sg.c~use-sg_init_one-where-appropriate drivers/scsi/sg.c
--- 25/drivers/scsi/sg.c~use-sg_init_one-where-appropriate      Mon Aug 29 
16:19:54 2005
+++ 25-akpm/drivers/scsi/sg.c   Mon Aug 29 16:19:54 2005
@@ -49,6 +49,7 @@ static int sg_version_num = 30533;    /* 2 
 #include <linux/seq_file.h>
 #include <linux/blkdev.h>
 #include <linux/delay.h>
+#include <linux/scatterlist.h>
 
 #include "scsi.h"
 #include <scsi/scsi_dbg.h>
@@ -1992,9 +1993,7 @@ sg_build_indirect(Sg_scatter_hold * schp
                                if (!p)
                                        break;
                        }
-                       sclp->page = virt_to_page(p);
-                       sclp->offset = offset_in_page(p);
-                       sclp->length = ret_sz;
+                       sg_init_one(sclp, p, ret_sz);
 
                        SCSI_LOG_TIMEOUT(5, printk("sg_build_build: k=%d, 
a=0x%p, len=%d\n",
                                          k, sg_scatg2virt(sclp), ret_sz));
diff -puN drivers/usb/misc/usbtest.c~use-sg_init_one-where-appropriate 
drivers/usb/misc/usbtest.c
--- 25/drivers/usb/misc/usbtest.c~use-sg_init_one-where-appropriate     Mon Aug 
29 16:19:54 2005
+++ 25-akpm/drivers/usb/misc/usbtest.c  Mon Aug 29 16:19:54 2005
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 
 #include <linux/usb.h>
 
@@ -381,7 +382,6 @@ alloc_sglist (int nents, int max, int va
        sg = kmalloc (nents * sizeof *sg, SLAB_KERNEL);
        if (!sg)
                return NULL;
-       memset (sg, 0, nents * sizeof *sg);
 
        for (i = 0; i < nents; i++) {
                char            *buf;
@@ -394,9 +394,7 @@ alloc_sglist (int nents, int max, int va
                memset (buf, 0, size);
 
                /* kmalloc pages are always physically contiguous! */
-               sg [i].page = virt_to_page (buf);
-               sg [i].offset = offset_in_page (buf);
-               sg [i].length = size;
+               sg_init_one(&sg[i], buf, size);
 
                if (vary) {
                        size += vary;
diff -puN include/linux/scatterlist.h~use-sg_init_one-where-appropriate 
include/linux/scatterlist.h
--- 25/include/linux/scatterlist.h~use-sg_init_one-where-appropriate    Mon Aug 
29 16:19:54 2005
+++ 25-akpm/include/linux/scatterlist.h Mon Aug 29 16:19:54 2005
@@ -2,7 +2,8 @@
 #define _LINUX_SCATTERLIST_H
 
 static inline void sg_init_one(struct scatterlist *sg,
-                              u8 *buf, unsigned int buflen)
+                              u8 *buf,
+                              const unsigned int buflen)
 {
        memset(sg, 0, sizeof(*sg));
 
diff -puN net/ipv6/addrconf.c~use-sg_init_one-where-appropriate 
net/ipv6/addrconf.c
--- 25/net/ipv6/addrconf.c~use-sg_init_one-where-appropriate    Mon Aug 29 
16:19:54 2005
+++ 25-akpm/net/ipv6/addrconf.c Mon Aug 29 16:19:54 2005
@@ -76,6 +76,7 @@
 #include <linux/random.h>
 #include <linux/crypto.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #endif
 
 #include <asm/uaccess.h>
@@ -1218,12 +1219,8 @@ static int __ipv6_regen_rndid(struct ine
        struct net_device *dev;
        struct scatterlist sg[2];
 
-       sg[0].page = virt_to_page(idev->entropy);
-       sg[0].offset = offset_in_page(idev->entropy);
-       sg[0].length = 8;
-       sg[1].page = virt_to_page(idev->work_eui64);
-       sg[1].offset = offset_in_page(idev->work_eui64);
-       sg[1].length = 8;
+       sg_init_one(&sg[0], idev->entropy, 8);
+       sg_init_one(&sg[1], idev->work_eui64, 8);
 
        dev = idev->dev;
 
diff -puN 
net/sunrpc/auth_gss/gss_krb5_crypto.c~use-sg_init_one-where-appropriate 
net/sunrpc/auth_gss/gss_krb5_crypto.c
--- 25/net/sunrpc/auth_gss/gss_krb5_crypto.c~use-sg_init_one-where-appropriate  
Mon Aug 29 16:19:54 2005
+++ 25-akpm/net/sunrpc/auth_gss/gss_krb5_crypto.c       Mon Aug 29 16:19:54 2005
@@ -38,6 +38,7 @@
 #include <linux/mm.h>
 #include <linux/slab.h>
 #include <asm/scatterlist.h>
+#include <linux/scatterlist.h>
 #include <linux/crypto.h>
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
@@ -75,9 +76,7 @@ krb5_encrypt(
                memcpy(local_iv, iv, crypto_tfm_alg_ivsize(tfm));
 
        memcpy(out, in, length);
-       sg[0].page = virt_to_page(out);
-       sg[0].offset = offset_in_page(out);
-       sg[0].length = length;
+       sg_init_one(&sg[0], out, length);
 
        ret = crypto_cipher_encrypt_iv(tfm, sg, sg, length, local_iv);
 
@@ -117,9 +116,7 @@ krb5_decrypt(
                memcpy(local_iv,iv, crypto_tfm_alg_ivsize(tfm));
 
        memcpy(out, in, length);
-       sg[0].page = virt_to_page(out);
-       sg[0].offset = offset_in_page(out);
-       sg[0].length = length;
+       sg_init_one(&sg[0], out, length);
 
        ret = crypto_cipher_decrypt_iv(tfm, sg, sg, length, local_iv);
 
@@ -132,13 +129,6 @@ out:
 
 EXPORT_SYMBOL(krb5_decrypt);
 
-static void
-buf_to_sg(struct scatterlist *sg, char *ptr, int len) {
-       sg->page = virt_to_page(ptr);
-       sg->offset = offset_in_page(ptr);
-       sg->length = len;
-}
-
 /* checksum the plaintext data and hdrlen bytes of the token header */
 s32
 make_checksum(s32 cksumtype, char *header, int hdrlen, struct xdr_buf *body,
@@ -167,10 +157,10 @@ make_checksum(s32 cksumtype, char *heade
                goto out;
 
        crypto_digest_init(tfm);
-       buf_to_sg(sg, header, hdrlen);
+       sg_init_one(sg, header, hdrlen);
        crypto_digest_update(tfm, sg, 1);
        if (body->head[0].iov_len) {
-               buf_to_sg(sg, body->head[0].iov_base, body->head[0].iov_len);
+               sg_init_one(sg, body->head[0].iov_base, body->head[0].iov_len);
                crypto_digest_update(tfm, sg, 1);
        }
 
@@ -193,7 +183,7 @@ make_checksum(s32 cksumtype, char *heade
                } while(len != 0);
        }
        if (body->tail[0].iov_len) {
-               buf_to_sg(sg, body->tail[0].iov_base, body->tail[0].iov_len);
+               sg_init_one(sg, body->tail[0].iov_base, body->tail[0].iov_len);
                crypto_digest_update(tfm, sg, 1);
        }
        crypto_digest_final(tfm, cksum->data);
_
-
To unsubscribe from this list: send the line "unsubscribe mm-commits" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to