]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
SG: Change sg_set_page() to take length and offset argument
authorJens Axboe <jens.axboe@oracle.com>
Wed, 24 Oct 2007 09:20:47 +0000 (11:20 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 24 Oct 2007 09:20:47 +0000 (11:20 +0200)
Most drivers need to set length and offset as well, so may as well fold
those three lines into one.

Add sg_assign_page() for those two locations that only needed to set
the page, where the offset/length is set outside of the function context.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
31 files changed:
block/ll_rw_blk.c
crypto/hmac.c
drivers/ata/libata-core.c
drivers/block/cryptoloop.c
drivers/block/ub.c
drivers/ieee1394/dma.c
drivers/infiniband/core/umem.c
drivers/infiniband/hw/mthca/mthca_memfree.c
drivers/md/dm-crypt.c
drivers/media/common/saa7146_core.c
drivers/media/video/ivtv/ivtv-udma.c
drivers/media/video/videobuf-dma-sg.c
drivers/net/mlx4/icm.c
drivers/s390/scsi/zfcp_aux.c
drivers/s390/scsi/zfcp_def.h
drivers/s390/scsi/zfcp_erp.c
drivers/scsi/ipr.c
drivers/scsi/iscsi_tcp.c
drivers/scsi/osst.c
drivers/scsi/sg.c
drivers/scsi/st.c
fs/ecryptfs/crypto.c
include/asm-frv/scatterlist.h
include/linux/scatterlist.h
net/core/skbuff.c
net/ieee80211/ieee80211_crypt_tkip.c
net/sctp/auth.c
net/sctp/sm_make_chunk.c
net/sunrpc/auth_gss/gss_krb5_crypto.c
net/sunrpc/xdr.c
net/xfrm/xfrm_algo.c

index de5ba479c2245b9e747558757fb6444eebc6745e..b01dee3ae7f36c1d29014bc91fee09466ed7b922 100644 (file)
@@ -1366,9 +1366,7 @@ new_segment:
                                sg = sg_next(sg);
                        }
 
-                       sg_set_page(sg, bvec->bv_page);
-                       sg->length = nbytes;
-                       sg->offset = bvec->bv_offset;
+                       sg_set_page(sg, bvec->bv_page, nbytes, bvec->bv_offset);
                        nsegs++;
                }
                bvprv = bvec;
