diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2013-09-16 16:44:46 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-10-03 19:00:52 -0400 |
commit | e036cc5727eb6d471442d2a9218990aa11215400 (patch) | |
tree | 0eb7788e41d4631828374da6320fadd85fa1b93a | |
parent | d7173493683853047d6efc8d4454c70469a7b033 (diff) |
mei: simplify mei_open error handling
1. Perform simple checks first and only then attempt to allocate cl structure.
2. Remove open_handler_count test, this is already checked in mei_cl_link function
3. return -EMFILE instead of -ENOENT as expected by user space
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/misc/mei/client.c | 8 | ||||
-rw-r--r-- | drivers/misc/mei/main.c | 31 |
2 files changed, 21 insertions, 18 deletions
diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c index fbd319c506e6..88770e040dd1 100644 --- a/drivers/misc/mei/client.c +++ b/drivers/misc/mei/client.c | |||
@@ -288,7 +288,13 @@ int mei_cl_link(struct mei_cl *cl, int id) | |||
288 | 288 | ||
289 | if (id >= MEI_CLIENTS_MAX) { | 289 | if (id >= MEI_CLIENTS_MAX) { |
290 | dev_err(&dev->pdev->dev, "id exceded %d", MEI_CLIENTS_MAX) ; | 290 | dev_err(&dev->pdev->dev, "id exceded %d", MEI_CLIENTS_MAX) ; |
291 | return -ENOENT; | 291 | return -EMFILE; |
292 | } | ||
293 | |||
294 | if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { | ||
295 | dev_err(&dev->pdev->dev, "open_handle_count exceded %d", | ||
296 | MEI_MAX_OPEN_HANDLE_COUNT); | ||
297 | return -EMFILE; | ||
292 | } | 298 | } |
293 | 299 | ||
294 | if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { | 300 | if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { |
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index c71420ef1e37..87ab5ca1d633 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c | |||
@@ -60,48 +60,45 @@ static int mei_open(struct inode *inode, struct file *file) | |||
60 | 60 | ||
61 | int err; | 61 | int err; |
62 | 62 | ||
63 | err = -ENODEV; | ||
64 | if (!misc->parent) | 63 | if (!misc->parent) |
65 | goto out; | 64 | return -ENODEV; |
66 | 65 | ||
67 | pdev = container_of(misc->parent, struct pci_dev, dev); | 66 | pdev = container_of(misc->parent, struct pci_dev, dev); |
68 | 67 | ||
69 | dev = pci_get_drvdata(pdev); | 68 | dev = pci_get_drvdata(pdev); |
70 | if (!dev) | 69 | if (!dev) |
71 | goto out; | 70 | return -ENODEV; |
72 | 71 | ||
73 | mutex_lock(&dev->device_lock); | 72 | mutex_lock(&dev->device_lock); |
74 | err = -ENOMEM; | 73 | |
75 | cl = mei_cl_allocate(dev); | 74 | cl = NULL; |
76 | if (!cl) | ||
77 | goto out_unlock; | ||
78 | 75 | ||
79 | err = -ENODEV; | 76 | err = -ENODEV; |
80 | if (dev->dev_state != MEI_DEV_ENABLED) { | 77 | if (dev->dev_state != MEI_DEV_ENABLED) { |
81 | dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n", | 78 | dev_dbg(&dev->pdev->dev, "dev_state != MEI_ENABLED dev_state = %s\n", |
82 | mei_dev_state_str(dev->dev_state)); | 79 | mei_dev_state_str(dev->dev_state)); |
83 | goto out_unlock; | 80 | goto err_unlock; |
84 | } | ||
85 | err = -EMFILE; | ||
86 | if (dev->open_handle_count >= MEI_MAX_OPEN_HANDLE_COUNT) { | ||
87 | dev_err(&dev->pdev->dev, "open_handle_count exceded %d", | ||
88 | MEI_MAX_OPEN_HANDLE_COUNT); | ||
89 | goto out_unlock; | ||
90 | } | 81 | } |
91 | 82 | ||
83 | err = -ENOMEM; | ||
84 | cl = mei_cl_allocate(dev); | ||
85 | if (!cl) | ||
86 | goto err_unlock; | ||
87 | |||
88 | /* open_handle_count check is handled in the mei_cl_link */ | ||
92 | err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); | 89 | err = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); |
93 | if (err) | 90 | if (err) |
94 | goto out_unlock; | 91 | goto err_unlock; |
95 | 92 | ||
96 | file->private_data = cl; | 93 | file->private_data = cl; |
94 | |||
97 | mutex_unlock(&dev->device_lock); | 95 | mutex_unlock(&dev->device_lock); |
98 | 96 | ||
99 | return nonseekable_open(inode, file); | 97 | return nonseekable_open(inode, file); |
100 | 98 | ||
101 | out_unlock: | 99 | err_unlock: |
102 | mutex_unlock(&dev->device_lock); | 100 | mutex_unlock(&dev->device_lock); |
103 | kfree(cl); | 101 | kfree(cl); |
104 | out: | ||
105 | return err; | 102 | return err; |
106 | } | 103 | } |
107 | 104 | ||