Re: [PATCH 02/32] Introduce flexible array struct memcpy() helpers

Keith Packard
2022-05-05T20:09:04Z

[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]

Kees Cook <keescook@chromium.org> writes:

> I don't think I can do a declaration and an expression statement at the
> same time with different scopes, but that would be kind of cool. We did
> just move to c11 to gain the in-loop iterator declarations...

Yeah, you'd end up creating a statement-level macro, and I think that
would have poor syntax:

mem_to_flex_dup(struct something *instance, rc, byte_array,
count, GFP_KERNEL);
if (rc)
return rc;

I bet you've already considered the simpler form:

struct something *instance = mem_to_flex_dup(byte_array, count, GFP_KERNEL);
if (IS_ERR(instance))
return PTR_ERR(instance);

This doesn't allow you to require a new name, so you effectively lose
the check you're trying to insist upon.

Some way to ask the compiler 'is this reference dead?' would be nice --
it knows if a valid pointer was passed to free, or if a variable has not
been initialized, after all; we just need that exposed at the source
level.

--
-keith

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]