vfio-ccw: Introduce new helper functions to free/destroy regions

Consolidate some of the cleanup code for the regions, so that
as more are added we reduce code duplication.

Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <20200505122745.53208-2-farman@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
This commit is contained in:
Farhan Ali 2020-05-05 14:27:38 +02:00 коммит произвёл Cornelia Huck
Родитель 430220b0bb
Коммит 9a44ce6c9b
1 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -116,6 +116,14 @@ static void vfio_ccw_sch_irq(struct subchannel *sch)
vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INTERRUPT); vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INTERRUPT);
} }
static void vfio_ccw_free_regions(struct vfio_ccw_private *private)
{
if (private->cmd_region)
kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region);
if (private->io_region)
kmem_cache_free(vfio_ccw_io_region, private->io_region);
}
static int vfio_ccw_sch_probe(struct subchannel *sch) static int vfio_ccw_sch_probe(struct subchannel *sch)
{ {
struct pmcw *pmcw = &sch->schib.pmcw; struct pmcw *pmcw = &sch->schib.pmcw;
@ -181,10 +189,7 @@ out_disable:
cio_disable_subchannel(sch); cio_disable_subchannel(sch);
out_free: out_free:
dev_set_drvdata(&sch->dev, NULL); dev_set_drvdata(&sch->dev, NULL);
if (private->cmd_region) vfio_ccw_free_regions(private);
kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region);
if (private->io_region)
kmem_cache_free(vfio_ccw_io_region, private->io_region);
kfree(private->cp.guest_cp); kfree(private->cp.guest_cp);
kfree(private); kfree(private);
return ret; return ret;
@ -200,8 +205,7 @@ static int vfio_ccw_sch_remove(struct subchannel *sch)
dev_set_drvdata(&sch->dev, NULL); dev_set_drvdata(&sch->dev, NULL);
kmem_cache_free(vfio_ccw_cmd_region, private->cmd_region); vfio_ccw_free_regions(private);
kmem_cache_free(vfio_ccw_io_region, private->io_region);
kfree(private->cp.guest_cp); kfree(private->cp.guest_cp);
kfree(private); kfree(private);
@ -304,6 +308,12 @@ static void vfio_ccw_debug_exit(void)
debug_unregister(vfio_ccw_debug_trace_id); debug_unregister(vfio_ccw_debug_trace_id);
} }
static void vfio_ccw_destroy_regions(void)
{
kmem_cache_destroy(vfio_ccw_cmd_region);
kmem_cache_destroy(vfio_ccw_io_region);
}
static int __init vfio_ccw_sch_init(void) static int __init vfio_ccw_sch_init(void)
{ {
int ret; int ret;
@ -346,8 +356,7 @@ static int __init vfio_ccw_sch_init(void)
return ret; return ret;
out_err: out_err:
kmem_cache_destroy(vfio_ccw_cmd_region); vfio_ccw_destroy_regions();
kmem_cache_destroy(vfio_ccw_io_region);
destroy_workqueue(vfio_ccw_work_q); destroy_workqueue(vfio_ccw_work_q);
vfio_ccw_debug_exit(); vfio_ccw_debug_exit();
return ret; return ret;
@ -357,8 +366,7 @@ static void __exit vfio_ccw_sch_exit(void)
{ {
css_driver_unregister(&vfio_ccw_sch_driver); css_driver_unregister(&vfio_ccw_sch_driver);
isc_unregister(VFIO_CCW_ISC); isc_unregister(VFIO_CCW_ISC);
kmem_cache_destroy(vfio_ccw_io_region); vfio_ccw_destroy_regions();
kmem_cache_destroy(vfio_ccw_cmd_region);
destroy_workqueue(vfio_ccw_work_q); destroy_workqueue(vfio_ccw_work_q);
vfio_ccw_debug_exit(); vfio_ccw_debug_exit();
} }