Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp11668867rwl; Tue, 3 Jan 2023 03:01:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXtS58vKprB7mYAKRwmvyjcj5q4iGyfAgVEOEREJ7gFCU0gkr4swXwz9IgPVlRvKCJN1bwn3 X-Received: by 2002:a62:8208:0:b0:580:d2d3:ef18 with SMTP id w8-20020a628208000000b00580d2d3ef18mr38978847pfd.29.1672743671564; Tue, 03 Jan 2023 03:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672743671; cv=none; d=google.com; s=arc-20160816; b=S4NXfHAa+AQWc0Sh0jkeBYM0LO4nJOVpbIon4Pj8sOsNraSwNpopetHmW0XC/zSCQb A2ES6ervZE+Kk6dZw/aZV9ObRG78+ZNbJ9hB+cg9f4Qbv69zqpMgmZgF7oNS/K7DbO4K LJ2mIjX1Czln7VVh2fIlUwy/f7qKcjPrKIosUz37R0Ctn7EwBF4AT7F3hU/xVA3mQin7 F4qg3sizVQlRNBttQUM13CElcXUCEZFgIMJUttTBFGuKqgsygly11JByz/EtFyVfikXE OIMPuahc3zA8tLRA3KRh3MS2VK59jviLNjXHd35i1OT3LHB9jNaYTQvtl7QjYQVxKdMg ogNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=xaFdqkmUa2xw274BNG9FQW1T/HjWKx1XdMMyVmWq9As=; b=ysO4BYSNHGbzocvK4QJ/blMgVJl042/LKpiQWDERsg+Z9JbLs1zIZnnO74mpt6+3xu xIBw6ZTyzhAvctA1oRCNPhd46xHByD2/HVaw9SOxhnRqSyS7Np0t9n99CEc4qEC14m+W e0ogOM2stAhC/CvICK2LugxG+VD2Hjnc848pBV5xOimXx0cGsNxBpH0lAnwHcLyn1cak koggRF1iLpHVF9ZHXVKpP+EYvH92QjWb5Jq/nWOprslor4NnzSzW8yY7F1O6oV3peUrV KHtU6M6tmtc4IWtznpgztlrENbH1kJY5dw0l7YEUCMEvSaFnwx1nB+4MHhmaWlMc+3JO 7xOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nrTAgLCi; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a056a0022c300b00582308c8101si10120739pfj.321.2023.01.03.03.00.57; Tue, 03 Jan 2023 03:01:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nrTAgLCi; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236976AbjACKWF (ORCPT + 61 others); Tue, 3 Jan 2023 05:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237383AbjACKVM (ORCPT ); Tue, 3 Jan 2023 05:21:12 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4BCD641D for ; Tue, 3 Jan 2023 02:21:02 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672741261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xaFdqkmUa2xw274BNG9FQW1T/HjWKx1XdMMyVmWq9As=; b=nrTAgLCi+Szd6JdsAW6y+kJrxSCzomfLrIXGBE6/Aagx4UVapBUohiLM6114fmmy2Bn8Y+ UHgtTZ1CZvd+nAFqHzFHmzqIcK95qt2abQbzm4UQ75CRXTkdaDp1zc+ufDUv6pYDi5598L bUW8hymMVaqgkUShbC4ctjK4gwR9jyPLfBMv6IuT00MmN45SRhv1qDAU6Q4K5pNowTbrtk kxbHUDkUDMT4taJCsw6cxmmUPDxn4ksqHOvYfeygV+0tQM4Acnfa9GXbzoWLQOYj4WxyPG 2VLvDV7egA2XlMNQVnkfzvFnbHhr/hawXvbfsCw5E31iqZq1WkrdB7JLtFkVyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672741261; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=xaFdqkmUa2xw274BNG9FQW1T/HjWKx1XdMMyVmWq9As=; b=eOxCVYhcOfUIJYna85+1GHJCxARXqXP0NIKRre3LRECWdpSbOk/lR2F+PJeZZPJU7ms9cM AScva6rW5CXX/aDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: Re: [PATCH printk v3 6/6] printk: introduce console_prepend_dropped() for dropped messages In-Reply-To: References: <20221221202704.857925-1-john.ogness@linutronix.de> <20221221202704.857925-7-john.ogness@linutronix.de> Date: Tue, 03 Jan 2023 11:26:23 +0106 Message-ID: <87y1qjdimw.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-01-02, Petr Mladek wrote: >> +static void console_prepend_dropped(struct console_message *cmsg, unsigned long dropped) >> +{ >> + struct console_buffers *cbufs = cmsg->cbufs; >> + const size_t scratchbuf_sz = sizeof(cbufs->scratchbuf); >> + const size_t outbuf_sz = sizeof(cbufs->outbuf); >> + char *scratchbuf = &cbufs->scratchbuf[0]; >> + char *outbuf = &cbufs->outbuf[0]; >> + size_t len; >> + >> + len = snprintf(scratchbuf, scratchbuf_sz, >> + "** %lu printk messages dropped **\n", dropped); >> + >> + /* >> + * Make sure outbuf is sufficiently large before prepending. Space >> + * for a terminator is also counted in case truncation occurs. >> + */ >> + if (WARN_ON_ONCE(len + 1 >= outbuf_sz)) >> + return; > > Strictly speaking, this should be: > > if (WARN_ON_ONCE(len >= outbuf_sz)) > return; > > The trailing '\0' will fit into the buffer when len < outbuf_sz. You are correct. My concern was that if "@len = @outbuf_sz - 1", the entire message will be truncated and you will only see the dropped messages text. I wanted at least 1 character from the message to survive. ;-) How about the commments: /* * Make sure outbuf is sufficiently large before prepending. Space * for a terminator and at least 1 byte of the message is also * checked in case truncation is needed. */ John