diff mbox series

nvme-apple: stop casting function pointer signatures

Message ID 20220718050500.227804-1-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series nvme-apple: stop casting function pointer signatures | expand

Commit Message

Christoph Hellwig July 18, 2022, 5:05 a.m. UTC
Casting function pointers breaks control flow enforcement and is
generally a horrible coding style.

Add two wrapper to get rid of these casts.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/nvme/host/apple.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

Comments

Sven Peter July 18, 2022, 4 p.m. UTC | #1
On Mon, Jul 18, 2022, at 07:05, Christoph Hellwig wrote:
> Casting function pointers breaks control flow enforcement and is
> generally a horrible coding style.
>
> Add two wrapper to get rid of these casts.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Sven Peter <sven@svenpeter.dev>

makes sense, thanks!


Sven
Chaitanya Kulkarni July 18, 2022, 9:37 p.m. UTC | #2
On 7/17/22 22:05, Christoph Hellwig wrote:
> Casting function pointers breaks control flow enforcement and is
> generally a horrible coding style.
> 
> Add two wrapper to get rid of these casts.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

totally, this should be avoided.

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
Hector Martin July 31, 2022, 7:15 a.m. UTC | #3
On 18/07/2022 14.05, Christoph Hellwig wrote:
> Casting function pointers breaks control flow enforcement and is
> generally a horrible coding style.
> 
> Add two wrapper to get rid of these casts.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Hector Martin <marcan@marcan.st>

Yeah, casting function pointers is evil.

- Hector
diff mbox series

Patch

diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index 7816b5a7d0e1b..3cf607bb9ee6c 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -1220,6 +1220,11 @@  static void apple_nvme_async_probe(void *data, async_cookie_t cookie)
 	nvme_put_ctrl(&anv->ctrl);
 }
 
+static void devm_apple_nvme_put_tag_set(void *data)
+{
+	blk_mq_free_tag_set(data);
+}
+
 static int apple_nvme_alloc_tagsets(struct apple_nvme *anv)
 {
 	int ret;
@@ -1236,8 +1241,7 @@  static int apple_nvme_alloc_tagsets(struct apple_nvme *anv)
 	ret = blk_mq_alloc_tag_set(&anv->admin_tagset);
 	if (ret)
 		return ret;
-	ret = devm_add_action_or_reset(anv->dev,
-				       (void (*)(void *))blk_mq_free_tag_set,
+	ret = devm_add_action_or_reset(anv->dev, devm_apple_nvme_put_tag_set,
 				       &anv->admin_tagset);
 	if (ret)
 		return ret;
@@ -1261,8 +1265,8 @@  static int apple_nvme_alloc_tagsets(struct apple_nvme *anv)
 	ret = blk_mq_alloc_tag_set(&anv->tagset);
 	if (ret)
 		return ret;
-	ret = devm_add_action_or_reset(
-		anv->dev, (void (*)(void *))blk_mq_free_tag_set, &anv->tagset);
+	ret = devm_add_action_or_reset(anv->dev, devm_apple_nvme_put_tag_set,
+					&anv->tagset);
 	if (ret)
 		return ret;
 
@@ -1363,6 +1367,11 @@  static int apple_nvme_attach_genpd(struct apple_nvme *anv)
 	return 0;
 }
 
+static void devm_apple_nvme_mempool_destroy(void *data)
+{
+	mempool_destroy(data);
+}
+
 static int apple_nvme_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -1460,8 +1469,8 @@  static int apple_nvme_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto put_dev;
 	}
-	ret = devm_add_action_or_reset(
-		anv->dev, (void (*)(void *))mempool_destroy, anv->iod_mempool);
+	ret = devm_add_action_or_reset(anv->dev,
+			devm_apple_nvme_mempool_destroy, anv->iod_mempool);
 	if (ret)
 		goto put_dev;