Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+49 -44
+49 -44
drivers/gpu/host1x/bus.c
··· 279 279 bus_unregister(&host1x_bus_type); 280 280 } 281 281 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 + 282 330 static void host1x_device_release(struct device *dev) 283 331 { 284 332 struct host1x_device *device = to_host1x_device(dev); 285 333 334 + __host1x_device_del(device); 286 335 kfree(device); 287 336 } 288 337 ··· 399 350 static void host1x_device_del(struct host1x *host1x, 400 351 struct host1x_device *device) 401 352 { 402 - struct host1x_subdev *subdev, *sd; 403 - struct host1x_client *client, *cl; 404 - 405 - mutex_lock(&device->subdevs_lock); 406 - 407 - /* unregister subdevices */ 408 - list_for_each_entry_safe(subdev, sd, &device->active, list) { 409 - /* 410 - * host1x_subdev_unregister() will remove the client from 411 - * any lists, so we'll need to manually add it back to the 412 - * list of idle clients. 413 - * 414 - * XXX: Alternatively, perhaps don't remove the client from 415 - * any lists in host1x_subdev_unregister() and instead do 416 - * that explicitly from host1x_unregister_client()? 417 - */ 418 - client = subdev->client; 419 - 420 - __host1x_subdev_unregister(device, subdev); 421 - 422 - /* add the client to the list of idle clients */ 423 - mutex_lock(&clients_lock); 424 - list_add_tail(&client->list, &clients); 425 - mutex_unlock(&clients_lock); 426 - } 427 - 428 - /* remove subdevices */ 429 - list_for_each_entry_safe(subdev, sd, &device->subdevs, list) 430 - host1x_subdev_del(subdev); 431 - 432 - mutex_unlock(&device->subdevs_lock); 433 - 434 - /* move clients to idle list */ 435 - mutex_lock(&clients_lock); 436 - mutex_lock(&device->clients_lock); 437 - 438 - list_for_each_entry_safe(client, cl, &device->clients, list) 439 - list_move_tail(&client->list, &clients); 440 - 441 - mutex_unlock(&device->clients_lock); 442 - mutex_unlock(&clients_lock); 443 - 444 - /* finally remove the device */ 445 - list_del_init(&device->list); 446 353 device_unregister(&device->dev); 447 354 } 448 355