/* Return the relative path of a possible device node. Non-default names may need to allocate a memory to compose a name. This memory is returned in tmp and needs to be freed by the caller.  */
const char* device_get_devnode(struct device *dev, mode_t *mode, const char **tmp)
/* Return the relative path of a possible device node. Non-default names may need to allocate a memory to compose a name. This memory is returned in tmp and needs to be freed by the caller.  */
const char* device_get_devnode(struct device *dev, mode_t *mode, const char **tmp)
{
	char *s;
	*tmp = NULL;
	if (dev->type && dev->type->devnode)
		*tmp = dev->type->devnode(dev, mode);
	if (*tmp)
		return *tmp;
	if (dev->class && dev->class->devnode)
		*tmp = dev->class->devnode(dev, mode);
	if (*tmp)
		return *tmp;
	if (strchr(dev_name(dev), '!') == NULL)
		return dev_name(dev);
	*tmp = kstrdup(dev_name(dev), GFP_KERNEL);
	if (!*tmp)
		return NULL;
	while ((s = strchr(*tmp, '!')))
		s[0] = '/';
	return *tmp;
}