msm: mdm: Fix bug in retrieving driver's private data
The current code retrieves driver's private data based on platform
device id or device file name. The device id match is broken
for targets which has only one external modem (platform device
id = -1).
Use device's private data and file's private data fields for
storing the driver's private data.
CRs-Fixed: 451830
Change-Id: I080ef86cce8d346c0b3e380432712dde07b64aea
Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org>
diff --git a/arch/arm/mach-msm/mdm_common.c b/arch/arm/mach-msm/mdm_common.c
index 536e859..f10d9b1 100644
--- a/arch/arm/mach-msm/mdm_common.c
+++ b/arch/arm/mach-msm/mdm_common.c
@@ -138,41 +138,6 @@
spin_unlock_irqrestore(&mdm_devices_lock, flags);
}
-struct mdm_device *mdm_get_device_by_device_id(int device_id)
-{
- unsigned long flags;
- struct mdm_device *mdev = NULL;
-
- spin_lock_irqsave(&mdm_devices_lock, flags);
- list_for_each_entry(mdev, &mdm_devices, link) {
- if (mdev && mdev->mdm_data.device_id == device_id) {
- spin_unlock_irqrestore(&mdm_devices_lock, flags);
- return mdev;
- }
- }
- spin_unlock_irqrestore(&mdm_devices_lock, flags);
- return NULL;
-}
-
-struct mdm_device *mdm_get_device_by_name(const char *name)
-{
- unsigned long flags;
- struct mdm_device *mdev;
-
- if (!name)
- return NULL;
- spin_lock_irqsave(&mdm_devices_lock, flags);
- list_for_each_entry(mdev, &mdm_devices, link) {
- if (mdev && !strncmp(mdev->device_name, name,
- sizeof(mdev->device_name))) {
- spin_unlock_irqrestore(&mdm_devices_lock, flags);
- return mdev;
- }
- }
- spin_unlock_irqrestore(&mdm_devices_lock, flags);
- return NULL;
-}
-
/* If the platform's cascading_ssr flag is set, the subsystem
* restart module will restart the other modems so stop
* monitoring them as well.
@@ -396,19 +361,13 @@
}
}
-long mdm_modem_ioctl(struct file *filp, unsigned int cmd,
+static long mdm_modem_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
int status, ret = 0;
- struct mdm_device *mdev;
+ struct mdm_device *mdev = filp->private_data;
struct mdm_modem_drv *mdm_drv;
- mdev = mdm_get_device_by_name(filp->f_path.dentry->d_iname);
- if (!mdev) {
- pr_err("%s: mdm_device not found\n", __func__);
- return -ENODEV;
- }
-
if (_IOC_TYPE(cmd) != CHARM_CODE) {
pr_err("%s: invalid ioctl code to mdm id %d\n",
__func__, mdev->mdm_data.device_id);
@@ -563,6 +522,11 @@
/* set the mdm_device as the file's private data */
static int mdm_modem_open(struct inode *inode, struct file *file)
{
+ struct miscdevice *misc = file->private_data;
+ struct mdm_device *mdev = container_of(misc,
+ struct mdm_device, misc_device);
+
+ file->private_data = mdev;
return 0;
}
@@ -1075,6 +1039,7 @@
goto init_err;
}
+ platform_set_drvdata(pdev, mdev);
mdm_modem_initialize_data(pdev, mdev);
if (mdm_ops->debug_state_changed_cb)
@@ -1121,10 +1086,7 @@
static int __devexit mdm_modem_remove(struct platform_device *pdev)
{
int ret;
- struct mdm_device *mdev = mdm_get_device_by_device_id(pdev->id);
-
- if (!mdev)
- return -ENODEV;
+ struct mdm_device *mdev = platform_get_drvdata(pdev);
pr_debug("%s: removing device id %d\n",
__func__, mdev->mdm_data.device_id);
@@ -1138,9 +1100,7 @@
static void mdm_modem_shutdown(struct platform_device *pdev)
{
struct mdm_modem_drv *mdm_drv;
- struct mdm_device *mdev = mdm_get_device_by_device_id(pdev->id);
- if (!mdev)
- return;
+ struct mdm_device *mdev = platform_get_drvdata(pdev);
pr_debug("%s: shutting down device id %d\n",
__func__, mdev->mdm_data.device_id);