Changeset a0d4afe in mainline


Ignore:
Timestamp:
2023-01-18T16:51:44Z (15 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.

Location:
uspace/srv/hid/display
Files:
6 edited

Legend:

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

    rb0ae23f ra0d4afe  
    796796{
    797797        assert(idevcfg->display == NULL);
    798         assert(!link_used(&idevcfg->lidevcfgs));
     798        assert(!link_used(&idevcfg->ldispidcfgs));
    799799
    800800        idevcfg->display = disp;
    801         list_append(&idevcfg->lidevcfgs, &disp->idevcfgs);
     801        list_append(&idevcfg->ldispidcfgs, &disp->idevcfgs);
    802802}
    803803
     
    808808void ds_display_remove_idevcfg(ds_idevcfg_t *idevcfg)
    809809{
    810         list_remove(&idevcfg->lidevcfgs);
     810        list_remove(&idevcfg->ldispidcfgs);
    811811        idevcfg->display = NULL;
    812812}
     
    824824                return NULL;
    825825
    826         return list_get_instance(link, ds_idevcfg_t, lidevcfgs);
     826        return list_get_instance(link, ds_idevcfg_t, ldispidcfgs);
    827827}
    828828
     
    834834ds_idevcfg_t *ds_display_next_idevcfg(ds_idevcfg_t *idevcfg)
    835835{
    836         link_t *link = list_next(&idevcfg->lidevcfgs, &idevcfg->display->idevcfgs);
    837 
    838         if (link == NULL)
    839                 return NULL;
    840 
    841         return list_get_instance(link, ds_idevcfg_t, lidevcfgs);
     836        link_t *link = list_next(&idevcfg->ldispidcfgs, &idevcfg->display->idevcfgs);
     837
     838        if (link == NULL)
     839                return NULL;
     840
     841        return list_get_instance(link, ds_idevcfg_t, ldispidcfgs);
    842842}
    843843
  • uspace/srv/hid/display/idevcfg.c

    rb0ae23f ra0d4afe  
    4141#include "display.h"
    4242#include "idevcfg.h"
     43#include "seat.h"
    4344
    4445/** Create input device configuration entry.
     
    6162
    6263        idevcfg->svc_id = svc_id;
    63         idevcfg->seat = seat;
     64        ds_seat_add_idevcfg(seat, idevcfg);
    6465
    6566        ds_display_add_idevcfg(display, idevcfg);
     
    7576{
    7677        ds_display_remove_idevcfg(idevcfg);
     78        ds_seat_remove_idevcfg(idevcfg);
    7779        free(idevcfg);
    7880}
  • 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 */
  • uspace/srv/hid/display/seat.h

    rb0ae23f ra0d4afe  
    5858extern void ds_seat_set_wm_cursor(ds_seat_t *, ds_cursor_t *);
    5959extern errno_t ds_seat_paint_pointer(ds_seat_t *, gfx_rect_t *);
     60extern void ds_seat_add_idevcfg(ds_seat_t *, ds_idevcfg_t *);
     61extern void ds_seat_remove_idevcfg(ds_idevcfg_t *);
     62extern ds_idevcfg_t *ds_seat_first_idevcfg(ds_seat_t *);
     63extern ds_idevcfg_t *ds_seat_next_idevcfg(ds_idevcfg_t *);
    6064
    6165#endif
  • uspace/srv/hid/display/types/display/idevcfg.h

    rb0ae23f ra0d4afe  
    4545        struct ds_display *display;
    4646        /** Link to display->idevcfgs */
    47         link_t lidevcfgs;
     47        link_t ldispidcfgs;
     48        /** Link to seat->idevcfgs */
     49        link_t lseatidcfgs;
    4850        /** Service ID */
    4951        service_id_t svc_id;
  • uspace/srv/hid/display/types/display/seat.h

    rb0ae23f ra0d4afe  
    5252        /** Seat name */
    5353        char *name;
     54        /** Input device configurations mapping to this seat */
     55        list_t idevcfgs;
    5456        /** Window this seat is focused on */
    5557        struct ds_window *focus;
Note: See TracChangeset for help on using the changeset viewer.