index e4eb6ac53b5c0b68e01643ce0ec2be97bca35939..6691981bda1147ec22171791cada8e334e1d29f7 100644 (file)
@@ -160,8 +160,7 @@ static int hmac_digest(struct hash_desc *pdesc, struct scatterlist *sg,
 
        sg_set_buf(sg1, ipad, bs);
 
-       sg_set_page(&sg[1], (void *) sg);
-       sg1[1].length = 0;
+       sg_set_page(&sg[1], (void *) sg, 0, 0);
        sg_set_buf(sg2, opad, bs + ds);
 
        err = crypto_hash_digest(&desc, sg1, nbytes + bs, digest);
index 2d147b51c9786d0b3bce7583e5cbcb697393add0..b5f7c5913062ed0458330e084099d0cd0923d2f7 100644 (file)
@@ -4689,8 +4689,8 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
                 * data in this function or read data in ata_sg_clean.
                 */
                offset = lsg->offset + lsg->length - qc->pad_len;
-               sg_set_page(psg, nth_page(sg_page(lsg), offset >> PAGE_SHIFT));
-               psg->offset = offset_in_page(offset);
+               sg_set_page(psg, nth_page(sg_page(lsg), offset >> PAGE_SHIFT),
+                               qc->pad_len, offset_in_page(offset));
 
                if (qc->tf.flags & ATA_TFLAG_WRITE) {
                        void *addr = kmap_atomic(sg_page(psg), KM_IRQ0);
index 1b58b010797f198332299cfa959aed18256d5e68..241167878edf5033aaeddf525d5ba0c529f5434c 100644 (file)
@@ -150,13 +150,8 @@ cryptoloop_transfer(struct loop_device *lo, int cmd,
                u32 iv[4] = { 0, };
                iv[0] = cpu_to_le32(IV & 0xffffffff);
 
-               sg_set_page(&sg_in, in_page);
-               sg_in.offset = in_offs;
-               sg_in.length = sz;
-
-               sg_set_page(&sg_out, out_page);
-               sg_out.offset = out_offs;
-               sg_out.length = sz;
+               sg_set_page(&sg_in, in_page, sz, in_offs);
+               sg_set_page(&sg_out, out_page, sz, out_offs);
 
                desc.info = iv;
                err = encdecfunc(&desc, &sg_out, &sg_in, sz);
index 14143f2c484d0ac28be1fc60b9d765c19d3c4b25..5e740e14ab351de7deddda3f2fd2308b4bb32b02 100644 (file)
@@ -1428,9 +1428,8 @@ static void ub_state_sense(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
        scmd->state = UB_CMDST_INIT;
        scmd->nsg = 1;
        sg = &scmd->sgv[0];
-       sg_set_page(sg, virt_to_page(sc->top_sense));
-       sg->offset = (unsigned long)sc->top_sense & (PAGE_SIZE-1);
-       sg->length = UB_SENSE_SIZE;
+       sg_set_page(sg, virt_to_page(sc->top_sense), UB_SENSE_SIZE,
+                       (unsigned long)sc->top_sense & (PAGE_SIZE-1));
        scmd->len = UB_SENSE_SIZE;
        scmd->lun = cmd->lun;
        scmd->done = ub_top_sense_done;
@@ -1864,9 +1863,7 @@ static int ub_sync_read_cap(struct ub_dev *sc, struct ub_lun *lun,
        cmd->state = UB_CMDST_INIT;
        cmd->nsg = 1;
        sg = &cmd->sgv[0];
-       sg_set_page(sg, virt_to_page(p));
-       sg->offset = (unsigned long)p & (PAGE_SIZE-1);
-       sg->length = 8;
+       sg_set_page(sg, virt_to_page(p), 8, (unsigned long)p & (PAGE_SIZE-1));
        cmd->len = 8;
        cmd->lun = lun;
        cmd->done = ub_probe_done;
index 3051e312fdc824733d837529461b13b27cbf587f..f5f4983dfbf3db5cc85fc77522ddc510e6839504 100644 (file)
@@ -111,8 +111,8 @@ int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes,
                unsigned long va =
                    (unsigned long)dma->kvirt + (i << PAGE_SHIFT);
 
-               sg_set_page(&dma->sglist[i], vmalloc_to_page((void *)va));
-               dma->sglist[i].length = PAGE_SIZE;
+               sg_set_page(&dma->sglist[i], vmalloc_to_page((void *)va),
+                               PAGE_SIZE, 0);
        }
 
        /* map sglist to the IOMMU */
index 14159ff29408c717fcf77c3940458f59dadc11c8..4e3128ff73c135ce988cdbb9d75fd58981faa26b 100644 (file)
@@ -171,9 +171,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
                                if (vma_list &&
                                    !is_vm_hugetlb_page(vma_list[i + off]))
                                        umem->hugetlb = 0;
-                               sg_set_page(&chunk->page_list[i], page_list[i + off]);
-                               chunk->page_list[i].offset = 0;
-                               chunk->page_list[i].length = PAGE_SIZE;
+                               sg_set_page(&chunk->page_list[i], page_list[i + off], PAGE_SIZE, 0);
                        }
 
                        chunk->nmap = ib_dma_map_sg(context->device,
index 007b38157fc49b81d8363ba9908597d75f8522ff..1f4d27d7c16d9d5f8741364e6d7b613ca8ba17af 100644 (file)
@@ -113,9 +113,7 @@ static int mthca_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_m
        if (!page)
                return -ENOMEM;
 
-       sg_set_page(mem, page);
-       mem->length = PAGE_SIZE << order;
-       mem->offset = 0;
+       sg_set_page(mem, page, PAGE_SIZE << order, 0);
        return 0;
 }
 
@@ -481,9 +479,8 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
        if (ret < 0)
                goto out;
 
-       sg_set_page(&db_tab->page[i].mem, pages[0]);
-       db_tab->page[i].mem.length = MTHCA_ICM_PAGE_SIZE;
-       db_tab->page[i].mem.offset = uaddr & ~PAGE_MASK;
+       sg_set_page(&db_tab->page[i].mem, pages[0], MTHCA_ICM_PAGE_SIZE,
+                       uaddr & ~PAGE_MASK);
 
        ret = pci_map_sg(dev->pdev, &db_tab->page[i].mem, 1, PCI_DMA_TODEVICE);
        if (ret < 0) {
index ac54f697c508e57adc95d545ca4ec15459118d84..1c159ac68c98f2372ffebe58f363fa1ff6e63a80 100644 (file)
@@ -351,14 +351,10 @@ static int crypt_convert(struct crypt_config *cc,
                struct scatterlist sg_in, sg_out;
 
                sg_init_table(&sg_in, 1);
-               sg_set_page(&sg_in, bv_in->bv_page);
-               sg_in.offset = bv_in->bv_offset + ctx->offset_in;
-               sg_in.length = 1 << SECTOR_SHIFT;
+               sg_set_page(&sg_in, bv_in->bv_page, 1 << SECTOR_SHIFT, bv_in->bv_offset + ctx->offset_in);
 
                sg_init_table(&sg_out, 1);
-               sg_set_page(&sg_out, bv_out->bv_page);
-               sg_out.offset = bv_out->bv_offset + ctx->offset_out;
-               sg_out.length = 1 << SECTOR_SHIFT;
+               sg_set_page(&sg_out, bv_out->bv_page, 1 << SECTOR_SHIFT, bv_out->bv_offset + ctx->offset_out);
 
                ctx->offset_in += sg_in.length;
                if (ctx->offset_in >= bv_in->bv_len) {
index 2b1f8b4be00a456c56495ee69525aaa1c8e66596..cb034ead95ab8e5b88d2867cecdf7a7d5fe566fc 100644 (file)
@@ -118,8 +118,7 @@ static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
                if (NULL == pg)
                        goto err;
                BUG_ON(PageHighMem(pg));
-               sg_set_page(&sglist[i], pg);
-               sglist[i].length = PAGE_SIZE;
+               sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
        }
        return sglist;
 
index 912b424e520490c50bd5c303ca65c53d8bf2281f..460db03b0ba061477ae321038378f99b08c6b61e 100644 (file)
@@ -49,8 +49,6 @@ int ivtv_udma_fill_sg_list (struct ivtv_user_dma *dma, struct ivtv_dma_page_info
                unsigned int len = (i == dma_page->page_count - 1) ?
                        dma_page->tail : PAGE_SIZE - offset;
 
-               dma->SGlist[map_offset].length = len;
-               dma->SGlist[map_offset].offset = offset;
                if (PageHighMem(dma->map[map_offset])) {
                        void *src;
 
@@ -63,10 +61,10 @@ int ivtv_udma_fill_sg_list (struct ivtv_user_dma *dma, struct ivtv_dma_page_info
                        memcpy(page_address(dma->bouncemap[map_offset]) + offset, src, len);
                        kunmap_atomic(src, KM_BOUNCE_READ);
                        local_irq_restore(flags);
-                       sg_set_page(&dma->SGlist[map_offset], dma->bouncemap[map_offset]);
+                       sg_set_page(&dma->SGlist[map_offset], dma->bouncemap[map_offset], len, offset);
                }
                else {
-                       sg_set_page(&dma->SGlist[map_offset], dma->map[map_offset]);
+                       sg_set_page(&dma->SGlist[map_offset], dma->map[map_offset], len, offset);
                }
                offset = 0;
                map_offset++;
index 9ab94a749d81ec813036e7bef8dc6d0ad35519d2..44ee408e145ff51e950c8a152cf44aa073359a1b 100644 (file)
@@ -67,8 +67,7 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
                if (NULL == pg)
                        goto err;
                BUG_ON(PageHighMem(pg));
-               sg_set_page(&sglist[i], pg);
-               sglist[i].length = PAGE_SIZE;
+               sg_set_page(&sglist[i], pg, PAGE_SIZE, 0);
        }
        return sglist;
 
@@ -95,16 +94,13 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
        if (PageHighMem(pages[0]))
                /* DMA to highmem pages might not work */
                goto highmem;
-       sg_set_page(&sglist[0], pages[0]);
-       sglist[0].offset = offset;
-       sglist[0].length = PAGE_SIZE - offset;
+       sg_set_page(&sglist[0], pages[0], PAGE_SIZE - offset, offset);
        for (i = 1; i < nr_pages; i++) {
                if (NULL == pages[i])
                        goto nopage;
                if (PageHighMem(pages[i]))
                        goto highmem;
-               sg_set_page(&sglist[i], pages[i]);
-               sglist[i].length = PAGE_SIZE;
+               sg_set_page(&sglist[i], pages[i], PAGE_SIZE, 0);
        }
        return sglist;
 
index 887633b207d9de533000aefa61b9da5a0d7543a6..2a5bef6388fec9fb28995edb44e350474f60a1d7 100644 (file)
@@ -101,9 +101,7 @@ static int mlx4_alloc_icm_pages(struct scatterlist *mem, int order, gfp_t gfp_ma
        if (!page)
                return -ENOMEM;
 
-       sg_set_page(mem, page);
-       mem->length = PAGE_SIZE << order;
-       mem->offset = 0;
+       sg_set_page(mem, page, PAGE_SIZE << order, 0);
        return 0;
 }
 
index d9e7be979760e270ba16e216e56ec559af636f08..00118499018b3c94d4c2834d45e6a8eb156be6f0 100644 (file)
@@ -562,8 +562,6 @@ zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
        sg_init_table(sg_list->sg, sg_list->count);
 
        for (i = 0, sg = sg_list->sg; i < sg_list->count; i++, sg++) {
-               sg->length = min(size, PAGE_SIZE);
-               sg->offset = 0;
                address = (void *) get_zeroed_page(GFP_KERNEL);
                if (address == NULL) {
                        sg_list->count = i;
@@ -571,7 +569,7 @@ zfcp_sg_list_alloc(struct zfcp_sg_list *sg_list, size_t size)
                        retval = -ENOMEM;
                        goto out;
                }
-               zfcp_address_to_sg(address, sg);
+               zfcp_address_to_sg(address, sg, min(size, PAGE_SIZE));
                size -= sg->length;
        }
 
@@ -1523,10 +1521,8 @@ zfcp_gid_pn_buffers_alloc(struct zfcp_gid_pn_data **gid_pn, mempool_t *pool)
         data->ct.req = &data->req;
         data->ct.resp = &data->resp;
        data->ct.req_count = data->ct.resp_count = 1;
-       zfcp_address_to_sg(&data->ct_iu_req, &data->req);
-        zfcp_address_to_sg(&data->ct_iu_resp, &data->resp);
-        data->req.length = sizeof(struct ct_iu_gid_pn_req);
-        data->resp.length = sizeof(struct ct_iu_gid_pn_resp);
+       zfcp_address_to_sg(&data->ct_iu_req, &data->req, sizeof(struct ct_iu_gid_pn_req));
+        zfcp_address_to_sg(&data->ct_iu_resp, &data->resp, sizeof(struct ct_iu_gid_pn_resp));
 
        *gid_pn = data;
        return 0;
index 326e7ee232cb7cf4cfafd5bb41cda916b863adfc..0754542978b68b91f92b1dcbd91ad7a8cac9e4f6 100644 (file)
@@ -74,8 +74,7 @@ zfcp_sg_to_address(struct scatterlist *list)
 static inline void
 zfcp_address_to_sg(void *address, struct scatterlist *list)
 {
-       sg_set_page(list, virt_to_page(address));
-       list->offset = ((unsigned long) address) & (PAGE_SIZE - 1);
+       sg_set_buf(list, address, 0);
 }
 
 #define REQUEST_LIST_SIZE 128
index 9438d0b28799838442bfa94eb5d5cc0c62bc8692..5552b755c08a5ff849022e02132a040cd6dc7879 100644 (file)
@@ -322,9 +322,9 @@ zfcp_erp_adisc(struct zfcp_port *port)
        if (address == NULL)
                goto nomem;
 
-       zfcp_address_to_sg(address, send_els->req);
+       zfcp_address_to_sg(address, send_els->req, sizeof(struct zfcp_ls_adisc));
        address += PAGE_SIZE >> 1;
-       zfcp_address_to_sg(address, send_els->resp);
+       zfcp_address_to_sg(address, send_els->resp, sizeof(struct zfcp_ls_adisc_acc));
        send_els->req_count = send_els->resp_count = 1;
 
        send_els->adapter = adapter;
@@ -336,9 +336,6 @@ zfcp_erp_adisc(struct zfcp_port *port)
        adisc = zfcp_sg_to_address(send_els->req);
        send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
 
-       send_els->req->length = sizeof(struct zfcp_ls_adisc);
-       send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
-
        /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
           without FC-AL-2 capability, so we don't set it */
        adisc->wwpn = fc_host_port_name(adapter->scsi_host);
index 439b97a6a269f6b8377b865d4759c300a0429f8a..0841df01bc19921d7d34f99d08116c0076b7954c 100644 (file)
@@ -2890,7 +2890,7 @@ static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
                        return NULL;
                }
 
-               sg_set_page(&scatterlist[i], page);
+               sg_set_page(&scatterlist[i], page, 0, 0);
        }
 
        return sglist;
index 6ce4109efdf3365a39ab736597bdd2fa39d696fb..097a136398cbd771d07cd98df22f813c63c93c52 100644 (file)
@@ -79,9 +79,7 @@ static inline void
 iscsi_buf_init_sg(struct iscsi_buf *ibuf, struct scatterlist *sg)
 {
        sg_init_table(&ibuf->sg, 1);
-       sg_set_page(&ibuf->sg, sg_page(sg));
-       ibuf->sg.offset = sg->offset;
-       ibuf->sg.length = sg->length;
+       sg_set_page(&ibuf->sg, sg_page(sg), sg->length, sg->offset);
        /*
         * Fastpath: sg element fits into single page
         */
index 1c5c4b68f20f1c463b74b05136a1f3e3eeff910a..4652ad22516be010f0c9c46bd1612dc9dbf833c0 100644 (file)
@@ -5256,8 +5256,7 @@ static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
 
                STbuffer->sg[0].offset = 0;
                if (page != NULL) {
-                   sg_set_page(&STbuffer->sg[0], page);
-                   STbuffer->sg[0].length = b_size;
+                   sg_set_page(&STbuffer->sg[0], page, b_size, 0);
                    STbuffer->b_data = page_address(page);
                    break;
                }
@@ -5285,8 +5284,7 @@ static int enlarge_buffer(struct osst_buffer *STbuffer, int need_dma)
                        normalize_buffer(STbuffer);
                        return 0;
                }
-               sg_set_page(&STbuffer->sg[segs], page);
-               STbuffer->sg[segs].length = (OS_FRAME_SIZE - got <= PAGE_SIZE / 2) ? (OS_FRAME_SIZE - got) : b_size;
+               sg_set_page(&STbuffer->sg[segs], page, (OS_FRAME_SIZE - got <= PAGE_SIZE / 2) ? (OS_FRAME_SIZE - got) : b_size, 0);
                got += STbuffer->sg[segs].length;
                STbuffer->buffer_size = got;
                STbuffer->sg_segs = ++segs;
index cc19710028468eebe01154f730076fd4abe2362a..b5fa4f091387eb83cdc9009e2050d0062fa9201f 100644 (file)
@@ -1717,16 +1717,12 @@ st_map_user_pages(struct scatterlist *sgl, const unsigned int max_pages,
                   goto out_unlock; */
         }
 
-       sg_set_page(sgl, pages[0]);
-       sgl[0].offset = uaddr & ~PAGE_MASK;
+       sg_set_page(sgl, pages[0], 0, uaddr & ~PAGE_MASK);
        if (nr_pages > 1) {
                sgl[0].length = PAGE_SIZE - sgl[0].offset;
                count -= sgl[0].length;
-               for (i=1; i < nr_pages ; i++) {
-                       sg_set_page(&sgl[i], pages[i]);
-                       sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE;
-                       count -= PAGE_SIZE;
-               }
+               for (i=1; i < nr_pages ; i++)
+                       sg_set_page(&sgl[i], pages[i], count < PAGE_SIZE ? count : PAGE_SIZE, 0);
        }
        else {
                sgl[0].length = count;
@@ -1854,8 +1850,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
                                scatter_elem_sz_prev = ret_sz;
                        }
                }
-               sg_set_page(sg, p);
-               sg->length = (ret_sz > num) ? num : ret_sz;
+               sg_set_page(sg, p, (ret_sz > num) ? num : ret_sz, 0);
 
                SCSI_LOG_TIMEOUT(5, printk("sg_build_indirect: k=%d, num=%d, "
                                 "ret_sz=%d\n", k, num, ret_sz));
index ce69b9efc10245f01dcdc4e26e7ad58a57adb002..98dfd6ea209c69cd42b54fcbad286ac83826d7c7 100644 (file)
@@ -3797,13 +3797,11 @@ static void buf_to_sg(struct st_buffer *STbp, unsigned int length)
        sg = &(STbp->sg[0]);
        frp = STbp->frp;
        for (i=count=0; count < length; i++) {
-               sg_set_page(&sg[i], frp[i].page);
                if (length - count > frp[i].length)
-                       sg[i].length = frp[i].length;
+                       sg_set_page(&sg[i], frp[i].page, frp[i].length, 0);
                else
-                       sg[i].length = length - count;
+                       sg_set_page(&sg[i], frp[i].page, length - count, 0);
                count += sg[i].length;
-               sg[i].offset = 0;
        }
        STbp->sg_segs = i;
        STbp->frp_sg_current = length;
@@ -4446,15 +4444,13 @@ static int sgl_map_user_pages(struct scatterlist *sgl, const unsigned int max_pa
         }
 
        /* Populate the scatter/gather list */
-       sg_set_page(&sgl[0], pages[0]);
-       sgl[0].offset = uaddr & ~PAGE_MASK;
+       sg_set_page(&sgl[0], pages[0], 0, uaddr & ~PAGE_MASK);
        if (nr_pages > 1) {
                sgl[0].length = PAGE_SIZE - sgl[0].offset;
                count -= sgl[0].length;
                for (i=1; i < nr_pages ; i++) {
-                       sg_set_page(&sgl[i], pages[i]);;
-                       sgl[i].offset = 0;
-                       sgl[i].length = count < PAGE_SIZE ? count : PAGE_SIZE;
+                       sg_set_page(&sgl[i], pages[i],
+                                   count < PAGE_SIZE ? count : PAGE_SIZE, 0);;
                        count -= PAGE_SIZE;
                }
        }
index 0a9882edf56222721abbcf7f0b185b5c6a009456..7a472b129997e0113a0c3cec99a2a0d8743c3bbc 100644 (file)
@@ -282,10 +282,8 @@ int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
        while (size > 0 && i < sg_size) {
                pg = virt_to_page(addr);
                offset = offset_in_page(addr);
-               if (sg) {
-                       sg_set_page(&sg[i], pg);
-                       sg[i].offset = offset;
-               }
+               if (sg)
+                       sg_set_page(&sg[i], pg, 0, offset);
                remainder_of_page = PAGE_CACHE_SIZE - offset;
                if (size >= remainder_of_page) {
                        if (sg)
@@ -716,12 +714,8 @@ ecryptfs_encrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
        sg_init_table(&src_sg, 1);
        sg_init_table(&dst_sg, 1);
 
-       sg_set_page(&src_sg, src_page);
-       src_sg.offset = src_offset;
-       src_sg.length = size;
-       sg_set_page(&dst_sg, dst_page);
-       dst_sg.offset = dst_offset;
-       dst_sg.length = size;
+       sg_set_page(&src_sg, src_page, size, src_offset);
+       sg_set_page(&dst_sg, dst_page, size, dst_offset);
        return encrypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv);
 }
 
@@ -746,14 +740,11 @@ ecryptfs_decrypt_page_offset(struct ecryptfs_crypt_stat *crypt_stat,
        struct scatterlist src_sg, dst_sg;
 
        sg_init_table(&src_sg, 1);
+       sg_set_page(&src_sg, src_page, size, src_offset);
+
        sg_init_table(&dst_sg, 1);
+       sg_set_page(&dst_sg, dst_page, size, dst_offset);
 
-       sg_set_page(&src_sg, src_page);
-       src_sg.offset = src_offset;
-       src_sg.length = size;
-       sg_set_page(&dst_sg, dst_page);
-       dst_sg.offset = dst_offset;
-       dst_sg.length = size;
        return decrypt_scatterlist(crypt_stat, &dst_sg, &src_sg, size, iv);
 }
 
index 99ba76edc42a4c94a333571e9c5c1d2658e465ca..2e7143b5a7ad2921109e4bbf1ec3a4ec2d8d1e76 100644 (file)
@@ -16,8 +16,7 @@
  *
  * can be rewritten as
  *
- * sg_set_page(virt_to_page(some_ptr));
- * sg->offset = (unsigned long) some_ptr & ~PAGE_MASK;
+ * sg_set_buf(sg, some_ptr, length);
  *
  * and that's it. There's no excuse for not highmem enabling YOUR driver. /jens
  */
index df7ddcee7c4bdcef4ea5f80ed99c8719c025fc27..809b2ac2e37e04f98103919013c942cc1ff17ee5 100644 (file)
 #define SG_MAGIC       0x87654321
 
 /**
- * sg_set_page - Set sg entry to point at given page
- * @sg:                 SG entry
- * @page:       The page
+ * sg_assign_page - Assign a given page to an SG entry
+ * @sg:                    SG entry
+ * @page:          The page
  *
  * Description:
- *   Use this function to set an sg entry pointing at a page, never assign
- *   the page directly. We encode sg table information in the lower bits
- *   of the page pointer. See sg_page() for looking up the page belonging
- *   to an sg entry.
+ *   Assign page to sg entry. Also see sg_set_page(), the most commonly used
+ *   variant.
  *
  **/
-static inline void sg_set_page(struct scatterlist *sg, struct page *page)
+static inline void sg_assign_page(struct scatterlist *sg, struct page *page)
 {
        unsigned long page_link = sg->page_link & 0x3;
 
@@ -52,6 +50,28 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page)
        sg->page_link = page_link | (unsigned long) page;
 }
 
+/**
+ * sg_set_page - Set sg entry to point at given page
+ * @sg:                 SG entry
+ * @page:       The page
+ * @len:        Length of data
+ * @offset:     Offset into page
+ *
+ * Description:
+ *   Use this function to set an sg entry pointing at a page, never assign
+ *   the page directly. We encode sg table information in the lower bits
+ *   of the page pointer. See sg_page() for looking up the page belonging
+ *   to an sg entry.
+ *
+ **/
+static inline void sg_set_page(struct scatterlist *sg, struct page *page,
+                              unsigned int len, unsigned int offset)
+{
+       sg_assign_page(sg, page);
+       sg->offset = offset;
+       sg->length = len;
+}
+
 #define sg_page(sg)    ((struct page *) ((sg)->page_link & ~0x3))
 
 /**
@@ -64,9 +84,7 @@ static inline void sg_set_page(struct scatterlist *sg, struct page *page)
 static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
                              unsigned int buflen)
 {
-       sg_set_page(sg, virt_to_page(buf));
-       sg->offset = offset_in_page(buf);
-       sg->length = buflen;
+       sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
 }
 
 /*
index 4e2c84fcf2766fd542fb401b4e5847cd54603ce1..7b7c6c44c2da28b5fe2e22ababff4dcd61e6e72e 100644 (file)
@@ -2045,9 +2045,7 @@ skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
        if (copy > 0) {
                if (copy > len)
                        copy = len;
-               sg_set_page(&sg[elt], virt_to_page(skb->data + offset));
-               sg[elt].offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
-               sg[elt].length = copy;
+               sg_set_buf(sg, skb->data + offset, copy);
                elt++;
                if ((len -= copy) == 0)
                        return elt;
@@ -2065,9 +2063,8 @@ skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int len)
 
                        if (copy > len)
                                copy = len;
-                       sg_set_page(&sg[elt], frag->page);
-                       sg[elt].offset = frag->page_offset+offset-start;
-                       sg[elt].length = copy;
+                       sg_set_page(&sg[elt], frag->page, copy,
+                                       frag->page_offset+offset-start);
                        elt++;
                        if (!(len -= copy))
                                return elt;
index 74d017520a23c62f10b98927daca98f4c7afcf1d..4cce3534e408c5e5d495eda666ccef80fd4348c3 100644 (file)
@@ -537,13 +537,8 @@ static int michael_mic(struct crypto_hash *tfm_michael, u8 * key, u8 * hdr,
                return -1;
        }
        sg_init_table(sg, 2);
-       sg_set_page(&sg[0], virt_to_page(hdr));
-       sg[0].offset = offset_in_page(hdr);
-       sg[0].length = 16;
-
-       sg_set_page(&sg[1], virt_to_page(data));
-       sg[1].offset = offset_in_page(data);
-       sg[1].length = data_len;
+       sg_set_buf(&sg[0], hdr, 16);
+       sg_set_buf(&sg[1], data, data_len);
 
        if (crypto_hash_setkey(tfm_michael, key, 8))
                return -1;
index cbd64b216cce33a5e9a43e5fad24d4683a71a20d..621113a109b2e2548769419e126568c637611abd 100644 (file)
@@ -727,9 +727,7 @@ void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
        /* set up scatter list */
        end = skb_tail_pointer(skb);
        sg_init_table(&sg, 1);
-       sg_set_page(&sg, virt_to_page(auth));
-       sg.offset = (unsigned long)(auth) % PAGE_SIZE;
-       sg.length = end - (unsigned char *)auth;
+       sg_set_buf(&sg, auth, end - (unsigned char *)auth);
 
        desc.tfm = asoc->ep->auth_hmacs[hmac_id];
        desc.flags = 0;
index 658476c4d58737b3f7f648ef5d66cff247485ede..c055212875f61331ec2d340ff92ff6f70197212c 100644 (file)
@@ -1514,9 +1514,7 @@ static sctp_cookie_param_t *sctp_pack_cookie(const struct sctp_endpoint *ep,
 
                /* Sign the message.  */
                sg_init_table(&sg, 1);
-               sg_set_page(&sg, virt_to_page(&cookie->c));
-               sg.offset = (unsigned long)(&cookie->c) % PAGE_SIZE;
-               sg.length = bodysize;
+               sg_set_buf(&sg, &cookie->c, bodysize);
                keylen = SCTP_SECRET_SIZE;
                key = (char *)ep->secret_key[ep->current_key];
                desc.tfm = sctp_sk(ep->base.sk)->hmac;
@@ -1587,9 +1585,7 @@ struct sctp_association *sctp_unpack_cookie(
        /* Check the signature.  */
        keylen = SCTP_SECRET_SIZE;
        sg_init_table(&sg, 1);
-       sg_set_page(&sg, virt_to_page(bear_cookie));
-       sg.offset = (unsigned long)(bear_cookie) % PAGE_SIZE;
-       sg.length = bodysize;
+       sg_set_buf(&sg, bear_cookie, bodysize);
        key = (char *)ep->secret_key[ep->current_key];
        desc.tfm = sctp_sk(ep->base.sk)->hmac;
        desc.flags = 0;
index 32be431affcf2b80eac2147b313e09e4a0a9d1fc..24711be4b2dc89d6cfec7d002cd4eab41a8c815a 100644 (file)
@@ -199,7 +199,7 @@ encryptor(struct scatterlist *sg, void *data)
        } else {
                in_page = sg_page(sg);
        }
-       sg_set_page(&desc->infrags[desc->fragno], in_page);
+       sg_assign_page(&desc->infrags[desc->fragno], in_page);
        desc->fragno++;
        desc->fraglen += sg->length;
        desc->pos += sg->length;
@@ -215,11 +215,10 @@ encryptor(struct scatterlist *sg, void *data)
        if (ret)
                return ret;
        if (fraglen) {
-               sg_set_page(&desc->outfrags[0], sg_page(sg));
-               desc->outfrags[0].offset = sg->offset + sg->length - fraglen;
-               desc->outfrags[0].length = fraglen;
+               sg_set_page(&desc->outfrags[0], sg_page(sg), fraglen,
+                               sg->offset + sg->length - fraglen);
                desc->infrags[0] = desc->outfrags[0];
-               sg_set_page(&desc->infrags[0], in_page);
+               sg_assign_page(&desc->infrags[0], in_page);
                desc->fragno = 1;
                desc->fraglen = fraglen;
        } else {
@@ -287,9 +286,8 @@ decryptor(struct scatterlist *sg, void *data)
        if (ret)
                return ret;
        if (fraglen) {
-               sg_set_page(&desc->frags[0], sg_page(sg));
-               desc->frags[0].offset = sg->offset + sg->length - fraglen;
-               desc->frags[0].length = fraglen;
+               sg_set_page(&desc->frags[0], sg_page(sg), fraglen,
+                               sg->offset + sg->length - fraglen);
                desc->fragno = 1;
                desc->fraglen = fraglen;
        } else {
index 3d1f7cdf9dd015819e227bb1a1830b17ffd0972e..f38dac30481b44d93344850494ea1ec041a148e5 100644 (file)
@@ -1059,9 +1059,7 @@ xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len,
                do {
                        if (thislen > page_len)
                                thislen = page_len;
-                       sg_set_page(sg, buf->pages[i]);
-                       sg->offset = page_offset;
-                       sg->length = thislen;
+                       sg_set_page(sg, buf->pages[i], thislen, page_offset);
                        ret = actor(sg, data);
                        if (ret)
                                goto out;
index 313d4bed3aa9444d9817aa6f57adacfa1d49d75f..fa45989a716af7a7045ad56f9431908641d4897b 100644 (file)
@@ -553,9 +553,7 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
                if (copy > len)
                        copy = len;
 
-               sg_set_page(&sg, virt_to_page(skb->data + offset));
-               sg.offset = (unsigned long)(skb->data + offset) % PAGE_SIZE;
-               sg.length = copy;
+               sg_set_buf(&sg, skb->data + offset, copy);
 
                err = icv_update(desc, &sg, copy);
                if (unlikely(err))
@@ -578,9 +576,8 @@ int skb_icv_walk(const struct sk_buff *skb, struct hash_desc *desc,
                        if (copy > len)
                                copy = len;
 
-                       sg_set_page(&sg, frag->page);
-                       sg.offset = frag->page_offset + offset-start;
-                       sg.length = copy;
+                       sg_set_page(&sg, frag->page, copy,
+                                       frag->page_offset + offset-start);
 
                        err = icv_update(desc, &sg, copy);
                        if (unlikely(err))