Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1148671ybj; Thu, 7 May 2020 16:14:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJBgtiO4vFrkEs8blFmBbcldloi9lzgVpw/tpw8m4hmWqUpYFjX/9pYf0xbAyMUPNcdezlI X-Received: by 2002:a17:906:72c8:: with SMTP id m8mr14895026ejl.318.1588893245861; Thu, 07 May 2020 16:14:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588893245; cv=none; d=google.com; s=arc-20160816; b=fzMj+Tv5/S/JAqIgfdrx2yuC3Q8bgAuykEYWwUcXxOGrEbo681Ktjk1sGRh4dNn4T0 QRHs1CJB2Hmr+lGwgzhov25wpKMjZ7+XRU7ZLPSn84AD7c1irAAOmb/abK/CGyYh2/8y 5g2gKvM/j1PW+44wL7IrecfHFQTiH3vMXSAPG+VyUDdvGKadCgZj3OJ4eGdm5MGSz2D8 zhOtwLBBmhJtvhKNP690d4gJlKSFLiYoKxoiduVK5mN10yndzOLYyeR3IwGzXZUz12QC dl2cqlazZOpNnRJpiB+giYzqnyp1oep+18kYOnic3PnI0oUFJckDDt+DdqJaBP2jDHjW ZmvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=J/3HPQN7W1ZKY/vF6kf3W74SkxKV+nge4or+WiAyuSA=; b=Z9x1jpIIHYz12ar6GH7SFYIHJkFdjtc4fY7snVteEniOjiXWeVCa2Ta2N8fXuqUfKF IlAb03Kq0Zd5Cr1KNuQGryjpnq/0nBM5i0FkgmDKiGjebI1bTtl56Ox9xvLFame4J+fB X7IzSSFcC6/Dtxz9nB/sWEDTrt/gZ++dvL91M+49GGHsqdR0L3teKNt7Twi9buUhDpxQ pgwkxUuskmiXFuUqTVJxeAJVj02FJxDgIOArbOLwk45b1m79aVtx8w+25BnLySPuePN7 QSQDk3pr5q7itdm/dgBohOvqRGgWgVIKzvTgjX3+aJz3ubZBdrQ1Dyg90m1hExxBWrt/ 6Xew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KDcfxey5; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw6si3995128edb.552.2020.05.07.16.13.42; Thu, 07 May 2020 16:14:05 -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=@chromium.org header.s=google header.b=KDcfxey5; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbgEGXMP (ORCPT + 99 others); Thu, 7 May 2020 19:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726514AbgEGXMP (ORCPT ); Thu, 7 May 2020 19:12:15 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B0EC05BD43 for ; Thu, 7 May 2020 16:12:15 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id w65so3762097pfc.12 for ; Thu, 07 May 2020 16:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J/3HPQN7W1ZKY/vF6kf3W74SkxKV+nge4or+WiAyuSA=; b=KDcfxey5JIeGwWZPE5JoJOlaG6N/dElrdB6K50KHlFNelrxKbvTlkPWInDHxs8alm/ NX3IKCFYgAxWXCG9PdEvu9YXEAfEcE2Nze27cHGAKW5PPMDiXPcZsxWxOItkDTN0ekWq LYsQeiFSGwWQ73N+eS/xnETE2JkSx8/6CnM7w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J/3HPQN7W1ZKY/vF6kf3W74SkxKV+nge4or+WiAyuSA=; b=UJz7AJmPU0Nmvc2MvyCU3yd7SyWOoELc3R2D1kOYesJS5kjq1bgt4TpIvMA+i8ZhFm V8h3Uip/UF66mk7rv2C4bWCOVAutVlDezIl90CYTCb4n6fjMRgkC9UFy0rHjViiwLyXV ZQPwTlfkFu6gG2jhJx8HG5ORQe2CkpLp1KRPOJXEEDpCRGufC7k8iPKMmLv/1y/r/8W1 apeSpNOSuWb8AcaiZr5E1AEyP9YUXSRJj2hEcYn1CQoXxHoeNqYWnJOZWuf4N9zdpxzi KKJFaNuJlVUB1ew1XuQSBNMAoxwDiNAPlJj+IqPWwERnrIwEPVYVpI0mjn17iV6LU9Kt foVw== X-Gm-Message-State: AGi0PuYVqTpERviG8xd/dlaEmPspBi+8tGmrZkoyHLlJNIp627HZBNaG FRZSiNuK/7Tff4Q9LI0GHZTOtw== X-Received: by 2002:a62:ed14:: with SMTP id u20mr16651128pfh.69.1588893134874; Thu, 07 May 2020 16:12:14 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id w12sm5861057pfq.133.2020.05.07.16.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 May 2020 16:12:14 -0700 (PDT) From: Douglas Anderson To: Jason Wessel , Daniel Thompson Cc: sumit.garg@linaro.org, Douglas Anderson , Chuhong Yuan , Dan Carpenter , Masahiro Yamada , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] kdb: Cleanup math with KDB_CMD_HISTORY_COUNT Date: Thu, 7 May 2020 16:11:46 -0700 Message-Id: <20200507161125.1.I2cce9ac66e141230c3644b8174b6c15d4e769232@changeid> X-Mailer: git-send-email 2.26.2.645.ge9eca65c58-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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