diff mbox series

[08/10] soc: fujitsu: hwb: Add release operation

Message ID 20210108105241.1757799-9-misono.tomohiro@jp.fujitsu.com (mailing list archive)
State Changes Requested
Headers show
Series Add Fujitsu A64FX soc entry/hardware barrier driver | expand

Commit Message

Misono Tomohiro Jan. 8, 2021, 10:52 a.m. UTC
Upon release, we cleanup remaining resources/registers if necessary.
This happens when user does not call IOC_BB_FREE properly and the
function will do effectively the same operation as IOC_BB_FREE.

Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
---
 drivers/soc/fujitsu/fujitsu_hwb.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Arnd Bergmann Jan. 8, 2021, 1:25 p.m. UTC | #1
On Fri, Jan 8, 2021 at 11:52 AM Misono Tomohiro
<misono.tomohiro@jp.fujitsu.com> wrote:
>
> Upon release, we cleanup remaining resources/registers if necessary.
> This happens when user does not call IOC_BB_FREE properly and the
> function will do effectively the same operation as IOC_BB_FREE.
>
> Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>

What is the benefit of calling IOC_BB_FREE instead of always relying
on close() to do this? Would it be easier to just not implement IOC_BB_FREE?

      Arnd
Tomohiro Misono Jan. 12, 2021, 10:38 a.m. UTC | #2
> On Fri, Jan 8, 2021 at 11:52 AM Misono Tomohiro
> <misono.tomohiro@jp.fujitsu.com> wrote:
> >
> > Upon release, we cleanup remaining resources/registers if necessary.
> > This happens when user does not call IOC_BB_FREE properly and the
> > function will do effectively the same operation as IOC_BB_FREE.
> >
> > Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
> 
> What is the benefit of calling IOC_BB_FREE instead of always relying
> on close() to do this? Would it be easier to just not implement IOC_BB_FREE?
> 

This is up to applications.
When the application want to reuse barrier driver resource with diffent
barrier settings (i.e. when changing which PEs joinining synchronization),
it can use IOC_BB_FREE rather than close and open device file again.

Regards,
Tomohiro
diff mbox series

Patch

diff --git a/drivers/soc/fujitsu/fujitsu_hwb.c b/drivers/soc/fujitsu/fujitsu_hwb.c
index 1132cb74b13b..46f1f244f93a 100644
--- a/drivers/soc/fujitsu/fujitsu_hwb.c
+++ b/drivers/soc/fujitsu/fujitsu_hwb.c
@@ -796,9 +796,35 @@  static int fujitsu_hwb_dev_open(struct inode *inode, struct file *filp)
 	return 0;
 }
 
+static int fujitsu_hwb_dev_release(struct inode *inode, struct file *filp)
+{
+	struct hwb_private_data *pdata = (struct hwb_private_data *)filp->private_data;
+	struct bb_info *bb_info, *tmp;
+
+	/*
+	 * Cleanup BB if IOC_BB_FREE is not called properly.
+	 * No lock for pdata->bb_list is needed cause there is no one else
+	 */
+	if (!list_empty(&pdata->bb_list)) {
+		pr_warn("free operation is not called properly\n");
+
+		list_for_each_entry_safe(bb_info, tmp, &pdata->bb_list, node) {
+			teardown_bb(bb_info);
+			list_del_init(&bb_info->node);
+			/* 1 put for alloc_bb_info */
+			put_bb_info(bb_info);
+		}
+	}
+
+	kfree(pdata);
+
+	return 0;
+}
+
 static const struct file_operations fujitsu_hwb_dev_fops = {
 	.owner          = THIS_MODULE,
 	.open           = fujitsu_hwb_dev_open,
+	.release        = fujitsu_hwb_dev_release,
 	.unlocked_ioctl = fujitsu_hwb_dev_ioctl,
 };