Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit af2a50bb authored by Ian Munsie's avatar Ian Munsie Committed by Michael Ellerman
Browse files

cxl: Fix + cleanup error paths in cxl_dev_context_init



If the cxl_context_alloc() call fails, we return immediately without
releasing the reference on the AFU device, allowing it to leak.

This patch switches to using goto style error handling so that the
device is released in common code for both error paths, and will also
simplify things if we add additional initialisation in this function in
the future.

Signed-off-by: default avatarIan Munsie <imunsie@au1.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 25980013
Loading
Loading
Loading
Loading
+12 −7
Original line number Original line Diff line number Diff line
@@ -25,19 +25,24 @@ struct cxl_context *cxl_dev_context_init(struct pci_dev *dev)


	get_device(&afu->dev);
	get_device(&afu->dev);
	ctx = cxl_context_alloc();
	ctx = cxl_context_alloc();
	if (IS_ERR(ctx))
	if (IS_ERR(ctx)) {
		return ctx;
		rc = PTR_ERR(ctx);
		goto err_dev;
	}


	/* Make it a slave context.  We can promote it later? */
	/* Make it a slave context.  We can promote it later? */
	rc = cxl_context_init(ctx, afu, false, NULL);
	rc = cxl_context_init(ctx, afu, false, NULL);
	if (rc) {
	if (rc)
		kfree(ctx);
		goto err_ctx;
		put_device(&afu->dev);
		return ERR_PTR(-ENOMEM);
	}
	cxl_assign_psn_space(ctx);
	cxl_assign_psn_space(ctx);


	return ctx;
	return ctx;

err_ctx:
	kfree(ctx);
err_dev:
	put_device(&afu->dev);
	return ERR_PTR(rc);
}
}
EXPORT_SYMBOL_GPL(cxl_dev_context_init);
EXPORT_SYMBOL_GPL(cxl_dev_context_init);