quirks: use __attribute__(cleanup)

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1184>
This commit is contained in:
Peter Hutterer 2025-04-01 12:10:15 +10:00
parent 0ecd08c134
commit fbc8eb8cb7
3 changed files with 287 additions and 414 deletions

View file

@ -1147,7 +1147,7 @@ quirks_init_subsystem(const char *data_path,
struct libinput *libinput, struct libinput *libinput,
enum quirks_log_type log_type) enum quirks_log_type log_type)
{ {
struct quirks_context *ctx = zalloc(sizeof *ctx); _unref_(quirks_context) *ctx = zalloc(sizeof *ctx);
assert(data_path); assert(data_path);
@ -1163,19 +1163,15 @@ quirks_init_subsystem(const char *data_path,
ctx->dmi = init_dmi(); ctx->dmi = init_dmi();
ctx->dt = init_dt(); ctx->dt = init_dt();
if (!ctx->dmi && !ctx->dt) if (!ctx->dmi && !ctx->dt)
goto error; return NULL;
if (!parse_files(ctx, data_path)) if (!parse_files(ctx, data_path))
goto error; return NULL;
if (override_file && !parse_file(ctx, override_file)) if (override_file && !parse_file(ctx, override_file))
goto error; return NULL;
return ctx; return steal(&ctx);
error:
quirks_context_unref(ctx);
return NULL;
} }
struct quirks_context * struct quirks_context *
@ -1613,7 +1609,6 @@ struct quirks *
quirks_fetch_for_device(struct quirks_context *ctx, quirks_fetch_for_device(struct quirks_context *ctx,
struct udev_device *udev_device) struct udev_device *udev_device)
{ {
struct quirks *q = NULL;
struct section *s; struct section *s;
struct match *m; struct match *m;
@ -1623,7 +1618,7 @@ quirks_fetch_for_device(struct quirks_context *ctx,
qlog_debug(ctx, "%s: fetching quirks\n", qlog_debug(ctx, "%s: fetching quirks\n",
udev_device_get_devnode(udev_device)); udev_device_get_devnode(udev_device));
q = quirks_new(); _unref_(quirks) *q = quirks_new();
m = match_new(udev_device, ctx->dmi, ctx->dt); m = match_new(udev_device, ctx->dmi, ctx->dt);
@ -1634,13 +1629,12 @@ quirks_fetch_for_device(struct quirks_context *ctx,
match_free(m); match_free(m);
if (q->nproperties == 0) { if (q->nproperties == 0) {
quirks_unref(q);
return NULL; return NULL;
} }
list_insert(&ctx->quirks, &q->link); list_insert(&ctx->quirks, &q->link);
return q; return steal(&q);
} }
static inline struct property * static inline struct property *

View file

@ -204,6 +204,8 @@ quirks_fetch_for_device(struct quirks_context *ctx,
struct quirks * struct quirks *
quirks_unref(struct quirks *q); quirks_unref(struct quirks *q);
DEFINE_UNREF_CLEANUP_FUNC(quirks);
/** /**
* Returns true if the given quirk applies is in this quirk list. * Returns true if the given quirk applies is in this quirk list.
*/ */

File diff suppressed because it is too large Load diff