Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1588210ybj; Fri, 8 May 2020 05:04:57 -0700 (PDT) X-Google-Smtp-Source: APiQypLFwrAzh5FMfI/B4VYz2YxskcvqYRbwUKJNw1GSAUVhNYWUTlM8imRdEJGnaWWQolCzpzQC X-Received: by 2002:a05:6402:8c9:: with SMTP id d9mr1751952edz.357.1588939497452; Fri, 08 May 2020 05:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588939497; cv=none; d=google.com; s=arc-20160816; b=b6MfngLT+viCSPRFHLjWksz4wOGja6nx5Bs7UaDpWhmn8++im0cvEFlkiRZQaeNCqH QMCyZymJSeNN3GsavbToALDCYivZv2qr7YMKqac/rkRxCnF6zGN3TISIzXLTpFNuOa7n JsgBixOpMF4fkG5rbDA/65rdJDvMvLgx1hV/6PxejxqRj+ayf7OVbafhfRDD0j5YpWzx 3FV6wWSKWsCgQphWeNkBVCbA+oHupeoyX27t2j8oqiwNML4GWBS7eKWBfaGMk20upqdg BcewaHOm5HDonJ7vqOxRVUIlzoKtNjUg9xcNrqyFbvD7ofL439EabMS/Mueuzx8uxYr7 iWlA== 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=lNKVrkJdHzfMbK2WFg5Y7tu/Zp5ibf2iNC5EM1tQRJo=; b=z0Ycv2ANK/wr4nToQeNTzEOo2pB+/gRHxgjPcxTeJTOEaEdkFL6mnsUPLf4AXaFlwx GuoYJnqWjEp8LmogF+PSIWp/LPUZLZUii09oMBBCXrpaukKgn+4CGkTq/oUP+SWNl6Cl 0nBlhZjZ0m/O+i5sYHt/O6ACSmpasjmJKHsISIZ5N/4criCRBSkKZWzQgrURAD2HnYp4 1Zg6M2V49Tpo+hfxsGyA7YWHLKBE/haaLo7F2oH3BVQpBSXYeU45zJiUiG2WzYC0q+AU 8u0HpNOMHt7iSpmES6iOAbgBDfGP0zWfuQNdbaNSiCw4YIQSXXNmPZvODsR2OCo2miKV L88w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ubfbVMHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si802144edx.302.2020.05.08.05.04.33; Fri, 08 May 2020 05:04:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ubfbVMHF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727051AbgEHMCi (ORCPT + 99 others); Fri, 8 May 2020 08:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726618AbgEHMCh (ORCPT ); Fri, 8 May 2020 08:02:37 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CDFFC05BD43 for ; Fri, 8 May 2020 05:02:37 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id b26so1209473lfa.5 for ; Fri, 08 May 2020 05:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=lNKVrkJdHzfMbK2WFg5Y7tu/Zp5ibf2iNC5EM1tQRJo=; b=ubfbVMHFvkGFqi6/lMGAmUyGcg20V5yh8C00LQp7ohCZxq2z4EmwwX3B73H8EZ7Y6+ aJCVbMOvPuRCut0Bnl8ET5c2XfZXweuNYjo3brQ6CEYILBG8HhEgVuhFWVWA1BmL+7wr PaMOGT8qiPBOFsYR+vprL3K/7EVvJ8oJXMBygdJ6uGjhciK55QG7biHSQuFnHCtyvZe5 srhzCTXCfW52nQOZMKMQqUcLd8x7Ffk6Kk/ZsU0oOHDAWkNAqGX1e8h1hy8E4RAfCjEQ 6gCD/cXPSscJnlWgSBvvUILe/g9S3+oDCA5v+IgSinV7FqAm/oZSQvwlhvdPaLD8bWMp QpoQ== 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=lNKVrkJdHzfMbK2WFg5Y7tu/Zp5ibf2iNC5EM1tQRJo=; b=jt5T2pwbkIemVv8rKA16OwkyDfrU/+p9bDtLKvVdzImOJToB0yhWFtxxx9dwaZ71mi ckX/3hQ/mthYGnmD5Rre0Wd2uHEghx05tPTUQMWlWu0vc6TP9RyzSM8oecDSyuGYBklQ 9nLKLFWIMH3QOpFrrfLqp9nrZz570AUTFDlKeU8sUdhltvmaD2Segc52nUGN2IpfYbuv TxeHeaDgtJ7CDSKQKIK/TR0+L2WCGpGX1ZItTev2ogjH0lT94EAyKsR6vdZa+exe545g Bgu60HnRtZlDq9+xJkckPtcV2EG7bilwk2vgInYK+2j2lx7STMkSQrtdgF/BAylcFN7b cOOA== X-Gm-Message-State: AOAM530LdvhDd9OANJ6/3F1QmPj0GorCULNZZ1A3aBsTYY6Ujdntc9a9 arW5qHlnhkQDNY1fJ9TJZnD8+FiuSP/STfJnV/dw2Q== X-Received: by 2002:a19:ccce:: with SMTP id c197mr1688763lfg.59.1588939355636; Fri, 08 May 2020 05:02:35 -0700 (PDT) MIME-Version: 1.0 References: <20200507161125.1.I2cce9ac66e141230c3644b8174b6c15d4e769232@changeid> In-Reply-To: <20200507161125.1.I2cce9ac66e141230c3644b8174b6c15d4e769232@changeid> From: Sumit Garg Date: Fri, 8 May 2020 17:32:24 +0530 Message-ID: Subject: Re: [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT To: Douglas Anderson Cc: Jason Wessel , Daniel Thompson , Chuhong Yuan , Dan Carpenter , Masahiro Yamada , kgdb-bugreport@lists.sourceforge.net, Linux Kernel Mailing List 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 On Fri, 8 May 2020 at 04:42, Douglas Anderson wrote: > > From code inspection the math in handle_ctrl_cmd() looks super sketchy > because it subjects -1 from cmdptr and then does a "% > KDB_CMD_HISTORY_COUNT". It turns out that this code works because > "cmdptr" is unsigned and KDB_CMD_HISTORY_COUNT is a nice power of 2. > Let's make this a little less sketchy. > > This patch should be a no-op. > > Signed-off-by: Douglas Anderson > --- > Reviewed-by: Sumit Garg > kernel/debug/kdb/kdb_main.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c > index 515379cbf209..6865a0f58d38 100644 > --- a/kernel/debug/kdb/kdb_main.c > +++ b/kernel/debug/kdb/kdb_main.c > @@ -1108,7 +1108,8 @@ static int handle_ctrl_cmd(char *cmd) > switch (*cmd) { > case CTRL_P: > if (cmdptr != cmd_tail) > - cmdptr = (cmdptr-1) % KDB_CMD_HISTORY_COUNT; > + cmdptr = (cmdptr + KDB_CMD_HISTORY_COUNT - 1) % > + KDB_CMD_HISTORY_COUNT; > strscpy(cmd_cur, cmd_hist[cmdptr], CMD_BUFLEN); > return 1; > case CTRL_N: > -- > 2.26.2.645.ge9eca65c58-goog >