diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
index 56ba4ff6d5ff..c2e0c6520f84 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-hash.c
@@ -344,9 +344,11 @@ static int sun8i_ss_run_hash_task(struct sun8i_ss_dev *ss,
 static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq)
 {
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
+	struct sun8i_ss_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
 	struct ahash_alg *alg = crypto_ahash_alg(tfm);
 	struct sun8i_ss_alg_template *algt;
 	struct scatterlist *sg;
+	int max_sg;
 
 	algt = container_of(alg, struct sun8i_ss_alg_template, alg.hash.base);
 
@@ -360,8 +362,9 @@ static bool sun8i_ss_hash_need_fallback(struct ahash_request *areq)
 		return true;
 	}
 
-	/* we need to reserve one SG for the padding one */
-	if (sg_nents(areq->src) > MAX_SG - 1) {
+	/* Reserve one SG for padding and, for HMAC, one for ipad */
+	max_sg = tfmctx->keylen ? MAX_SG - 2 : MAX_SG - 1;
+	if (sg_nents(areq->src) > max_sg) {
 		algt->stat_fb_sgnum++;
 		return true;
 	}
