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

crypto: ccp - CCP device enabled/disabled changes

The CCP cannot be hot-plugged so it will either be there
or it won't. Do not allow the driver to stay loaded if the
CCP does not successfully initialize.

Provide stub routines in the ccp.h file that return -ENODEV
if the CCP has not been configured in the build.

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
db34cf91 82d1585b

+29 -1
+14 -1
drivers/crypto/ccp/ccp-dev.c
··· 552 552 static int __init ccp_mod_init(void) 553 553 { 554 554 struct cpuinfo_x86 *cpuinfo = &boot_cpu_data; 555 + int ret; 555 556 556 557 if (!x86_match_cpu(ccp_support)) 557 558 return -ENODEV; ··· 561 560 case 22: 562 561 if ((cpuinfo->x86_model < 48) || (cpuinfo->x86_model > 63)) 563 562 return -ENODEV; 564 - return ccp_pci_init(); 563 + 564 + ret = ccp_pci_init(); 565 + if (ret) 566 + return ret; 567 + 568 + /* Don't leave the driver loaded if init failed */ 569 + if (!ccp_get_device()) { 570 + ccp_pci_exit(); 571 + return -ENODEV; 572 + } 573 + 574 + return 0; 575 + 565 576 break; 566 577 } 567 578
+3
drivers/crypto/ccp/ccp-pci.c
··· 267 267 struct device *dev = &pdev->dev; 268 268 struct ccp_device *ccp = dev_get_drvdata(dev); 269 269 270 + if (!ccp) 271 + return; 272 + 270 273 ccp_destroy(ccp); 271 274 272 275 pci_iounmap(pdev, ccp->io_map);
+12
include/linux/ccp.h
··· 23 23 struct ccp_device; 24 24 struct ccp_cmd; 25 25 26 + #if defined(CONFIG_CRYPTO_DEV_CCP_DD) || \ 27 + defined(CONFIG_CRYPTO_DEV_CCP_DD_MODULE) 28 + 26 29 /** 27 30 * ccp_enqueue_cmd - queue an operation for processing by the CCP 28 31 * ··· 50 47 * the return code is -EBUSY and CCP_CMD_MAY_BACKLOG flag is set 51 48 */ 52 49 int ccp_enqueue_cmd(struct ccp_cmd *cmd); 50 + 51 + #else /* CONFIG_CRYPTO_DEV_CCP_DD is not enabled */ 52 + 53 + static inline int ccp_enqueue_cmd(struct ccp_cmd *cmd) 54 + { 55 + return -ENODEV; 56 + } 57 + 58 + #endif /* CONFIG_CRYPTO_DEV_CCP_DD */ 53 59 54 60 55 61 /***** AES engine *****/