Commit 0ca4da24 authored by Srinivas Pandruvada's avatar Srinivas Pandruvada Committed by Jia, Yingbao
Browse files

platform/x86: ISST: Simplify isst_misc_reg() and isst_misc_unreg()

mainline inclusion
from mainline-v6.11
commit 440814caedb0e33c56f0478d7fa5b54479013904
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/IB6QD3
CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=440814caedb0e33c56f0478d7fa5b54479013904



-------------------------------------------------

Intel-SIG: commit 440814caedb0 platform/x86: ISST: Simplify isst_misc_reg() and isst_misc_unreg().
Backport Intel speed select ISST driver bugfix from upstream 6.11.

After commit '1630dc626c87 ("platform/x86: ISST: Add model specific
loading for common module")' isst_misc_reg() and isst_misc_unreg() can be
simplified. Since these functions are only called during module_init()
and module_exit() respectively, there is no contention while calling
misc_register()/misc_deregister or isst_if_cpu_info_init()/
isst_if_cpu_info_exit().

Hence remove mutex and reference counting.

Signed-off-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240731184256.1852840-1-srinivas.pandruvada@linux.intel.com


Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
[ yingbao jia: amend commit log ]
Signed-off-by: default avataryingbao jia <yingbao.jia@intel.com>
parent 3771612b
Loading
Loading
Loading
Loading
+11 −31
Original line number Diff line number Diff line
@@ -653,10 +653,6 @@ static long isst_if_def_ioctl(struct file *file, unsigned int cmd,

/* Lock to prevent module registration when already opened by user space */
static DEFINE_MUTEX(punit_misc_dev_open_lock);
/* Lock to allow one share misc device for all ISST interace */
static DEFINE_MUTEX(punit_misc_dev_reg_lock);
static int misc_usage_count;
static int misc_device_ret;
static int misc_device_open;

static int isst_if_open(struct inode *inode, struct file *file)
@@ -722,40 +718,24 @@ static struct miscdevice isst_if_char_driver = {

static int isst_misc_reg(void)
{
	mutex_lock(&punit_misc_dev_reg_lock);
	if (misc_device_ret)
		goto unlock_exit;
	int ret;

	if (!misc_usage_count) {
		misc_device_ret = isst_if_cpu_info_init();
		if (misc_device_ret)
			goto unlock_exit;
	ret = isst_if_cpu_info_init();
	if (ret)
		return ret;

		misc_device_ret = misc_register(&isst_if_char_driver);
		if (misc_device_ret) {
	ret = misc_register(&isst_if_char_driver);
	if (ret)
		isst_if_cpu_info_exit();
			goto unlock_exit;
		}
	}
	misc_usage_count++;

unlock_exit:
	mutex_unlock(&punit_misc_dev_reg_lock);

	return misc_device_ret;
	return ret;
}

static void isst_misc_unreg(void)
{
	mutex_lock(&punit_misc_dev_reg_lock);
	if (misc_usage_count)
		misc_usage_count--;
	if (!misc_usage_count && !misc_device_ret) {
	misc_deregister(&isst_if_char_driver);
	isst_if_cpu_info_exit();
}
	mutex_unlock(&punit_misc_dev_reg_lock);
}

/**
 * isst_if_cdev_register() - Register callback for IOCTL