Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp133521ybp; Tue, 8 Oct 2019 15:21:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqGd1Tt1tuOu1K1OCphi0ABVNpNlViT6W/rlri8EaJjpN7FxLEwWKxWMgD7Ji2+bprG52g X-Received: by 2002:a05:6402:128c:: with SMTP id w12mr295181edv.284.1570573294738; Tue, 08 Oct 2019 15:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570573294; cv=none; d=google.com; s=arc-20160816; b=DL1DZrar6an7qk4KuNlyi8xRcTlS6kq9yYj5oHLdHd+EP+IS6/YHUxU4U8qdh+IguS Ez2O/9Zfx1jQ5tYyJ0yqP1AyBJA8IjvmfrjW45qP661T94ZdgTX6AT9G9Y+i4PMBr0tY 3IDGof0Ng5tNF9bKHkCDg42ZSTRCR9h8xZOUJajCd47s6KiWaH7h6oBcJ1pbYGdipmH1 ExfPUCedAUXvnNE+GMBMd0LjufPKRSv174i6CJChyRR8IexxBdoCW4xSEsQGVzDcucgc EJwlbMLeexuWCVkNA1PAJOP5zKcvfG0QTlxmiIwCvRqRhII70BLvJE/UtrQTAoAsDf6q gZmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=dVXX+jePG0dCtUJvg0DDOB9y84J6FIyWcr2vDL3JBhU=; b=jOzLK3RPykK0Q9rANYhE6H1veg5lWf93aFsKg0zV2e+W6D2CzrY8JIJfy+0uTJ1Rl/ HcwST88uuLfIQOgMAo9rfFaIDd2D6GJMb2f43FlEgnrle5IsbL0XC0FyoM56AMyHrg4P WbsjF+P5tzCprcbGcUt9BYwxRcKimwPynuIAkWn5KMdoalFY+vnZF8YHLzpLyPjeHSKI 08FfySdngQeZS0Ij1ym0Hs9V4l7gIej7wpFjq4AnZSHlfjB0FizQ4C1qByWCWPTKvPyY zPupGGFiqj0C4C0em3EkqwoFMZf3VQLMJumDtH0EoBPVEnXSM3ZoPL9lsbG9C5Dqw3jg Td9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SJySUhGx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k25si131834ejs.189.2019.10.08.15.21.11; Tue, 08 Oct 2019 15:21:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SJySUhGx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726068AbfJHWUp (ORCPT + 99 others); Tue, 8 Oct 2019 18:20:45 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:34534 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfJHWUp (ORCPT ); Tue, 8 Oct 2019 18:20:45 -0400 Received: by mail-io1-f66.google.com with SMTP id q1so590016ion.1 for ; Tue, 08 Oct 2019 15:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dVXX+jePG0dCtUJvg0DDOB9y84J6FIyWcr2vDL3JBhU=; b=SJySUhGxbmn/z4rxv9EcvoyuY58UMbJjjlI5IXJep3N8nUl1az6BoWji8k9FAnv7zJ +OaYKJbhRu6oKs8uY3BrrxiBNL7ZdmsvdsbnsL1LdCYyjv+Dsxe9dQOFGjA7RXWsNFv9 bKVRXreg1AVstVtJPPVC5ZYOuFp6Z7eQ6C6cA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dVXX+jePG0dCtUJvg0DDOB9y84J6FIyWcr2vDL3JBhU=; b=gCv9ABWSi1iNMonH2VqqELD+ZD8cpKXnUewI8O4Z4VJTLGFD7qjV9Zk3W1dKYorKfD 2GjGulWvOPSu9Pww7AOz4/lsv5oo3krYkNA2jMtPQ3yd1e7676JxQqnPlWCuq6m0ZYsy 7Mnu3pa8dR/LCfOF0oJAdqrw3s/caQdbaQgAfTM0dv5yInpXKDJDVPgvzeXikMyAcl9T Wn1vN0+sLIpWbVsMXKAvPIxv2KmkE1Ch9ZFhkVLD7foZ0IMdicyT29FKHi5kSA0jPkb4 Y40f83LmwLUDLu1cZmmwSEFGDghKKczZ2KR7awNv2OVnSXdMeGS2VDCa/4li6qwAhiVT fGFw== X-Gm-Message-State: APjAAAU46X7GNx8i/LVLqHezuD0h+aYX4wXUxSvBQeiGCRW6uU+aVjbL ZeqRP0qNWRyc4y/xXwD4boQS/8RQ8mo= X-Received: by 2002:a02:ac8e:: with SMTP id x14mr280405jan.11.1570573244204; Tue, 08 Oct 2019 15:20:44 -0700 (PDT) Received: from mail-io1-f52.google.com (mail-io1-f52.google.com. [209.85.166.52]) by smtp.gmail.com with ESMTPSA id d26sm151203ioc.16.2019.10.08.15.20.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Oct 2019 15:20:43 -0700 (PDT) Received: by mail-io1-f52.google.com with SMTP id h144so508355iof.7 for ; Tue, 08 Oct 2019 15:20:43 -0700 (PDT) X-Received: by 2002:a92:dcc1:: with SMTP id b1mr733444ilr.168.1570573242957; Tue, 08 Oct 2019 15:20:42 -0700 (PDT) MIME-Version: 1.0 References: <20191008132043.7966-1-daniel.thompson@linaro.org> <20191008132043.7966-2-daniel.thompson@linaro.org> In-Reply-To: <20191008132043.7966-2-daniel.thompson@linaro.org> From: Doug Anderson Date: Tue, 8 Oct 2019 15:20:30 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/5] kdb: Tidy up code to handle escape sequences To: Daniel Thompson Cc: Jason Wessel , kgdb-bugreport@lists.sourceforge.net, LKML , Patch Tracking Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Oct 8, 2019 at 6:21 AM Daniel Thompson wrote: > > kdb_read_get_key() has extremely complex break/continue control flow > managed by state variables and is very hard to review or modify. In > particular the way the escape sequence handling interacts with the > general control flow is hard to follow. Separate out the escape key > handling, without changing the control flow. This makes the main body of > the code easier to review. > > Signed-off-by: Daniel Thompson > --- > kernel/debug/kdb/kdb_io.c | 127 ++++++++++++++++++++------------------ > 1 file changed, 66 insertions(+), 61 deletions(-) > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > index 3a5184eb6977..68e2c29f14f5 100644 > --- a/kernel/debug/kdb/kdb_io.c > +++ b/kernel/debug/kdb/kdb_io.c > @@ -49,6 +49,63 @@ static int kgdb_transition_check(char *buffer) > return 0; > } > > +/* > + * kdb_read_handle_escape > + * > + * Run a validity check on an accumulated escape sequence. > + * > + * Returns -1 if the escape sequence is unwanted, 0 if it is incomplete, > + * otherwise it returns a mapped key value to pass to the upper layers. > + */ > +static int kdb_read_handle_escape(char *buf, size_t sz) > +{ > + char *lastkey = buf + sz - 1; > + > + switch (sz) { > + case 1: > + if (*lastkey == '\e') > + return 0; Technically the "if" here isn't needed, at least not until a later patch in the series. The only way we could get here is if *lastkey == '\e'... ...but I suppose it's fine to keep it here in preparation for the last patch. Reviewed-by: Douglas Anderson