Re: [PATCH printk v2 06/26] printk: nbcon: Ensure ownership release on failed emit

From: John Ogness
Date: Wed Feb 21 2024 - 08:23:53 EST


On 2024-02-20, John Ogness <john.ogness@xxxxxxxxxxxxx> wrote:
>> Is there a valid reason when con->write_atomic() would return false
>> and still own the context?
>
> This is driver code, so you must use your imagination. But I thought
> maybe there might be some reason why the driver cannot print the
> message (due to other driver-internal reasons). In this case, it would
> return false even though it never lost ownership.

I have been thinking about this. I think there is nothing useful that
write_atomic() can return. I suggest making it a void return. Then the
driver must print the message if ownership was not lost. This is already
how write() works and I think it is fine.

This simplifies nbcon_emit_next_record() because it can assume
write_atomic() was successful and try to enter the unsafe section for
the @seq update. If ownership was lost, it will be detected here. If
not, the message will be considered handled and @seq is updated.

>> if (WARN_ON_ONCE(!con->write_atomic)) {
>> /*
>> * This function should never be called for legacy consoles.
>> * Handle it as if write_atomic() have lost the ownership
>> * and try to continue.
>> */
>> nbcon_context_release(ctxt);
>> return false;
>> }

I will keep the WARN with a comment similar to your suggestion.

John