Message ID | 20220314160108.1440470-1-armbru@redhat.com (mailing list archive) |
---|---|
Headers | show |
Series | Use g_new() & friends where that makes obvious | expand |
On 14/3/22 17:01, Markus Armbruster wrote: > g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer, > for two reasons. One, it catches multiplication overflowing size_t. > Two, it returns T * rather than void *, which lets the compiler catch > more type errors. > > This series only touches allocations with size arguments of the form > sizeof(T). It's mechanical, except for a tiny fix in PATCH 2. > > PATCH 1 adds the Coccinelle script. > > PATCH 2 cleans up the virtio-9p subsystem, and fixes a harmless typing > error uncovered by the cleanup. > > PATCH 3 cleans up everything else. I started to split it up, but > splitting is a lot of decisions, and I just can't see the value. > > For instance, MAINTAINERS tells me to split for subsystem "virtio", > patching > > hw/char/virtio-serial-bus.c > hw/display/virtio-gpu.c > hw/net/virtio-net.c > hw/virtio/virtio-crypto.c > hw/virtio/virtio-iommu.c > hw/virtio/virtio.c > > But it also tells me to split for subsystem "Character devices", > patching > > hw/char/parallel.c | 2 +- > hw/char/riscv_htif.c | 2 +- > hw/char/virtio-serial-bus.c | 6 +- > > and for subsystem "Network devices", patching > > hw/net/virtio-net.c > > and for subsystem "virtio-gpu", patching > > hw/display/virtio-gpu.c > > I guess I'd go with "virtio". Six files down, 103 to go. Thanks, but > no thanks. > > Since the transformation is local to a function call, dropping is > completely safe. We can deal with conflicts by dropping conflicting > hunks, with "git-pull -s recursive -X ours". Or drop entire files > with conflicts. > > If you want me to split off certain parts, please tell me exactly what > you want split off, and I'll gladly do the splitting. I don't mind > the splitting part, I do mind the *thinking* part. > > Markus Armbruster (3): > scripts/coccinelle: New use-g_new-etc.cocci > 9pfs: Use g_new() & friends where that makes obvious sense > Use g_new() & friends where that makes obvious sense Series: Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>