Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35277268 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

spmi: prevent showing the address of spmidev



Creating devices with the address of the container spmidev is not
indicative of the actual hardware device it represents.

Instead use an unique id to indicate the device it represents.

CRs-Fixed: 1024197
Change-Id: Id18e2a19f4fa1249901a3f275defa8f589270d69
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent cc957303
Loading
Loading
Loading
Loading
+16 −4
Original line number Original line Diff line number Diff line
/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2014, 2016 The Linux Foundation. All rights reserved.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * it under the terms of the GNU General Public License version 2 and
@@ -32,6 +32,7 @@ struct spmii_boardinfo {
static DEFINE_MUTEX(board_lock);
static DEFINE_MUTEX(board_lock);
static LIST_HEAD(board_list);
static LIST_HEAD(board_list);
static DEFINE_IDR(ctrl_idr);
static DEFINE_IDR(ctrl_idr);
static DEFINE_IDA(spmi_devid_ida);
static struct device_type spmi_dev_type;
static struct device_type spmi_dev_type;
static struct device_type spmi_ctrl_type;
static struct device_type spmi_ctrl_type;


@@ -229,22 +230,32 @@ int spmi_add_device(struct spmi_device *spmidev)
{
{
	int rc;
	int rc;
	struct device *dev = get_valid_device(spmidev);
	struct device *dev = get_valid_device(spmidev);
	int id;


	if (!dev) {
	if (!dev) {
		pr_err("invalid SPMI device\n");
		pr_err("invalid SPMI device\n");
		return -EINVAL;
		return -EINVAL;
	}
	}


	id = ida_simple_get(&spmi_devid_ida, 0, 0, GFP_KERNEL);
	if (id < 0) {
		pr_err("No id available, status = %d\n", id);
		return id;
	}

	/* Set the device name */
	/* Set the device name */
	dev_set_name(dev, "%s-%p", spmidev->name, spmidev);
	spmidev->id = id;
	dev_set_name(dev, "%s-%d", spmidev->name, spmidev->id);


	/* Device may be bound to an active driver when this returns */
	/* Device may be bound to an active driver when this returns */
	rc = device_add(dev);
	rc = device_add(dev);


	if (rc < 0)
	if (rc < 0) {
		ida_simple_remove(&spmi_devid_ida, spmidev->id);
		dev_err(dev, "Can't add %s, status %d\n", dev_name(dev), rc);
		dev_err(dev, "Can't add %s, status %d\n", dev_name(dev), rc);
	else
	} else {
		dev_dbg(dev, "device %s registered\n", dev_name(dev));
		dev_dbg(dev, "device %s registered\n", dev_name(dev));
	}


	return rc;
	return rc;
}
}
@@ -292,6 +303,7 @@ EXPORT_SYMBOL_GPL(spmi_new_device);
void spmi_remove_device(struct spmi_device *spmi_dev)
void spmi_remove_device(struct spmi_device *spmi_dev)
{
{
	device_unregister(&spmi_dev->dev);
	device_unregister(&spmi_dev->dev);
	ida_simple_remove(&spmi_devid_ida, spmi_dev->id);
}
}
EXPORT_SYMBOL_GPL(spmi_remove_device);
EXPORT_SYMBOL_GPL(spmi_remove_device);


+4 −1
Original line number Original line Diff line number Diff line
/* Copyright (c) 2012-2014 The Linux Foundation. All rights reserved.
/* Copyright (c) 2012-2014, 2016 The Linux Foundation. All rights reserved.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * it under the terms of the GNU General Public License version 2 and
@@ -120,6 +120,8 @@ struct spmi_resource {
 *  @dev_node: array of SPMI resources when used with spmi-dev-container.
 *  @dev_node: array of SPMI resources when used with spmi-dev-container.
 *  @num_dev_node: number of device_node structures.
 *  @num_dev_node: number of device_node structures.
 *  @sid: Slave Identifier.
 *  @sid: Slave Identifier.
 *  @id: Unique identifier to differentiate from other spmi devices with
 *	 possibly same name.
 */
 */
struct spmi_device {
struct spmi_device {
	struct device		dev;
	struct device		dev;
@@ -129,6 +131,7 @@ struct spmi_device {
	struct spmi_resource	*dev_node;
	struct spmi_resource	*dev_node;
	u32			num_dev_node;
	u32			num_dev_node;
	u8			sid;
	u8			sid;
	int			id;
};
};
#define to_spmi_device(d) container_of(d, struct spmi_device, dev)
#define to_spmi_device(d) container_of(d, struct spmi_device, dev)