Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c46f2334 authored by Jens Axboe's avatar Jens Axboe Committed by Jens Axboe
Browse files

[SG] Get rid of __sg_mark_end()



sg_mark_end() overwrites the page_link information, but all users want
__sg_mark_end() behaviour where we just set the end bit. That is the most
natural way to use the sg list, since you'll fill it in and then mark the
end point.

So change sg_mark_end() to only set the termination bit. Add a sg_magic
debug check as well, and clear a chain pointer if it is set.

Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 87ae9afd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1369,7 +1369,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
	} /* segments in rq */

	if (sg)
		__sg_mark_end(sg);
		sg_mark_end(sg);

	return nsegs;
}
+1 −1
Original line number Diff line number Diff line
@@ -785,7 +785,7 @@ struct scatterlist *scsi_alloc_sgtable(struct scsi_cmnd *cmd, gfp_t gfp_mask)
		 * end-of-list
		 */
		if (!left)
			sg_mark_end(sgl, this);
			sg_mark_end(&sgl[this - 1]);

		/*
		 * don't allow subsequent mempool allocs to sleep, it would
+12 −10
Original line number Diff line number Diff line
@@ -188,21 +188,23 @@ static inline void sg_chain(struct scatterlist *prv, unsigned int prv_nents,

/**
 * sg_mark_end - Mark the end of the scatterlist
 * @sgl:	Scatterlist
 * @nents:	Number of entries in sgl
 * @sg:		 SG entryScatterlist
 *
 * Description:
 *   Marks the last entry as the termination point for sg_next()
 *   Marks the passed in sg entry as the termination point for the sg
 *   table. A call to sg_next() on this entry will return NULL.
 *
 **/
static inline void sg_mark_end(struct scatterlist *sgl, unsigned int nents)
{
	sgl[nents - 1].page_link = 0x02;
}

static inline void __sg_mark_end(struct scatterlist *sg)
static inline void sg_mark_end(struct scatterlist *sg)
{
#ifdef CONFIG_DEBUG_SG
	BUG_ON(sg->sg_magic != SG_MAGIC);
#endif
	/*
	 * Set termination bit, clear potential chain bit
	 */
	sg->page_link |= 0x02;
	sg->page_link &= ~0x01;
}

/**
@@ -218,7 +220,6 @@ static inline void __sg_mark_end(struct scatterlist *sg)
static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
{
	memset(sgl, 0, sizeof(*sgl) * nents);
	sg_mark_end(sgl, nents);
#ifdef CONFIG_DEBUG_SG
	{
		unsigned int i;
@@ -226,6 +227,7 @@ static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents)
			sgl[i].sg_magic = SG_MAGIC;
	}
#endif
	sg_mark_end(&sgl[nents - 1]);
}

/**
+1 −1
Original line number Diff line number Diff line
@@ -2095,7 +2095,7 @@ int skb_to_sgvec(struct sk_buff *skb, struct scatterlist *sg, int offset, int le
{
	int nsg = __skb_to_sgvec(skb, sg, offset, len);

	__sg_mark_end(&sg[nsg - 1]);
	sg_mark_end(&sg[nsg - 1]);

	return nsg;
}
+1 −1
Original line number Diff line number Diff line
@@ -1083,7 +1083,7 @@ static int tcp_v4_do_calc_md5_hash(char *md5_hash, struct tcp_md5sig_key *key,
	sg_set_buf(&sg[block++], key->key, key->keylen);
	nbytes += key->keylen;

	__sg_mark_end(&sg[block - 1]);
	sg_mark_end(&sg[block - 1]);

	/* Now store the Hash into the packet */
	err = crypto_hash_init(desc);
Loading