Skip to content

Commit c97f6dd

Browse files
committed
hwspinlock/omap: simplify allocation scheme
Instead of allocating every hwspinlock separately, allocate them all in one shot. This both simplifies the driver and helps achieving better slab utilization. Reported-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
1 parent e467b64 commit c97f6dd

1 file changed

Lines changed: 17 additions & 34 deletions

File tree

‎drivers/hwspinlock/omap_hwspinlock.c‎

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct omap_hwspinlock {
5252
struct omap_hwspinlock_state {
5353
int num_locks; /* Total number of locks in system */
5454
void __iomem *io_base; /* Mapped base address */
55+
struct omap_hwspinlock lock[0]; /* Array of 'num_locks' locks */
5556
};
5657

5758
static int omap_hwspinlock_trylock(struct hwspinlock *lock)
@@ -95,7 +96,6 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
9596
{
9697
struct omap_hwspinlock *omap_lock;
9798
struct omap_hwspinlock_state *state;
98-
struct hwspinlock *lock;
9999
struct resource *res;
100100
void __iomem *io_base;
101101
int i, ret;
@@ -104,15 +104,9 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
104104
if (!res)
105105
return -ENODEV;
106106

107-
state = kzalloc(sizeof(*state), GFP_KERNEL);
108-
if (!state)
109-
return -ENOMEM;
110-
111107
io_base = ioremap(res->start, resource_size(res));
112-
if (!io_base) {
113-
ret = -ENOMEM;
114-
goto free_state;
115-
}
108+
if (!io_base)
109+
return -ENOMEM;
116110

117111
/* Determine number of locks */
118112
i = readl(io_base + SYSSTATUS_OFFSET);
@@ -124,7 +118,15 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
124118
goto iounmap_base;
125119
}
126120

127-
state->num_locks = i * 32;
121+
i *= 32; /* actual number of locks in this device */
122+
123+
state = kzalloc(sizeof(*state) + i * sizeof(*omap_lock), GFP_KERNEL);
124+
if (!state) {
125+
ret = -ENOMEM;
126+
goto iounmap_base;
127+
}
128+
129+
state->num_locks = i;
128130
state->io_base = io_base;
129131

130132
platform_set_drvdata(pdev, state);
@@ -136,50 +138,34 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
136138
pm_runtime_enable(&pdev->dev);
137139

138140
for (i = 0; i < state->num_locks; i++) {
139-
omap_lock = kzalloc(sizeof(*omap_lock), GFP_KERNEL);
140-
if (!omap_lock) {
141-
ret = -ENOMEM;
142-
goto free_locks;
143-
}
141+
omap_lock = &state->lock[i];
144142

145143
omap_lock->lock.dev = &pdev->dev;
146144
omap_lock->lock.id = i;
147145
omap_lock->lock.ops = &omap_hwspinlock_ops;
148146
omap_lock->addr = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
149147

150148
ret = hwspin_lock_register(&omap_lock->lock);
151-
if (ret) {
152-
kfree(omap_lock);
149+
if (ret)
153150
goto free_locks;
154-
}
155151
}
156152

157153
return 0;
158154

159155
free_locks:
160-
while (--i >= 0) {
161-
lock = hwspin_lock_unregister(i);
162-
/* this should't happen, but let's give our best effort */
163-
if (!lock) {
164-
dev_err(&pdev->dev, "%s: cleanups failed\n", __func__);
165-
continue;
166-
}
167-
omap_lock = to_omap_hwspinlock(lock);
168-
kfree(omap_lock);
169-
}
156+
while (--i >= 0)
157+
hwspin_lock_unregister(i);
170158
pm_runtime_disable(&pdev->dev);
159+
kfree(state);
171160
iounmap_base:
172161
iounmap(io_base);
173-
free_state:
174-
kfree(state);
175162
return ret;
176163
}
177164

178165
static int omap_hwspinlock_remove(struct platform_device *pdev)
179166
{
180167
struct omap_hwspinlock_state *state = platform_get_drvdata(pdev);
181168
struct hwspinlock *lock;
182-
struct omap_hwspinlock *omap_lock;
183169
int i;
184170

185171
for (i = 0; i < state->num_locks; i++) {
@@ -190,9 +176,6 @@ static int omap_hwspinlock_remove(struct platform_device *pdev)
190176
dev_err(&pdev->dev, "%s: failed on %d\n", __func__, i);
191177
return -EBUSY;
192178
}
193-
194-
omap_lock = to_omap_hwspinlock(lock);
195-
kfree(omap_lock);
196179
}
197180

198181
pm_runtime_disable(&pdev->dev);

0 commit comments

Comments
 (0)