From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C8D32E0B71 for ; Tue, 4 Aug 2026 05:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785821107; cv=none; b=K6CWi3mLw8TFetoEc/rWUh0qHtNEUGRBH7EiNVqdPSz1rkCnfzySSzXuAe6lmoQyLp1thdKCd7Z+FWahRwQu7m3xDYaD6tP8Q/1f396PasbYkrkQb4ZtGhUbuYXJNbk+2xWNMcbDLmVuXn5ovT6muFqt6sxugmL1cfmI461x/Dw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785821107; c=relaxed/simple; bh=mmwglf4UtvVil0QRLKOnjGSQ/l5rlXu/Ugbg3jrBdQU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OOzHGjjPb5tlcmhCpZH+9r5tCjF9hsW3G0Ka0yV8sUffIlh064AxtLvPZ1FcyYVZLWrq6HMzaYMXbcGwmrLcB8jfmRXRXi51yy/B3nw03l1Ml560XBh5b+m/CP8HfIKVFbB5R90o3ERHyghBiILNZFpLl68y9FRjj/adDnAva8I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ou8YG01E; arc=none smtp.client-ip=209.85.215.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ou8YG01E" Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-cbe3fed2f58so2366046a12.3 for ; Mon, 03 Aug 2026 22:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785821105; x=1786425905; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=t6kvzdvm62iAzdXKiMHQHO64pAvvpog/HEHKw/8UdVs=; b=Ou8YG01EHv9F2nYdYK5SrOBUMEBsa0ot+P/ppADOvWeOFdDLJ/YbmlVBK+1vN7gy3N 8qWDO+RrAiZHgN8d97f38gNs9mRz1dEtk/vWsnqAOEnSsdehSECvMe2lSQMnv6d050PI /JvR+fKE5MI0PENMM8nnGgLJIUpeql5RJCd7YDn3+ODJhKUvHI15sjjmeKRb7PxF3f+P pHHotVbpOFwBoXD/q5dkeoalM+Fw0qtgkpgzxKxHkl362cm9mPoFKr95D2ZTKqAeAL7h bH01fG9HDcTvePtPITy1H2ngHYDWjrHpb/hFSIIDbxEzQEY2a2dhhdKIruih+xXc24zj FAiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785821105; x=1786425905; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=t6kvzdvm62iAzdXKiMHQHO64pAvvpog/HEHKw/8UdVs=; b=ASjMpW16rj2/JkHnxb1RtBWkNrbj0x+YpfOqViY5F4QIOPfX9KDPeZxuPcwiq2R4rJ TFCnBUoF7OX3x04SOv6Cgges3U1mWwV2484DxM4ISuvAV6qKjr/zXEyx1qvD6y57lWXo 8rrNTlMuNlIrMKOnb5aPYQW/Ov+IFtjeCi81/l2GsNCLQKnwr/6P+2CpO63w7qLHRmZH 9b33Q/falHMgELIripl/UxTWFPHG3vi0Np6lbxeU1BpAu7s0C5MQa82kZyE0cKZYJK6w wO7zMHhXJe3yEV78AU2EeiKVzxvBagwWgQRMM84DzMaVPPUaicfxGO9QsEMZ188tC7F4 Pe3A== X-Forwarded-Encrypted: i=1; AHgh+Rqnc63mHOC7rGXG/1OL/9Rn91Bb0+0+GfEX2JoAx8W07Y8yScuZbRr5JmuCIA5aSLld7/H2OQJbBGIXdy4=@vger.kernel.org X-Gm-Message-State: AOJu0YwND8RqfzwLJR21HcX/o6CGAUF6zQ8Vykk7kcydzuXQpRm2aFkZ FYu1L/8j/mCe6DYriSKP0NJPe4s7li9jQ0ytKPBbrUrYuEjpmHxuLf0I X-Gm-Gg: AR+sD11BcVEgv7ne68KxS6yhMlJcKmec9uxqzKSpKuLmFxC61H0XDwJn9wj7lIGb85q Dy27tASI/rnbLT2M/nB+5Jom2vzNSnmjj5kJs3FQn9MD3IO3PzXRZ0/Sm6l+1VgDDW/DTG4V2OF G/IWnNI7KueBViwMqCMOlROPcaYctlIzKI/oQvr7RVK7cHhhPPajFCJQfOq3pCTe7a7Z5IlctoV q2WlMNl3ua6i6VSmsZ430epbOyvu9JiSuzr5DELR2sdR1/qJa+BXCNc8hTnywJs0yGF8qV/Mfqe NhClwGM5kr6tQA+leNZ+tUlnU0tfxu9ZssiAj7ZUKKNxZ2L1zoUCgekd6J96hY5/NWeS9FbKirp zYjUha47fijVTKLQ3UaYDDSSZhWWcnpuWAffoT99EAx5Pid36VGxoLsivy0hrxV+vjImPecEeEv jvNXQg0V3JXWrRwajTy/66kPHwqYylIJmhBGwz78QOf2yYfmI2mqda2hSjQ7z5rlhnfbdE6MoWw m9fCtnowRVDMK96UrhJvsOqCZszPA== X-Received: by 2002:a05:6a21:9a4a:b0:3c3:bb40:790 with SMTP id adf61e73a8af0-3c92a8eff65mr13424705637.66.1785821105399; Mon, 03 Aug 2026 22:25:05 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:d109:cdba:8a20:74ad]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13fab1334cfsm41847138c88.1.2026.08.03.22.24.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 22:24:54 -0700 (PDT) Date: Mon, 3 Aug 2026 22:24:51 -0700 From: Dmitry Torokhov To: Richard Davies Cc: linux-input@vger.kernel.org, Mathias Gottschlag , Hans de Goede , linux-kernel@vger.kernel.org Subject: Re: [PATCH] Input: focaltech - use signed coordinates to prevent underflow Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Aug 03, 2026 at 01:29:32PM +0000, Richard Davies wrote: > Dmitry Torokhov wrote: > > focaltech_finger_state stores finger coordinates x and y as unsigned > > int. When processing relative packets, negative deltas can cause > > unsigned integer underflow if the finger moves past the left or bottom > > boundary of the touchpad, wrapping the coordinates to values near > > UINT_MAX. > > > > When clamping the coordinates in focaltech_report_state(), these > > underflowed values are clamped against priv->x_max / priv->y_max instead > > of 0, causing the cursor to jump erratically to the opposite edge of the > > touchpad. > > I agree this is theoretically possible. For what it's worth, I haven't > actually experienced the cursor jumping to the opposite edge of the screen > on my laptop. That might mean the relative packets are actually safe, e.g. > generated internally from an absolute position. > > > Change the coordinate variables and limits to signed int so that > > negative values resulting from relative movements clamp correctly to 0. > > > > Fixes: 05be1d079ec0 ("Input: psmouse - support for the FocalTech PS/2 protocol extensions") > > Reported-by: sashiko-bot@kernel.org > > Assisted-by: Antigravity:gemini-3.6-flash > > Signed-off-by: Dmitry Torokhov > > --- > > drivers/input/mouse/focaltech.c | 12 ++++++------ > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c > > index d3ad4af5aa09..c6f6540e3e29 100644 > > --- a/drivers/input/mouse/focaltech.c > > +++ b/drivers/input/mouse/focaltech.c > > @@ -78,8 +78,8 @@ struct focaltech_finger_state { > > * Absolute position (from the bottom left corner) of the > > * finger. > > */ > > - unsigned int x; > > - unsigned int y; > > + int x; > > + int y; > > }; > > > > /* > > @@ -108,7 +108,7 @@ struct focaltech_hw_state { > > }; > > > > struct focaltech_data { > > - unsigned int x_max, y_max; > > + int x_max, y_max; > > struct focaltech_hw_state state; > > }; > > > > @@ -126,14 +126,14 @@ static void focaltech_report_state(struct psmouse *psmouse) > > input_mt_slot(dev, i); > > input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); > > if (active) { > > - unsigned int clamped_x, clamped_y; > > + int clamped_x, clamped_y; > > /* > > * The touchpad might report invalid data, so we clamp > > * the resulting values so that we do not confuse > > * userspace. > > */ > > - clamped_x = clamp(finger->x, 0U, priv->x_max); > > - clamped_y = clamp(finger->y, 0U, priv->y_max); > > + clamped_x = clamp(finger->x, 0, priv->x_max); > > + clamped_y = clamp(finger->y, 0, priv->y_max); > > input_report_abs(dev, ABS_MT_POSITION_X, clamped_x); > > input_report_abs(dev, ABS_MT_POSITION_Y, > > priv->y_max - clamped_y); > > If it's allowed and race-free to change finger->{x,y} in > focaltech_report_state, then you might fix the Sashiko [High] issue on this > patch by just doing: > > finger->x = clamp(finger->x, 0, priv->x_max); > finger->y = clamp(finger->y, 0, priv->y_max); > > not having the clamped_{x,y} variables at all, and updating the two > input_report_abs lines below to use finger->{x,y} Good idea, thank you. I'll update and apply. Thanks. -- Dmitry