solve the kobject_get_path undefined in gki build

TP:
The kobject_get_path function is not in Google's
whitelist, so reimplement the function.

Change-Id: I162e4d91cc5d8e918da1e7497fba7d48df9e86ef
Reviewed-on: https://gerrit.mot.com/2076930
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Jichao Zou <zoujc@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
litong20 2021-09-26 20:35:10 +08:00 • committed by litong
commit a6e5f91024

View file

@ -137,6 +137,41 @@ TOUCH_MMI_GET_ATTR_WO(refresh_rate);
TOUCH_MMI_GET_ATTR_WO(charger_mode);
TOUCH_MMI_GET_ATTR_WO(update_baseline);
static char *ts_mmi_kobject_get_path(struct kobject *kobj, gfp_t gfp_mask)
{
char *path;
int len = 1;
struct kobject *parent = kobj;
do {
if (parent->name == NULL) {
len = 0;
break;
}
len += strlen(parent->name) + 1;
parent = parent->parent;
} while (parent);
if (len == 0)
return NULL;
path = kzalloc(len, gfp_mask);
if (!path)
return NULL;
--len;
for (parent = kobj; parent; parent = parent->parent) {
int cur = strlen(parent->name);
len -= cur;
memcpy(path + len, parent->name, cur);
*(path + --len) = '/';
}
pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobj->name,
kobj, __func__, path);
return path;
}
static ssize_t path_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@ -148,7 +183,12 @@ static ssize_t path_show(struct device *dev,
dev_err(dev, "touchscreen device pointer is NULL\n");
return (ssize_t)0;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
path = ts_mmi_kobject_get_path(&DEV_MMI->kobj, GFP_KERNEL);
#else
path = kobject_get_path(&DEV_MMI->kobj, GFP_KERNEL);
#endif
blen = scnprintf(buf, PAGE_SIZE, "%s", path ? path : "na");
kfree(path);
return blen;