diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 66665e6d7ef1..e1a9694fab19 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -1064,10 +1064,15 @@ static struct sg_table *ion_dupe_sg_table(struct sg_table *orig_table) return NULL; } - sg_orig = orig_table->sgl; - for_each_sg(table->sgl, sg, table->nents, i) { - *sg = *sg_orig; - sg_orig = sg_next(sg_orig); + if (table->nents <= SG_MAX_SINGLE_ALLOC) { + memcpy(table->sgl, orig_table->sgl, + table->nents * sizeof(*table->sgl)); + } else { + sg_orig = orig_table->sgl; + for_each_sg(table->sgl, sg, table->nents, i) { + *sg = *sg_orig; + sg_orig = sg_next(sg_orig); + } } return table; }