Skip to content

Commit 99d2cd8

Browse files
committed
gpu: host1x: Factor out __host1x_device_del()
This function is needed in several places, so factor it out. Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent 38d98de commit 99d2cd8

1 file changed

Lines changed: 49 additions & 44 deletions

File tree

‎drivers/gpu/host1x/bus.c‎

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,59 @@ void host1x_bus_exit(void)
279279
bus_unregister(&host1x_bus_type);
280280
}
281281

282+
static void __host1x_device_del(struct host1x_device *device)
283+
{
284+
struct host1x_subdev *subdev, *sd;
285+
struct host1x_client *client, *cl;
286+
287+
mutex_lock(&device->subdevs_lock);
288+
289+
/* unregister subdevices */
290+
list_for_each_entry_safe(subdev, sd, &device->active, list) {
291+
/*
292+
* host1x_subdev_unregister() will remove the client from
293+
* any lists, so we'll need to manually add it back to the
294+
* list of idle clients.
295+
*
296+
* XXX: Alternatively, perhaps don't remove the client from
297+
* any lists in host1x_subdev_unregister() and instead do
298+
* that explicitly from host1x_unregister_client()?
299+
*/
300+
client = subdev->client;
301+
302+
__host1x_subdev_unregister(device, subdev);
303+
304+
/* add the client to the list of idle clients */
305+
mutex_lock(&clients_lock);
306+
list_add_tail(&client->list, &clients);
307+
mutex_unlock(&clients_lock);
308+
}
309+
310+
/* remove subdevices */
311+
list_for_each_entry_safe(subdev, sd, &device->subdevs, list)
312+
host1x_subdev_del(subdev);
313+
314+
mutex_unlock(&device->subdevs_lock);
315+
316+
/* move clients to idle list */
317+
mutex_lock(&clients_lock);
318+
mutex_lock(&device->clients_lock);
319+
320+
list_for_each_entry_safe(client, cl, &device->clients, list)
321+
list_move_tail(&client->list, &clients);
322+
323+
mutex_unlock(&device->clients_lock);
324+
mutex_unlock(&clients_lock);
325+
326+
/* finally remove the device */
327+
list_del_init(&device->list);
328+
}
329+
282330
static void host1x_device_release(struct device *dev)
283331
{
284332
struct host1x_device *device = to_host1x_device(dev);
285333

334+
__host1x_device_del(device);
286335
kfree(device);
287336
}
288337

@@ -350,50 +399,6 @@ static int host1x_device_add(struct host1x *host1x,
350399
static void host1x_device_del(struct host1x *host1x,
351400
struct host1x_device *device)
352401
{
353-
struct host1x_subdev *subdev, *sd;
354-
struct host1x_client *client, *cl;
355-
356-
mutex_lock(&device->subdevs_lock);
357-
358-
/* unregister subdevices */
359-
list_for_each_entry_safe(subdev, sd, &device->active, list) {
360-
/*
361-
* host1x_subdev_unregister() will remove the client from
362-
* any lists, so we'll need to manually add it back to the
363-
* list of idle clients.
364-
*
365-
* XXX: Alternatively, perhaps don't remove the client from
366-
* any lists in host1x_subdev_unregister() and instead do
367-
* that explicitly from host1x_unregister_client()?
368-
*/
369-
client = subdev->client;
370-
371-
__host1x_subdev_unregister(device, subdev);
372-
373-
/* add the client to the list of idle clients */
374-
mutex_lock(&clients_lock);
375-
list_add_tail(&client->list, &clients);
376-
mutex_unlock(&clients_lock);
377-
}
378-
379-
/* remove subdevices */
380-
list_for_each_entry_safe(subdev, sd, &device->subdevs, list)
381-
host1x_subdev_del(subdev);
382-
383-
mutex_unlock(&device->subdevs_lock);
384-
385-
/* move clients to idle list */
386-
mutex_lock(&clients_lock);
387-
mutex_lock(&device->clients_lock);
388-
389-
list_for_each_entry_safe(client, cl, &device->clients, list)
390-
list_move_tail(&client->list, &clients);
391-
392-
mutex_unlock(&device->clients_lock);
393-
mutex_unlock(&clients_lock);
394-
395-
/* finally remove the device */
396-
list_del_init(&device->list);
397402
device_unregister(&device->dev);
398403
}
399404

0 commit comments

Comments
 (0)