Changeset a0d4afe in mainline for uspace/srv/hid/display/seat.c


Ignore:
Timestamp:
2023-01-18T16:51:44Z (16 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3e7e226
Parents:
b0ae23f
Message:

Make sure input device configuration is destroyed together with seat

When a seat is destroyed without unassigning devices first, this causes
a dangling seat pointer that would cause the display server to crash
if the corresponding device generates an event.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/seat.c

    rb0ae23f ra0d4afe  
    4343#include "cursor.h"
    4444#include "display.h"
     45#include "idevcfg.h"
    4546#include "seat.h"
    4647#include "window.h"
     
    7980        }
    8081
     82        list_initialize(&seat->idevcfgs);
     83
    8184        ds_display_add_seat(display, seat);
    8285        seat->pntpos.x = 0;
     
    9699void ds_seat_destroy(ds_seat_t *seat)
    97100{
     101        ds_idevcfg_t *idevcfg;
     102
     103        /* Remove all input device configuration entries pointing to this seat */
     104        idevcfg = ds_seat_first_idevcfg(seat);
     105        while (idevcfg != NULL) {
     106                ds_idevcfg_destroy(idevcfg);
     107                idevcfg = ds_seat_first_idevcfg(seat);
     108        }
     109
    98110        ds_display_remove_seat(seat);
     111
    99112        free(seat->name);
    100113        free(seat);
     
    549562}
    550563
     564/** Add input device configuration entry to seat.
     565 *
     566 * @param seat Seat
     567 * @param idevcfg Input device configuration
     568 */
     569void ds_seat_add_idevcfg(ds_seat_t *seat, ds_idevcfg_t *idevcfg)
     570{
     571        assert(idevcfg->seat == NULL);
     572        assert(!link_used(&idevcfg->lseatidcfgs));
     573
     574        idevcfg->seat = seat;
     575        list_append(&idevcfg->lseatidcfgs, &seat->idevcfgs);
     576}
     577
     578/** Remove input device configuration entry from seat.
     579 *
     580 * @param idevcfg Input device configuration entry
     581 */
     582void ds_seat_remove_idevcfg(ds_idevcfg_t *idevcfg)
     583{
     584        list_remove(&idevcfg->lseatidcfgs);
     585        idevcfg->seat = NULL;
     586}
     587
     588/** Get first input device configuration entry in seat.
     589 *
     590 * @param disp Display
     591 * @return First input device configuration entry or @c NULL if there is none
     592 */
     593ds_idevcfg_t *ds_seat_first_idevcfg(ds_seat_t *seat)
     594{
     595        link_t *link = list_first(&seat->idevcfgs);
     596
     597        if (link == NULL)
     598                return NULL;
     599
     600        return list_get_instance(link, ds_idevcfg_t, lseatidcfgs);
     601}
     602
     603/** Get next input device configuration entry in seat.
     604 *
     605 * @param idevcfg Current input device configuration entry
     606 * @return Next input device configuration entry or @c NULL if there is none
     607 */
     608ds_idevcfg_t *ds_seat_next_idevcfg(ds_idevcfg_t *idevcfg)
     609{
     610        link_t *link = list_next(&idevcfg->lseatidcfgs, &idevcfg->seat->idevcfgs);
     611
     612        if (link == NULL)
     613                return NULL;
     614
     615        return list_get_instance(link, ds_idevcfg_t, lseatidcfgs);
     616}
     617
    551618/** @}
    552619 */
Note: See TracChangeset for help on using the changeset viewer.