Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: ccp - Account for CCP backlog processing

When the crypto layer is able to queue up a command for processing
by the CCP on the initial call to ccp_crypto_enqueue_request and
the CCP returns -EBUSY, then if the backlog flag is not set the
command needs to be freed and not added to the active command list.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Tom Lendacky and committed by
Herbert Xu
c65a52f8 950b10ba

+11 -7
+11 -7
drivers/crypto/ccp/ccp-crypto-main.c
··· 205 205 { 206 206 struct ccp_crypto_cmd *active = NULL, *tmp; 207 207 unsigned long flags; 208 + bool free_cmd = true; 208 209 int ret; 209 210 210 211 spin_lock_irqsave(&req_queue_lock, flags); ··· 232 231 if (!active) { 233 232 ret = ccp_enqueue_cmd(crypto_cmd->cmd); 234 233 if (!ccp_crypto_success(ret)) 235 - goto e_lock; 234 + goto e_lock; /* Error, don't queue it */ 235 + if ((ret == -EBUSY) && 236 + !(crypto_cmd->cmd->flags & CCP_CMD_MAY_BACKLOG)) 237 + goto e_lock; /* Not backlogging, don't queue it */ 236 238 } 237 239 238 240 if (req_queue.cmd_count >= CCP_CRYPTO_MAX_QLEN) { ··· 248 244 req_queue.cmd_count++; 249 245 list_add_tail(&crypto_cmd->entry, &req_queue.cmds); 250 246 247 + free_cmd = false; 248 + 251 249 e_lock: 252 250 spin_unlock_irqrestore(&req_queue_lock, flags); 251 + 252 + if (free_cmd) 253 + kfree(crypto_cmd); 253 254 254 255 return ret; 255 256 } ··· 271 262 { 272 263 struct ccp_crypto_cmd *crypto_cmd; 273 264 gfp_t gfp; 274 - int ret; 275 265 276 266 gfp = req->flags & CRYPTO_TFM_REQ_MAY_SLEEP ? GFP_KERNEL : GFP_ATOMIC; 277 267 ··· 295 287 else 296 288 cmd->flags &= ~CCP_CMD_MAY_BACKLOG; 297 289 298 - ret = ccp_crypto_enqueue_cmd(crypto_cmd); 299 - if (!ccp_crypto_success(ret)) 300 - kfree(crypto_cmd); 301 - 302 - return ret; 290 + return ccp_crypto_enqueue_cmd(crypto_cmd); 303 291 } 304 292 305 293 struct scatterlist *ccp_crypto_sg_table_add(struct sg_table *table,