@@ -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,
};
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(+)