From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 A8D2941D233 for ; Fri, 24 Jul 2026 09:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886266; cv=none; b=Q3OgBSWGYsKWv3/iHsfUm39ZlZ8QBsW7cSVhnnthubMI5CvWW3t7PEblYmsihVXiWyvY4ylnwxSlBsMg5MJb+DHinxPVutGMLeUr+FvDnOoz3kGdPz32Dxsx5QiRKm6Y+3ybd5Xm3yu67JHzg92AfFi6AIjBN+oufBYjdzwiAXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886266; c=relaxed/simple; bh=eMlyiqXZjmjDnaqiA9Beg57b9q4uHubEnNNZqn0tyTM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=JTRdwHbR/giwSKP09v7hZrwCSJcgaE5tmsxfJCF/fJ04AqldIYfw9Atp1vkTGQjmtoIGMBpaOytz8uzseSe9LYboFc7mjJAvoXcNIXrxjy8gRmO2xfaaXJn15a0qPMITSz++sbGD9kksg85P4E8z+UBJi9HXuUzWQH/QTVqpjlw= 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=h5oYk1zn; arc=none smtp.client-ip=209.85.218.41 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="h5oYk1zn" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-c166f1bbeaeso41696266b.0 for ; Fri, 24 Jul 2026 02:44:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886263; x=1785491063; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=zACxA3C6bQvdgy3UWB7mt1+4bltOYljsqgZV5imQp+M=; b=h5oYk1zn4nQYn50FZ5izpwxBC/z5J6A8vtLBfuP4PIaoG3aCGR3ptV5wFgUsbaU69L 6KsmEOsptsea5BypqjQtzy8CeMwV2B0Rj8x6+UTYVr6RgLLgu3uXq7QZr5H/au9gr/bn 2TUxAwrrOk4B1iE81rdDIY0DjbhPmwIpgBimjIVInN/KMlSGYp0BEojgRGZSGxcURAJJ bnLky4sYB3AoFxYTenpXpJGQAA1YXf0tYzsnbFB2Yt13y2EY+GPgZHCIDSs5zchyz5jY 5JWJknfG0rO6XbSdLxFK5l56nwp0/PCDFnQoRs1EopOd/EvA0aVgNVkyQHBCI864G5JQ iy1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886263; x=1785491063; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=zACxA3C6bQvdgy3UWB7mt1+4bltOYljsqgZV5imQp+M=; b=dJZS0cAZjeb7xy6wdqSyLIigC2MEi7VyluQG8VeygO2ijYwpFLkRCisDPdj/y8NNi/ +w15XKZ8lZpJGWg91+5nCO2/zGX81tBoz85BETayWooKApZ5JyU26ywRbQg3WYIbvZNl oZ50tTd2PuNWsfZEnv4v85CsHjKvcdieaf/sOjM1C/EpW9H2xeFRjChQE2f3mllBMBhM 6ggjhjAz9j5hI5doLuRlSCr1ew3Chf5mA8AtMJferf350DaEWm3H0TyicSiwBpv4AKuI nyfu9x+UFZzkHKQLp5Z3Kh3ZIvshkM+eN+o3zznnvFXSJY7vWQZP0Qv0zwOLZ2m9DdHP t+eQ== X-Forwarded-Encrypted: i=1; AHgh+RrPC/00a5comtPQjAsQOyevIGEFpstplvt/6/uLTH8cGK3ikJmaIOAU/hLm/BYY82zME5Xk1w9e2+YWWFs=@vger.kernel.org X-Gm-Message-State: AOJu0YzI9KD6KSrXnCrruk8TvD5hLrbcr7fPlxORpaHpLvm/u4ZK3Rm6 oW+mELVbt+vmLBC6AU1bUCOPkWA/mDwdvMTzEzyOrsBuZ1LfCE8MCOXJ X-Gm-Gg: AR+sD12OvTYCjOVUmxJAdi8NJ+Z2v7Cq9/335R6yGzoQECQPBQWAowr3aoTaN/oHGlD M0TSG2aTThFbe32GHKfRTpPllwVDuS6O+z5G3w/jeMYFofGTf8HbgzBr0JMz0DryzRGfuNwZvJ1 uUe0zu9Eh9F3USTGNXp3N4VjLYGpk30Qgr7z3z5m7l5/SNxVeMyJ5vP3kykp9zxLH91c2Jd2aTE INMd8fuyrw3ytxdI1JPfj1NmYSc6MQlf8skx9K2WsZChmDMj+LstzCK7fPZI9JEZ82EaFDHhEup yhS263u6i6dB0gM462JOj85kPdIIkkapsXtgKMnlZ7d6T4iZUkivXga7FIPJMyar0romQFUKK0S I91fSgFvykJ5HUv2vJp4y8ZJVAO5C3U+emKtZQXy75vb0UCZLDHzAKVWlkEWOo40auq57H5qucl R+QbpUqWF/DNgkUz1WfDSTaPEwFRJoPA== X-Received: by 2002:a17:906:7947:b0:c15:f4aa:f30e with SMTP id a640c23a62f3a-c1c50d1cf10mr261248166b.37.1784886262530; Fri, 24 Jul 2026 02:44:22 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c4835c4bdsm245383166b.16.2026.07.24.02.44.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:22 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 1/7] char: xillybus: Improve control of execution flow with mutexes Date: Fri, 24 Jul 2026 11:42:56 +0200 Message-Id: <20260724094302.50761-2-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This commit addresses two issues by using mutexes: (1) Add a mutex to protect the fifo_buf_order global variable. The purpose of this variable is avoid repeated failed calls to __get_free_pages() for allocating FIFO memory, when the chunk size was too big. However, if two drivers are initialized at the same time, fifo_init() may run in parallel, and fifo_buf_order may be reduced too much. This is a far-fetched scenario, now completely prevented by fifo_buf_order_mutex. (2) setup_channels() acquires process_in_mutex to prevent process_bulk_in() from accessing the xillyusb_dev struct. With correctly working hardware, process_bulk_in() is never called while setup_channels() runs, because the device has no reason to send data in that phase. The mutex ensures that process_bulk_in() does not touch the members that setup_channels() alters. There is no similar protection for data flow in the other direction, because during the setup process, the only outbound data is the BULK endpoint used for commands, and it remains untouched after its initial setup. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillyusb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xilly= usb.c index 34e7ad3bcab3..a28e6416cb01 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -50,6 +50,7 @@ MODULE_LICENSE("GPL v2"); static const char xillyname[] =3D "xillyusb"; =20 static unsigned int fifo_buf_order; +static DEFINE_MUTEX(fifo_buf_order_mutex); static struct workqueue_struct *wakeup_wq; =20 #define USB_VENDOR_ID_XILINX 0x03fd @@ -375,6 +376,8 @@ static int fifo_init(struct xillyfifo *fifo, =20 unsigned int log2_fifo_buf_size; =20 + guard(mutex)(&fifo_buf_order_mutex); + retry: log2_fifo_buf_size =3D fifo_buf_order + PAGE_SHIFT; =20 @@ -1943,6 +1946,9 @@ static int setup_channels(struct xillyusb_dev *xdev, struct xillyusb_channel *chan, *new_channels; int i; =20 + /* Don't let process_bulk_in() run while we change the channels */ + guard(mutex)(&xdev->process_in_mutex); + chan =3D kzalloc_objs(*chan, num_channels); if (!chan) return -ENOMEM; --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 683713D9DB6 for ; Fri, 24 Jul 2026 09:44:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886269; cv=none; b=KPNX8n23fL64068jY+sOtGg8Wed9MdraNFQNzY/GutHrc3RxdBqTtAaMh3VMNyGiowO0ON9Pr4m/mYNCZDXHsfb/fVlusKrwDmCyUvEVwbuG3r3zFTY22N0EgOzMq/fon55CwhtnJJq8+VyZjQEOCo0a3pI7pOeDHpTDRf3xjYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886269; c=relaxed/simple; bh=sUA7FHukNsScIZLQP0xgI8THUUyLT/6hRDoo2eCKr6g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=AHVuPOl7UW9P+OeXinXFn2e3uZXCC/kqMIvg+mml8BSzyBLhMrDlxMpUFDOjthoHPZaKDyJw/5Zqwt0UdoOVpQYoIz2ViVUaPjkdMwfYln0HWauC2kUoUldt4arp4r1BFbmBjvUF7BehvMKrVRUchdI6e4el66u5mQk2U4KB/nU= 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=dlnowHqv; arc=none smtp.client-ip=209.85.208.51 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="dlnowHqv" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-69c1220bd51so323102a12.3 for ; Fri, 24 Jul 2026 02:44:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886265; x=1785491065; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Z4UYRb5GP95XbbKS3BzXHzHeJsPryg5Ef3ntWHW+d0s=; b=dlnowHqvTR6OXy87YWDD1mBCUje9KSqy7ZTmG5LjRcA0kzFd1oxoK2vqmGP6k5MSbI iMf6rIlwxj3nRYekF9iDt8w/cxiDHuXH98kU9moy6acVD8jgfjWc+VApdSlEh5RcCCvs gyPOPh+UMInUnHc7opB0ana/XY2/vt4a7hEmxKBlZS2AlGqdeqge8b41oKpdATic/tMp VBUO9l9Xx9U0MNn7BdERi0YjWjwMbPJiwlfosU/aVIb2pb9LyXC4ixqpMXyGlwrkfBXB HtgFKKt+cmrfjW1q/hLsisSkWQtuuQ/veN0xnbxmr4Pht6O3NAYPzThIPj/vX0i+A1Bb 5scA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886265; x=1785491065; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Z4UYRb5GP95XbbKS3BzXHzHeJsPryg5Ef3ntWHW+d0s=; b=h7A7JfcgOYpWVZoxKYiuG4I2WksWdeMO4y/wHuo9xeff9iv1HCnFBY1oXKfVYxL+R1 PlZsd5bIGtad8UHfd1m47uZo1CCpuSL/UDRYQkIwwN1jKQF+swjfX1rE86yBns+uaAsc oCkyJxbtCCcUMPTfQc8Zu+noxN9DhMh69j12rIFfR6ZrSBLHXphCDmb4RKuBgA8spLRR 9iSAPBBYrmM5mwJYig0Y0s6j2skQURsH2bC+hmC3XlVPcMHtt9CHAgoTKKsnZJrJdgYG teDYCgUTHBKo2d8KhxQx860/Xe8bGWzYWTc6u96iYHTTt0wr3JnvY/SHtiwngWLsr7G2 zmBA== X-Forwarded-Encrypted: i=1; AHgh+RrYicEm3i4xzXDGk1kXElGEiJTzvx4g+mbzKQI/l25mzLdjlw/ijzskH8iDUExx0gc7fpT8O455a0L5KQk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxb5zG8wGNOrdPWh3AANpj9ctvROhHIFkaTHwv/XiFZxuaM+4I6 7gl993BaxysERnoFX4BRGFCL4xTwXMMTA0tlTgdMwWn8UYaN+Id+Wh2v X-Gm-Gg: AR+sD13vUew8/munwfy7u9WKmm5m/ybKizAS19MhQwsiSibT7vYVdeHRpyw7wVbXYX2 Vl1nHv8kQ5bxTZq6Xv52uPOgbBF/sxLkxGzxsGKtAVDci7OVLbQ/Sk4ewPOM761V/pRRHJguQgx 93xgGzjmOmfYyjND6C0EmIDMlQXoZhwjdWP9+r28AXKj6ADUakj24gEuWhEV9p19oDRmlYQWBie 6ifscYesWc0qBALkWsQB0vFabzGGn/frjKCJN4VG6Zd4W+NMBHf3pPlFICTieOduAFMDsQiVJbD 2W5lQFCLNhZaEotjdTLnAOpjWI2FF73P5/med3Sb6L9Qd9+DkeU3kcfLRyKiBoC/+9isanT8rnj BfqXuxRNS1Y32ggfOxJ2fZTK+devGZr16eJBToAdGpRIqYGGtPg32xU07cbif2Dg1tQY8rIRtVN 0+9dFxrTTJOKW0Z6QB+jzurAtdPXPNoGQmDlSnfLQY X-Received: by 2002:a05:6402:5053:b0:698:3b7b:e48a with SMTP id 4fb4d7f45d1cf-69f6c5e4fa9mr2860977a12.32.1784886265087; Fri, 24 Jul 2026 02:44:25 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-69f35026b10sm3070405a12.25.2026.07.24.02.44.23 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:24 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 2/7] char: xillybus: Remove duplicate error path code Date: Fri, 24 Jul 2026 11:42:57 +0200 Message-Id: <20260724094302.50761-3-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No need for dedicated code for the error path. The removed dedicated error path code differs only in when the mutex is released, and that makes no difference in this context. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillyusb.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xilly= usb.c index a28e6416cb01..ab5f9159aa17 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -1419,16 +1419,12 @@ static int xillyusb_open(struct inode *inode, struc= t file *filp) if (filp->f_mode & FMODE_WRITE) chan->open_for_write =3D 0; =20 +unmutex_fail: mutex_unlock(&chan->lock); =20 kref_put(&xdev->kref, cleanup_dev); =20 return rc; - -unmutex_fail: - kref_put(&xdev->kref, cleanup_dev); - mutex_unlock(&chan->lock); - return rc; } =20 static ssize_t xillyusb_read(struct file *filp, char __user *userbuf, --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 3BAFD41DE12 for ; Fri, 24 Jul 2026 09:44:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886271; cv=none; b=sCK9hQnh03CUxPYR2T837hwc1r31SHk+4FeYm9F1fjFVwC4uwoFEUlv11YMtSUOTFyY/N+1QiH55ObOWuj91f77pMtqEUrBJBmBVPoK9sxQjl6YXwiFvH1D7vbO3VP3yxeeWI2qh3dgMPGugHmQy7KFJDHvRiTvgxFy4AgZe30w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886271; c=relaxed/simple; bh=Q6wwlMqR5T8MAIyiPqsMcBqx6CJQn+tCpRJgIXUMErU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=N7xeESOoscx0wE5NlaDmU7+NIrImQW7WodfK+4czu9m1bPNdEDYU31EzL+nqyreWWU/6tTqjOlW22AWSAG3e5HU5jpvgG0z/5wZb3LVrp9h4vEr3tIlW6gEB9fpxSh9A79LP3+L63Czany9SA9/FPGLCqXZQ2bzeG8hUPj5grSk= 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=iRIyPVIH; arc=none smtp.client-ip=209.85.218.51 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="iRIyPVIH" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c15c42a45adso194539566b.0 for ; Fri, 24 Jul 2026 02:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886267; x=1785491067; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=yuc+kiQDgL6coKIxn3rsMJs58ojI9P6Kgpsrlk3FLvM=; b=iRIyPVIHp5RtaXUSSfJMxlwFdln6qj4Ma6kvt4C9AVrYeyTtkTm+LD4+4wNOvz38Tj rM7OzXnYU9wh1Sj3y7bBNFcFJeIsB6aiMZvuTF4o1xBLUNsofUwYyTi67blzxD9jZfCU xVfzQc9b4sxzRIkHp267RnqbPMji5pwf/tyCJCQMnx5ZqJt3O30RiIYl2ur70IYJEGT1 RWpoIcOnrAQP76nv5IvUtYnTGfv4OhX1QSUErMoNvVVwtTreQ+OPoNa3Ozl/EB1fMCHt C6KbvDWVOSqHX8+jJplGxytGHB2y8HFTbFRQTzs9Vdr+3QIOVU1ARXX5Do6MH3DhAOaM 7YvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886267; x=1785491067; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=yuc+kiQDgL6coKIxn3rsMJs58ojI9P6Kgpsrlk3FLvM=; b=UrwUB4rQ8Wq4Wpk4s/9vUrq686wAM89Z/ZA+qPrGwxvr3W8dUlEHIyBEDVD9ts/21a 5eWxmgc5ES68wJhGAnb4RY2SSy256JwFu7CF5iAt9Gb+WvnVkocOJjiszvSDbCiUq3bf /bUP4EbTql7CgumBrsx/8Ifj88ATGbS5JulbnW+fCOWu5uCM/f4xJUYUAuoPT2HgytyD k/qtgSR8tSjrvfQ7SotdfdgHojMVs6BtQKtCIsf5xS30MQ6SRme89LCpB+ixa+SfofxC PdVyVGJ4uwCvWW9QatVGoTed5o+PWeqOTOQPDwygtl4w2ijVs/Gqkxy+N7njPjeXj1WW sJpA== X-Forwarded-Encrypted: i=1; AHgh+RqPZ5JYRvnfSYQDK7R+bwOh5JrR77XKCqmBHvmmXhizSOWKLqgT76R/Pf+iA0Jj0cInIcWfsGdfTwpzn4I=@vger.kernel.org X-Gm-Message-State: AOJu0YxOdcTY1Xv+xnQtInvQicDgHL23d5CW1PwoVyx5svHCyoCJm8w3 xzBeRvsweokNj0QMNElY73JZVVTCsdUf1kCuHp01gu5eNKQlgkqhPVwUXVg6fDCv X-Gm-Gg: AR+sD12GY/hgYQpGO9qOGsFk0jeTPhz9A1RpRP081mHHxBWZMk8sBoFc/QSlNhIcBq9 Nt8wY+m7iTI10IybOp3qENVW+iB2NsEP4t8AXk+DE91wEKDgpxMzOSBT64LcX6Mozs135FGWoGJ whKOfpaKtfyf8yZHaepc6XlDC+PKJ0htSwP9wBSYeqkVDKRmmEh70sfty1/RGzece0/HTPybvms 5AMhzU6inE/osB4qgV9eUo2t+5Ot0APGcQtMv9oRMd4/PoSEjBeXBXdYCScSAYl+hxja0Foy755 LIXhigYg1CrTonh1yrPmxpP4mnA1T3S7JYf5kNY073GiVE3seI7/CWT8QYQkmD3HVe/e7q+3eMZ R5dLYwX8sARKyoZ6lRXdPBFdKFqeqcSmeZ8noMY3zvmD+VNOMN1tscR4kZTes0rGh6LYfjyo1jp RKjiZvOnhr0qkXcrutXh6mCvyy8mzXDQ== X-Received: by 2002:a17:906:f596:b0:c16:64e3:945a with SMTP id a640c23a62f3a-c1c537c48d5mr291002866b.25.1784886266825; Fri, 24 Jul 2026 02:44:26 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32f1127fsm327406566b.55.2026.07.24.02.44.26 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:26 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 3/7] char: xillybus: Avoid possible bandwidth inefficiency Date: Fri, 24 Jul 2026 11:42:58 +0200 Message-Id: <20260724094302.50761-4-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The host flow controls the payload data flow from the FPGA by sending OPCODE_SET_CHECKPOINT messages. Fix the condition for sending such a message, to correctly handle the case where leap < 0. The previous expression leap > (fifo->size >> 3) was not intended to evaluate true when leap is negative. However, due to C's integer promotion rules, leap (of s32 type) is promoted to unsigned int when compared with the unsigned fifo->size >> 3 expression. As a result, negative leap values are interpreted as large positive numbers, causing the condition to evaluate true unintentionally. Consequently, the device receives correctly formed checkpoint messages that encourage it to send data, but too frequently. This may cause the device to send short data chunks, wasting USB bandwidth. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillyusb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xilly= usb.c index ab5f9159aa17..7d2434c02fa7 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -1507,8 +1507,8 @@ static ssize_t xillyusb_read(struct file *filp, char = __user *userbuf, */ =20 if (chan->read_data_ok && - (leap > (fifo->size >> 3) || - (checkpoint_for_complete && leap > 0))) { + (leap > 0 && (leap > (fifo->size >> 3) || + checkpoint_for_complete))) { chan->in_current_checkpoint =3D checkpoint; rc =3D xillyusb_send_opcode(xdev, chan_num, OPCODE_SET_CHECKPOINT, --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 3052141CB5C for ; Fri, 24 Jul 2026 09:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886273; cv=none; b=mNh/YaPb4MiMA9pfzosX83UcuQ5Cxcynv4jfCzeWHXxiTWGs56zjAlIC28Tl79zXIzH4FHBxhhGKQB393BBmAOPCf+RymE7YZ5Emw4U/a7MVu/FbrWajTR6wI5phLeburwjRlbtm8ckNfrKXyLMHKEmJ9KM15VVuuEYwJJce6T0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886273; c=relaxed/simple; bh=Dv+bY9RauteyeV/g853HpenpScE4tBDwQ8sOFX0Ybik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=QELG3bD2lXeEC0IjX5dDBD31yInKcud+rUeL9G5/ir6o+zMbPKqCgoSV3J441J2XUPJUHOBuubqk7lTdf9xdHuukCb/GOKdn9ONHOmkW7kJsZsNxHtCnj4BVnMPfJ8/nzLj3waFBrt9/iuO/gdVokQBiO2WkTj/TRnSWwVnKrgI= 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=YoFYNQ/Z; arc=none smtp.client-ip=209.85.218.51 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="YoFYNQ/Z" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-c197f968b3cso36771366b.2 for ; Fri, 24 Jul 2026 02:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886268; x=1785491068; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=h+OhafIneSQ53uhY2AzN2/or7dHkJV9E9pGuPyuaOKs=; b=YoFYNQ/ZyDIvPPYUSNWxxwGgPnkkbFPXLJpn9N2Uo+4gg3oW4X4x7cWnObAIWGgwGr rh6KttV5V+kF9maQhzIC0zsnL+iKNqVZkE3r103BWLT/7Y8U6MgfUOwRBr+6p8L7UF/Z BHJqybii3d+siP9fr5FNp2sVUk9nHrGKRBWE/uzxHZiQKMIM+tdSOLbTPI9UFa0k/7Yb 7KfelUPSZhh/7aIIm3Wb/ItPz8R+nDRTAI7XXb29Y4eG/CtgzRF0GXqrKqaQioycyTxU H8J0XMIuCz3HEVlh62PVbgtrJb3K3J80CfJiWlppf9noLo/edxQZqmb4YkLMcu92hTW6 lXEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886268; x=1785491068; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=h+OhafIneSQ53uhY2AzN2/or7dHkJV9E9pGuPyuaOKs=; b=JluHgoRnxcRzNV0rCNZVXlVxx0hATvM7vozBnSoP9F9THfgamFHX/V6fKZqIBWINVR VxiPDmNRV9aPUP0uL85P4h9IwhhtPs4tEn6dQK8Y8RE1maRLXLAbalzoonsxkqPsrFgn NBaCcUhyKQfAnlzzK80NxrABf1NR144qxe8lHR2fgw/2ZMQQSAKd3L8IyHFjq8BHRRqn d4qi29heOa4XKzXbTqXGc7lHc5zrvu0H59JYRhq1BTtgeLtuwIC5hUKXsr8S/UNcB0GG cakIZfHoovXcclgi7OKdAHqGScHyuMpvo4gUcVjzxNsCzAywvsFvVXgg3PeH1MJAkpZx PEWA== X-Forwarded-Encrypted: i=1; AHgh+Rq1tpPjqgSAXUXDZxpkSLdqsQk4WRKs3+vv1WZF0yA6Be4wTGk5KFib+d9Mrvou5t1FdP2ZWYrZj0nzJ1o=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2QVIEImDiPRIF2RWd+QK36RLzqPRtkPmPns5giwpN4ZCKg+uK f1VGIlKQmfugdDeesZGQuYztbsFAEx/glYnwGcFTZaCds6bJdt9SE9Cq X-Gm-Gg: AR+sD13xBKWKXqFOiOLmYFTEvXfrcdC+2vpewqv7KFnyPrre8dad0f4RSc0Bjl2qx62 gllXFNRd+eTgygZl23yuMobk4TYroZMhfT/uWO7FMC+Rm+RBQSPhR44ru1xB5EmtDh+029vQMK1 wwK3TFxub0slVrPLiTU81th14wDVb1qjoko5S8kQoEnZi+gAoKG2+M8jmHI7XDFlOKNvtz8OTqm S8+f5FF8fsdiNnYWQV8RCVsbaSo1oaPxU++6vv6QqSmg1zf5YcpUhMIxoiu9dpC3nlNcrboKx4s TGGqQ8GUodDREK1SXC6GvKt/eXshCD3L2EK5r4qgmGJj4b5JwqA9GkG9c5hKNyOY8oD8iJn3XU8 qhsq2TAzItOoPlI8jf2xuT2Ya/CKccWJGhAYgynd55zKvLJr+HjMudd3fO+Nozi9bEvR4FTNpzJ lwMmr09rjGwg/H6wDjn3zT1NvkVy1P8A== X-Received: by 2002:a17:907:d09:b0:c15:c108:dcd with SMTP id a640c23a62f3a-c1c509bbd04mr362329466b.49.1784886268368; Fri, 24 Jul 2026 02:44:28 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32a798a5sm329410566b.9.2026.07.24.02.44.27 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:28 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 4/7] char: xillybus: Use unsigned arithmetic for jiffies differences Date: Fri, 24 Jul 2026 11:42:59 +0200 Message-Id: <20260724094302.50761-5-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Change the type of jiffies-related deadline variables from long to unsigned long, and remove unnecessary casts when computing time remaining as deadline - jiffies. No functional change is expected: although signed overflow is undefined in the C standard, processors perform the calculation correctly in practice. Using unsigned arithmetic is nevertheless the proper way to handle jiffies differences. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillybus_core.c | 5 +++-- drivers/char/xillybus/xillyusb.c | 17 ++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/= xillybus_core.c index 952ef149aba1..7acebc1e6050 100644 --- a/drivers/char/xillybus/xillybus_core.c +++ b/drivers/char/xillybus/xillybus_core.c @@ -694,7 +694,8 @@ static ssize_t xillybus_read(struct file *filp, char __= user *userbuf, unsigned long flags; int bytes_done =3D 0; int no_time_left =3D 0; - long deadline, left_to_sleep; + unsigned long deadline; + long left_to_sleep; struct xilly_channel *channel =3D filp->private_data; =20 int empty, reached_eof, exhausted, ready; @@ -938,7 +939,7 @@ static ssize_t xillybus_read(struct file *filp, char __= user *userbuf, return -EINTR; } =20 - left_to_sleep =3D deadline - ((long) jiffies); + left_to_sleep =3D deadline - jiffies; =20 /* * If our time is out, skip the waiting. We may miss wr_sleepy diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xilly= usb.c index 7d2434c02fa7..aa08206a18ef 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -1127,12 +1127,13 @@ static int xillyusb_send_opcode(struct xillyusb_dev= *xdev, */ =20 static int flush_downstream(struct xillyusb_channel *chan, - long timeout, + unsigned long timeout, bool interruptible) { struct xillyusb_dev *xdev =3D chan->xdev; int chan_num =3D chan->chan_idx << 1; - long deadline, left_to_sleep; + unsigned long deadline; + long left_to_sleep; int rc; =20 if (chan->flushed) @@ -1141,7 +1142,8 @@ static int flush_downstream(struct xillyusb_channel *= chan, deadline =3D jiffies + 1 + timeout; =20 if (chan->flushing) { - long cancel_deadline =3D jiffies + 1 + XILLY_RESPONSE_TIMEOUT; + unsigned long cancel_deadline =3D + jiffies + 1 + XILLY_RESPONSE_TIMEOUT; =20 chan->canceled =3D 0; rc =3D xillyusb_send_opcode(xdev, chan_num, @@ -1152,7 +1154,7 @@ static int flush_downstream(struct xillyusb_channel *= chan, =20 /* Ignoring interrupts. Cancellation must be handled */ while (!chan->canceled) { - left_to_sleep =3D cancel_deadline - ((long)jiffies); + left_to_sleep =3D cancel_deadline - jiffies; =20 if (left_to_sleep <=3D 0) { report_io_error(xdev, -EIO); @@ -1202,7 +1204,7 @@ static int flush_downstream(struct xillyusb_channel *= chan, } =20 while (chan->flushing) { - left_to_sleep =3D deadline - ((long)jiffies); + left_to_sleep =3D deadline - jiffies; =20 if (left_to_sleep <=3D 0) return -ETIMEDOUT; @@ -1435,7 +1437,8 @@ static ssize_t xillyusb_read(struct file *filp, char = __user *userbuf, struct xillyfifo *fifo =3D chan->in_fifo; int chan_num =3D (chan->chan_idx << 1) | 1; =20 - long deadline, left_to_sleep; + unsigned long deadline; + long left_to_sleep; int bytes_done =3D 0; bool sent_set_push =3D false; int rc; @@ -1464,7 +1467,7 @@ static ssize_t xillyusb_read(struct file *filp, char = __user *userbuf, bytes_done +=3D rc; chan->in_consumed_bytes +=3D rc; =20 - left_to_sleep =3D deadline - ((long)jiffies); + left_to_sleep =3D deadline - jiffies; =20 /* * Some 32-bit arithmetic that may wrap. Note that --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 2D26D41DED2 for ; Fri, 24 Jul 2026 09:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886273; cv=none; b=CAdEBYYbABqEROPsoIaQukuNgC70Zkido6ygCnflTJiMGIb5I8ZnpiXjF0KfC2lu+tBcurpEfq8iUhR2P/XFSKxnNAAacgIZTFSr5QORXiYwjUgrLwNFRkMyoFIFim9/xth4ctoO6QkphRShV/FzHpR+rqbt3/I0dsPQwtGkYRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886273; c=relaxed/simple; bh=eR7+Xd+VqrkaMibHzXeZvPDiNxOe5G2DypMol5wF6h8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=k92obSatrR8YTwmH4ckBj7ww63XAVi8bsM+b8VLzBnxramipUSe3ghEw3XKeq7H/4LChdnjE6MY86DBjbEDYRj4BMOAZh2KxJg9vNQnAhARRKp1bIqpYOhqQebNcRd7aVqlcLfMB6bYF3lLtL0qoCe5MKMXTuDlXH+ETH1dSXP8= 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=sSGVNfXw; arc=none smtp.client-ip=209.85.208.44 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="sSGVNfXw" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-69e28b554ceso383155a12.0 for ; Fri, 24 Jul 2026 02:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886270; x=1785491070; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Be81MoWCkWbNVBXpOEfawVOZ99FwymP5loMauubaj34=; b=sSGVNfXwpQGBxPQJGcfq857SW2QkNaGGtuegVnMWyDQe9sqvjgKGuu74bg5hBGlhJh jUtyunalYBvk/IZVAPnr4SEQcDx07zPMNli0cg2jNe7eSbhdeOP8ua6WPbpuX5Z6b6ay BmwtTrFoXfLQQr/2UbRm/N4ndmrJWGVELKP5NS+FRBnRW11ZrS1PZ6U2xRpi0VoqD1aC riadr9QP+VkaAfKZTKKY9jhJnlU2dNmyMeOR4ertAWWhtfbYhqkzUyaP97OkO0q6B96u pCagqUPbb9Eo9fi/nmTsUt2WTVFu6pxHnGvzVyd+pbCWrJbYU5w2o9wbnhd60x5NeSoz TQzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886270; x=1785491070; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Be81MoWCkWbNVBXpOEfawVOZ99FwymP5loMauubaj34=; b=KKuFFgD0U4SBAATV78QiB9LbgYtgpUkYmGmLxq7GbPAzoIWBR1K1874sRFqD5KIbPg TYDBJ7+zMGPeQJK1PnO+5KHH8Hb5yJumVAFlPEfoT0WVfQbEdP+UyJ+c229KWlzoXDvL tuDK5YucTWcpYt4/C1bFz20ftxGKWO1skgrZjq/27qhVdZbPaPa/X6VM14G2vUt9bfVI E9+PoObCe2muPzSYZsitdO7fDRN8rlcDBNecyPCxkHhagYBKIUFRc4qtc4kUfKUDN7IS memkBXN8jrkHRytQGUMEs5Mmvsxa/CByUQrOAn7hxjY3D0sDaAUXmRwtiHK8zojXDaGl 9gsg== X-Forwarded-Encrypted: i=1; AHgh+RruF+SrPusDNaLU77XJRg7s+Vpo7XmTPzXeiJFY8nLryV3KfxI3dZXQeixkfu6O78jV6fmzg6jqBOxKvvI=@vger.kernel.org X-Gm-Message-State: AOJu0YxOrx+SKecG4PD/Rc10bDAWsQYs1t0U5V+zuUEaRueIVFN+KXIY U4BodoEjHVxs+bkaEJkvK88+Z7593EvhHZlXsHVKyuEcTV6r0Ghe3BK9 X-Gm-Gg: AR+sD11XwbWTVIvBxtp1rt+ihE1SWlYC3mcEGolmwjnHdEmkX68uEhGd1LkdCoXWB2I UBzPxYzQ0T2qeM1p2jW0eC/0vb/GIXVFvLoXw4INAo1QJR/MIcUcAnmhcPetbSEAeTfokAWaD8B g1RQ1FUM/XEFpxI4wC4dh0HIWr/6+jBbEIj5VAm2sK7Ju5AYii1gwNadk7A6orS3WOr/JGy4c3i Mgi+XlMiB8bdf14gSjBjNLVKwcoQv9RLq9FJtAZ3xOIB1YLOdaHDvu3Kx8z5ixUsmwcSQyHaryq woxGL4EsWGuMsiJt/pddmg4y8edIvRN/G/Xy9DLqRBYJxuWLRDZZxBMyeiyKc6peObGY2w4uTxE B2IHmBfNsat8XkEAx1LPPng7HIkOJA+qrpSCxinwdUPjoRKoVj0b4M0amZT2HLFZ3oMS9EzqLJP nEH2w9PXvm/uQC2LIQdRdhJBn2gPfKvg== X-Received: by 2002:a17:906:730f:b0:c15:b133:9dfe with SMTP id a640c23a62f3a-c1c50c401c6mr310536966b.43.1784886269898; Fri, 24 Jul 2026 02:44:29 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32a76fecsm330490866b.8.2026.07.24.02.44.29 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:29 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 5/7] char: xillybus: Integer arithmetic improvements Date: Fri, 24 Jul 2026 11:43:00 +0200 Message-Id: <20260724094302.50761-6-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Choose unsigned integers instead of signed where natural, and also ensure overflow wraps as expected. Simplify an arithmetic expression too. No functional change is expected, as the relevant variables normally never reach values where this transition matters. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillybus_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/= xillybus_core.c index 7acebc1e6050..b264578b2572 100644 --- a/drivers/char/xillybus/xillybus_core.c +++ b/drivers/char/xillybus/xillybus_core.c @@ -343,7 +343,8 @@ static int xilly_map_single(struct xilly_endpoint *ep, static int xilly_get_dma_buffers(struct xilly_endpoint *ep, struct xilly_alloc_state *s, struct xilly_buffer **buffers, - int bufnum, int bytebufsize) + unsigned int bufnum, + unsigned int bytebufsize) { int i, rc; dma_addr_t dma_addr; @@ -431,8 +432,8 @@ static int xilly_setupchannels(struct xilly_endpoint *e= p, struct device *dev =3D ep->dev; int i, entry, rc; struct xilly_channel *channel; - int channelnum, bufnum, bufsize, format, is_writebuf; - int bytebufsize; + unsigned int channelnum, bufnum, bufsize, format, is_writebuf; + unsigned int bytebufsize; int synchronous, allowpartial, exclusive_open, seekable; int supports_nonempty; int msg_buf_done =3D 0; @@ -531,8 +532,7 @@ static int xilly_setupchannels(struct xilly_endpoint *e= p, channel->log2_element_size =3D ((format > 2) ? 2 : format); =20 - bytebufsize =3D bufsize * - (1 << channel->log2_element_size); + bytebufsize =3D bufsize << channel->log2_element_size; =20 buffers =3D devm_kcalloc(dev, bufnum, sizeof(struct xilly_buffer *), @@ -589,7 +589,7 @@ static int xilly_setupchannels(struct xilly_endpoint *e= p, static int xilly_scan_idt(struct xilly_endpoint *endpoint, struct xilly_idt_handle *idt_handle) { - int count =3D 0; + unsigned int count =3D 0; unsigned char *idt =3D endpoint->channels[1]->wr_buffers[0]->addr; unsigned char *end_of_idt =3D idt + endpoint->idtlen - 4; unsigned char *scan; --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 8AD6C42046D for ; Fri, 24 Jul 2026 09:44:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886275; cv=none; b=IwY88PjkfoF5W0ZslREkpYjHugv1oeCHfrMhvhfcGVK2r2bNxq+fWZLK7tr2JWnAjztKNWt0h4A6Et390ESOl5OwWV/24OV2iZbX/FHlmIJGRMqtCRKVpG8cGnaltZPPlg1T9ICW719z8kbyGDox3pAMY0i0C2hGNHHUoKzcUwU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886275; c=relaxed/simple; bh=H5N5sy21MKlfRcNnXzrMqAK4+OX58u35diz43V104Z4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=TqXppnmW8xfC+7J0X8hWv7Kz9e3IoHuKwlN0UsCcXwfnxzEiNz9AVRKFPdOr/1YOYXVorkaRVWsdaxXBxLXhLkyTRlrXlLSL8S9NpTz9MZvgzKqKjfKwSoMl3ttikdzOscx42lPNDY7TycCYPzjuQzmA6u4e6lldxmekfIabOQ4= 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=YeyDRVQa; arc=none smtp.client-ip=209.85.208.50 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="YeyDRVQa" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-698bf053053so324112a12.3 for ; Fri, 24 Jul 2026 02:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886272; x=1785491072; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=uOxeeeUe03Lp2o+lDboMOBPZatL9F/0sqHMnsrQyzRw=; b=YeyDRVQajLrfPLWtT3Bs3X+MD+hBh0QY3Ryi4t1hHHxAeg68Shqj2KBHKQSRXjxSOJ r5DY3PmiUlVuTk5/htKQt/BZEV7xbKxAJGa1uWDZrq4I6tFkBmnsa6VTNMTHvLUPbxIB DQ01ZZPzSvK8fZMPFRACmcWboI6st+k8LljRU4GQdCia+bNpUA/rWWTxkiZerLnFUkup m/u66VuiK3DU2lhhmurYo59MkO0xXU8Ll+90GCxm9g4ZmVr2DuPnYGA8sNxxmpw2Pitd vtijM7IONOmWNNk7GO7joxX+o9Pyb16T+nFexO2/DlL+YKVymv9P4BoPas2NrVey3HI2 z3Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886272; x=1785491072; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uOxeeeUe03Lp2o+lDboMOBPZatL9F/0sqHMnsrQyzRw=; b=MBMIwW4i39Kk3pKYuVx+PiIqvLsKgDs4ykB3F3k+/HI0TipRy6HBzsipyTzz8p+EuX Tufut7m6qHL4gMK8CPMC2ZrGkx906C4Qi8pUIZzIO/iCpu6wRBegYnZE02ze4LS6Fdr+ KB9yVNGfCFYj/LCFP/Dq9dF7nEN9+xfMXapssMRWTt+mv9VLJTCkdF6XxhQ7hhBeaSSD q9nazZpDgeE0vOH1QaU+m11gpX9Qf+9E7Fw/9Mg2E/pycB+ZBvbf3jP/EW9CWMO7I80W Lgm3LI8heMvNt5CPqvwdaADlNHd0aDTl0kqDaY4QqGlEetBhMlohKuIhzLpK40wKWf74 oc4A== X-Forwarded-Encrypted: i=1; AHgh+RqL0I/hZZzB9soUFmBVjIakSczt2EKC54JEZyoMtHnR+4EP3egDwPhWgtI6xWJ50fKdZ6ujO1uRjiH5GrY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9spV2+MgnKfUuGqRXRfuUqhVWZ8fzFb9ixjAFWf2eVw3ocNmh dkBg4Ian/Y7bouLR7VH5+3ou5Gi0ZzvM+3k8DoAxMaTYzaess0sTro6m X-Gm-Gg: AR+sD10Jv/3123zCD5Ob4mFOx8H8O9gkQOJu684/YhXx9PbnTtVjNJw34vZ2P8q6NwH 2ru7efsInsql+aC4tHAYWUyzGetCqOkB2KDpVy50AnCmwokFEKXtWEBOdQnnJbHEHYEOlGPZLTY JTaYs2IOg9+RM7lChHNCGR5OAZO7tRwTeY0lLu4Llz2uUiNL87uAw+wofeccBmYoMcg0878/mfI uWCc93LtmFfu0gkYz1oLSooF5QkVgl62L0p1g0Cn/cw6r+XFEyYpO3LTDDhmQZrD4rbX7ia5akC K2M7UyIRm8HFMxN5RoHcVdbsfONMVmU/Z7tibcDPh+NbYwQRYdcddih1+wEx9DOrsWIP3w1AKC7 7WioToxjS6Q0nKFzIYmn1wodjKThHm/V6vfmyHVf+p4unZmGlyScwpH14zLXbBgpwRH1PS1cfEv NtYhu+c3zdZ07uxX0+bGxv7LxUM3/v2OYVvMw6Td+3 X-Received: by 2002:a17:906:794c:b0:c15:f26a:342f with SMTP id a640c23a62f3a-c1c507b60d9mr268791266b.23.1784886271501; Fri, 24 Jul 2026 02:44:31 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32c902d2sm319070866b.34.2026.07.24.02.44.30 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:31 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 6/7] char: xillybus: Add defensive sanity checks Date: Fri, 24 Jul 2026 11:43:01 +0200 Message-Id: <20260724094302.50761-7-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add validation checks for values derived from hardware or user input to prevent incorrect behavior with malformed data. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 Changes v1->v2: -- xillybus_class.c: Assign @rc a value before goto in xillybus_init_chrdev(). -- xillybus_class.c: Improve check on @inode in xillybus_find_inode(). -- xillybus_of.c: Remove redundant dev_err(), as platform_get_irq() outputs an error message if necessary. drivers/char/xillybus/xillybus_class.c | 18 +++++++++++-- drivers/char/xillybus/xillybus_class.h | 4 +++ drivers/char/xillybus/xillybus_core.c | 37 ++++++++++++++++++++++++-- drivers/char/xillybus/xillybus_of.c | 3 +++ drivers/char/xillybus/xillyusb.c | 29 +++++++++++++++++++- 5 files changed, 86 insertions(+), 5 deletions(-) diff --git a/drivers/char/xillybus/xillybus_class.c b/drivers/char/xillybus= /xillybus_class.c index 5e8f03b77064..f7e0da233e2a 100644 --- a/drivers/char/xillybus/xillybus_class.c +++ b/drivers/char/xillybus/xillybus_class.c @@ -57,6 +57,9 @@ int xillybus_init_chrdev(struct device *dev, size_t namelen; struct xilly_unit *unit, *u; =20 + if (num_nodes <=3D 0 || num_nodes > XILLYBUS_MAX_NODES || !idt || !prefix= || !dev) + return -ENODEV; + unit =3D kzalloc_obj(*unit); =20 if (!unit) @@ -68,6 +71,12 @@ int xillybus_init_chrdev(struct device *dev, snprintf(unit->name, UNITNAMELEN, "%s", prefix); =20 for (i =3D 0; enumerate; i++) { + if (i > 99) { + dev_err(dev, "Failed to obtain unique unit name\n"); + rc =3D -ENODEV; + goto fail_obtain; + } + snprintf(unit->name, UNITNAMELEN, "%s_%02d", prefix, i); =20 @@ -215,10 +224,15 @@ EXPORT_SYMBOL(xillybus_cleanup_chrdev); int xillybus_find_inode(struct inode *inode, void **private_data, int *index) { - int minor =3D iminor(inode); - int major =3D imajor(inode); + int minor, major; struct xilly_unit *unit =3D NULL, *iter; =20 + if (!inode || !private_data || !index) + return -ENODEV; + + minor =3D iminor(inode); + major =3D imajor(inode); + mutex_lock(&unit_mutex); =20 list_for_each_entry(iter, &unit_list, list_entry) diff --git a/drivers/char/xillybus/xillybus_class.h b/drivers/char/xillybus= /xillybus_class.h index 5dbfdfc95c65..264b9f6d6793 100644 --- a/drivers/char/xillybus/xillybus_class.h +++ b/drivers/char/xillybus/xillybus_class.h @@ -8,6 +8,10 @@ #ifndef __XILLYBUS_CLASS_H #define __XILLYBUS_CLASS_H =20 +#define XILLYBUS_MAX_COUNT (((unsigned int) ~0x1ffff) >> 1) +#define XILLYBUS_MAX_NODES 1024 +#define XILLYBUS_MAX_IDT 1048576 + #include #include #include diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/= xillybus_core.c index b264578b2572..3436f16092e0 100644 --- a/drivers/char/xillybus/xillybus_core.c +++ b/drivers/char/xillybus/xillybus_core.c @@ -351,6 +351,12 @@ static int xilly_get_dma_buffers(struct xilly_endpoint= *ep, struct device *dev =3D ep->dev; struct xilly_buffer *this_buffer =3D NULL; /* Init to silence warning */ =20 + if (bytebufsize =3D=3D 0 || bytebufsize > 0x40000000) { + dev_err(ep->dev, + "Illegal buffer size requested in IDT. Aborting.\n"); + return -ENODEV; + } + if (buffers) { /* Not the message buffer */ this_buffer =3D devm_kcalloc(dev, bufnum, sizeof(struct xilly_buffer), @@ -623,6 +629,12 @@ static int xilly_scan_idt(struct xilly_endpoint *endpo= int, return -ENODEV; } =20 + if (count =3D=3D 0 || count > XILLYBUS_MAX_NODES) { + dev_err(endpoint->dev, + "Unreasonable number of channels. Aborting.\n"); + return -ENODEV; + } + idt_handle->entries =3D len >> 2; endpoint->num_channels =3D count; =20 @@ -707,6 +719,9 @@ static ssize_t xillybus_read(struct file *filp, char __= user *userbuf, if (channel->endpoint->fatal_error) return -EIO; =20 + if (count > XILLYBUS_MAX_COUNT) + count =3D XILLYBUS_MAX_COUNT; + deadline =3D jiffies + 1 + XILLY_RX_TIMEOUT; =20 rc =3D mutex_lock_interruptible(&channel->wr_mutex); @@ -725,8 +740,18 @@ static ssize_t xillybus_read(struct file *filp, char _= _user *userbuf, bufidx =3D channel->wr_host_buf_idx; bufpos =3D channel->wr_host_buf_pos; howmany =3D ((channel->wr_buffers[bufidx]->end_offset - + 1) << channel->log2_element_size) - - bufpos; + + 1) << channel->log2_element_size); + + if (howmany > channel->wr_buf_size || + howmany < bufpos) { + dev_err(channel->endpoint->dev, + "Illegal buffer fill level from hardware\n"); + channel->endpoint->fatal_error =3D 1; + spin_unlock_irqrestore(&channel->wr_spinlock, flags); + break; + } + + howmany -=3D bufpos; =20 /* Update wr_host_* to its post-operation state */ if (howmany > bytes_to_do) { @@ -1216,6 +1241,9 @@ static ssize_t xillybus_write(struct file *filp, cons= t char __user *userbuf, if (channel->endpoint->fatal_error) return -EIO; =20 + if (count > XILLYBUS_MAX_COUNT) + count =3D XILLYBUS_MAX_COUNT; + rc =3D mutex_lock_interruptible(&channel->rd_mutex); if (rc) return rc; @@ -1902,6 +1930,11 @@ int xillybus_endpoint_discovery(struct xilly_endpoin= t *endpoint) return -ENODEV; } =20 + if (endpoint->idtlen < 4 || endpoint->idtlen > XILLYBUS_MAX_IDT) { + dev_err(endpoint->dev, "Invalid IDT length. Aborting.\n"); + return -ENODEV; + } + /* Enable DMA */ iowrite32((u32) (0x0002 | (endpoint->dma_using_dac & 0x0001)), endpoint->registers + fpga_dma_control_reg); diff --git a/drivers/char/xillybus/xillybus_of.c b/drivers/char/xillybus/xi= llybus_of.c index 46e1046abfca..44b0c754deb2 100644 --- a/drivers/char/xillybus/xillybus_of.c +++ b/drivers/char/xillybus/xillybus_of.c @@ -53,6 +53,9 @@ static int xilly_drv_probe(struct platform_device *op) =20 irq =3D platform_get_irq(op, 0); =20 + if (irq < 0) + return irq; + rc =3D devm_request_irq(dev, irq, xillybus_isr, 0, xillyname, endpoint); =20 if (rc) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xilly= usb.c index aa08206a18ef..7459ec9295af 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -396,6 +396,10 @@ static int fifo_init(struct xillyfifo *fifo, fifo->size =3D fifo->bufnum * fifo->bufsize; fifo->buf_order =3D buf_order; =20 + if (!fifo->size || /* Unsigned integer overflow */ + fifo->size > 0x40000000) /* Stay clear from signed int issues */ + return -ENOMEM; /* Reported as greed for memory */ + fifo->mem =3D kmalloc_array(fifo->bufnum, sizeof(void *), GFP_KERNEL); =20 if (!fifo->mem) @@ -888,6 +892,7 @@ static int process_in_opcode(struct xillyusb_dev *xdev, struct xillyusb_channel *chan; struct device *dev =3D xdev->dev; int chan_idx =3D chan_num >> 1; + struct xillyfifo *in_fifo; =20 if (chan_idx >=3D xdev->num_channels) { dev_err(dev, "Received illegal channel ID %d from FPGA\n", @@ -912,7 +917,10 @@ static int process_in_opcode(struct xillyusb_dev *xdev, */ smp_wmb(); WRITE_ONCE(chan->read_data_ok, 0); - wake_up_interruptible(&chan->in_fifo->waitq); + + in_fifo =3D READ_ONCE(chan->in_fifo); + if (in_fifo) + wake_up_interruptible(&in_fifo->waitq); break; =20 case OPCODE_REACHED_CHECKPOINT: @@ -1443,6 +1451,9 @@ static ssize_t xillyusb_read(struct file *filp, char = __user *userbuf, bool sent_set_push =3D false; int rc; =20 + if (count > XILLYBUS_MAX_COUNT) + count =3D XILLYBUS_MAX_COUNT; + deadline =3D jiffies + 1 + XILLY_RX_TIMEOUT; =20 rc =3D mutex_lock_interruptible(&chan->in_mutex); @@ -1649,6 +1660,9 @@ static ssize_t xillyusb_write(struct file *filp, cons= t char __user *userbuf, struct xillyfifo *fifo =3D &chan->out_ep->fifo; int rc; =20 + if (count > XILLYBUS_MAX_COUNT) + count =3D XILLYBUS_MAX_COUNT; + rc =3D mutex_lock_interruptible(&chan->out_mutex); =20 if (rc) @@ -2072,6 +2086,13 @@ static int xillyusb_discovery(struct usb_interface *= interface) } =20 idt_len =3D READ_ONCE(idt_fifo.fill); + + if (idt_len < 4 || idt_len > XILLYBUS_MAX_IDT) { + rc =3D -ENODEV; + dev_err(&interface->dev, "Invalid IDT length. Aborting.\n"); + goto unfifo; + } + idt =3D kmalloc(idt_len, GFP_KERNEL); =20 if (!idt) { @@ -2106,6 +2127,12 @@ static int xillyusb_discovery(struct usb_interface *= interface) goto unidt; } =20 + if (num_channels =3D=3D 0 || num_channels > XILLYBUS_MAX_NODES) { + dev_err(&interface->dev, "Unreasonable number of channels. Aborting.\n"); + rc =3D -ENODEV; + goto unidt; + } + rc =3D setup_channels(xdev, (void *)idt + 3, num_channels); =20 if (rc) --=20 2.34.1 From nobody Fri Jul 24 21:52:38 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 2E68041F7F2 for ; Fri, 24 Jul 2026 09:44:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886276; cv=none; b=Ph/ZZTr4azm6Zgbwda0xXzintcq+ds7RYnxLD/3gxhlTRwS4Zju3SxRENZ3B8xle5ENh2Cl0WXrN473BxhG3XkmMUxv/9vbMbBzbbJAr7T1243C2Mnr2Ycxg9/BI7stqIne6U05lZv9lFjC+8Ah1XBie8+Y5Tx5nvNTrH8o8EEg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784886276; c=relaxed/simple; bh=WWpWZmEo0SA7ZK5K2j4Y+nwBCA6XRx9UwXUrSHx9nSY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=SnNooerzHGRQKeRFk4JG2F/LrTXEqvZHEiXdwDHEoE2MLGgfSMw6P+gQGqb5kVsHAJr3t5xXEA6Y9l/gVfNE5G/oo1TTzpuhie+BtcOfCTTN21X2XpU+P3Wv5j+lG+LG0Dkyn4lBSz8Zhhuxl4BFBoPiZtGxKwdxq5EnWmAwjgM= 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=Ww58IsAs; arc=none smtp.client-ip=209.85.218.54 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="Ww58IsAs" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-c197eaaab00so39360466b.0 for ; Fri, 24 Jul 2026 02:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784886273; x=1785491073; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=jiFXlmUHbUTL6H6Ji2BpOJqmyMj4AtdFF5lJdRApy60=; b=Ww58IsAsrFYTLD3oP+Ga79mtYnAG2UMzq4DYwvXNKLbYC03l/T37O6Le6lLh3jz8tE OMjw8SFZhgBOUAZKubU0tGkZqEOxEk38FFTAOrOBL5U9E0K03Ut5aClX/lFqcpkTPmHo peC08ozdACbQqoA3C1sH58QSrRAvZZ9ifb2zK479cs3HhliMzgeuXhumTYVgg2l4OMAS Ei1k7/d72yNcmy6mzYR1QIFc7cpBDRQ+eCPVJDlcyJ5BbFQDBsuasrpGymT6aD8MrpJ5 2CIR+nTHiWFoPoWiQkkM1jzOvPKPUTZHqoL8otiwkCzAWSqV6Y7TGPoZPXdwVgRIEBpr a6vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784886273; x=1785491073; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jiFXlmUHbUTL6H6Ji2BpOJqmyMj4AtdFF5lJdRApy60=; b=EDgXjMBePjyGI+Gezs3tG1geGzHOkMlbVKA9XBKa7HNfXD01CHNk7KHuFjv5u3I8qR WMRCuUBTtZIBGbsD97ITZoblIP1bi6FmvzNbvsvAnFm3l4YAZ8q1KaPpgZjRfuSlgXKF dg3rTr2HnzZnjH7djiKq9DcsB5jralSNdkhvVMR/BuS4bc5kubHcgh5CQCaHiAX0T19a hFJP2WFuLXWnCmuP+39KfYh9nNgO+3ETe0vuoPoA33VQ3KKm56cOw2952C/COzSWSu4a LB/gR2CntuBfcAJlpSQ6vuSu4s1y//iW0U1jE6/td8ZSdO2xCn2z9rSdRh8UWDXxqLxP JGVA== X-Forwarded-Encrypted: i=1; AHgh+RrtZbxPUs+ww8DRK2qyO3At98Mqf4jvgox0COdLvNIstH1lQdEiKTs15nuIjD8XwyGEqdwn1Q7PDQpP9Yk=@vger.kernel.org X-Gm-Message-State: AOJu0YwNFSoxsvBCypHJK6yeQj/QMYE3x7yf9+d9xKYyAdId6ijC2R/v 2uSiMw4UuSK2KpIZNrYp6Nl2YQ0s4CMLCDKg7jJcv0wbw/iqW3ply1G3 X-Gm-Gg: AR+sD10iysRzKO3rzBPq1/KttuqLveYxGOQX6C04P5d4HY7NgjPOn7T1shrgmXL9J04 b3fZxhwqtSBTwFw4LyDnL5JY7ac0Hzj7Elw9vWUydK5HQt7Y70J2M46utRM2206KTs0T9DJXw7n 5IlqR7IYQx4zQvTVUqDSh6y8ZvelMYJfk+gjhDbyXh3W3CM8mIAHuc2SXcJ49P83UJHgfFJ2WlG 8+t9A5h6cq1kin/Ug0hGZU1ppSsL5yUZ/ao5RmwrMDj0Zvu7ot8vjTh3MJ31sf+OQyC9WUemk6u s80Bu+rvKgBsACbYzIL7f5PDUSK1HRm59hBGFW+v92bv5RBhU6vrHW38qmoT5iro6y7u0nizj3S NLAxnvxbgP228pr2V3/dTaG2N2vUgFx9YnlmP4UNCAXofB+jzWLgmX8uIZ0nIKEeM63PDVE8T0h dlp974hkGuz9xT0MBkHtd8ZAesg8AUyVCbmwArtEKw X-Received: by 2002:a17:907:fd0f:b0:c16:9bd:39cb with SMTP id a640c23a62f3a-c1c50c6cb4bmr279328466b.52.1784886273144; Fri, 24 Jul 2026 02:44:33 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1d0a73520csm44064866b.1.2026.07.24.02.44.32 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 24 Jul 2026 02:44:32 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v3 7/7] char: xillybus: Ignore and report unsolicited interrupts Date: Fri, 24 Jul 2026 11:43:02 +0200 Message-Id: <20260724094302.50761-8-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260724094302.50761-1-eli.billauer@gmail.com> References: <20260724094302.50761-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" During initialization, the hardware should issue interrupts only in response to requests from the host. Ignore and log unexpected interrupts, as these indicate misbehaving hardware. In the same spirit, in xilly_quiesce(), assign endpoint->num_channels =3D 0 before allowing the ISR, in order to expose whether the hardware incorrectly sends messages related to data channels during shutdown. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changes v2->v3: -- Add Assisted-by tag to description =20 No change on v1->v2. drivers/char/xillybus/xillybus.h | 3 ++ drivers/char/xillybus/xillybus_core.c | 46 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/char/xillybus/xillybus.h b/drivers/char/xillybus/xilly= bus.h index 51de7cbc579e..98c7ac4dd1f9 100644 --- a/drivers/char/xillybus/xillybus.h +++ b/drivers/char/xillybus/xillybus.h @@ -94,6 +94,9 @@ struct xilly_endpoint { __iomem void *registers; int fatal_error; =20 + bool allow_isr; + spinlock_t allow_isr_lock; + struct mutex register_mutex; wait_queue_head_t ep_wait; =20 diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/= xillybus_core.c index 3436f16092e0..ea0debe24968 100644 --- a/drivers/char/xillybus/xillybus_core.c +++ b/drivers/char/xillybus/xillybus_core.c @@ -72,6 +72,8 @@ static struct workqueue_struct *xillybus_wq; * * rd_spinlock does the same with rd_*_buf_idx, rd_empty and end_offset. * + * allow_isr_lock protects allow_isr. + * * register_mutex is endpoint-specific, and is held when non-atomic * register operations are performed. wr_mutex and rd_mutex may be * held when register_mutex is taken, but none of the spinlocks. Note that @@ -84,7 +86,8 @@ static struct workqueue_struct *xillybus_wq; * Only interruptible blocking is allowed on mutexes and wait queues. * * All in all, the locking order goes (with skips allowed, of course): - * wr_mutex -> rd_mutex -> register_mutex -> wr_spinlock -> rd_spinlock + * wr_mutex -> rd_mutex -> register_mutex -> + * allow_isr_lock -> wr_spinlock -> rd_spinlock */ =20 static void malformed_message(struct xilly_endpoint *endpoint, u32 *buf) @@ -119,6 +122,13 @@ irqreturn_t xillybus_isr(int irq, void *data) unsigned int msg_channel, msg_bufno, msg_data, msg_dir; struct xilly_channel *channel; =20 + guard(spinlock)(&ep->allow_isr_lock); + + if (!ep->allow_isr) { + dev_err_ratelimited(ep->dev, "Unexpected interrupt! Something is wrong w= ith the hardware.\n"); + return IRQ_HANDLED; + } + buf =3D ep->msgbuf_addr; buf_size =3D ep->msg_buf_size/sizeof(u32); =20 @@ -283,6 +293,19 @@ irqreturn_t xillybus_isr(int irq, void *data) } EXPORT_SYMBOL(xillybus_isr); =20 +/* + * xilly_allow_isr() is similar to enabling / disabling the interrupt, + * with the difference that if an interrupt is issued while ep->allow_isr + * is false, this is visible in the kernel log. + */ + +static void xilly_allow_isr(struct xilly_endpoint *ep, bool newstate) +{ + guard(spinlock_irqsave)(&ep->allow_isr_lock); + + ep->allow_isr =3D newstate; +} + /* * A few trivial memory management functions. * NOTE: These functions are used only on probe and remove, and therefore @@ -651,6 +674,8 @@ static int xilly_obtain_idt(struct xilly_endpoint *endp= oint) =20 channel->wr_sleepy =3D 1; =20 + xilly_allow_isr(endpoint, true); + iowrite32(1 | (3 << 24), /* Opcode 3 for channel 0 =3D Send IDT */ endpoint->registers + fpga_buf_ctrl_reg); @@ -659,6 +684,8 @@ static int xilly_obtain_idt(struct xilly_endpoint *endp= oint) (!channel->wr_sleepy), XILLY_TIMEOUT); =20 + xilly_allow_isr(endpoint, false); + if (t <=3D 0) { dev_err(endpoint->dev, "Failed to obtain IDT. Aborting.\n"); =20 @@ -1843,6 +1870,9 @@ struct xilly_endpoint *xillybus_init_endpoint(struct = device *dev) endpoint->failed_messages =3D 0; endpoint->fatal_error =3D 0; =20 + endpoint->allow_isr =3D false; + spin_lock_init(&endpoint->allow_isr_lock); + init_waitqueue_head(&endpoint->ep_wait); mutex_init(&endpoint->register_mutex); =20 @@ -1855,6 +1885,9 @@ static int xilly_quiesce(struct xilly_endpoint *endpo= int) long t; =20 endpoint->idtlen =3D -1; + endpoint->num_channels =3D 0; + + xilly_allow_isr(endpoint, true); =20 iowrite32((u32) (endpoint->dma_using_dac & 0x0001), endpoint->registers + fpga_dma_control_reg); @@ -1862,6 +1895,9 @@ static int xilly_quiesce(struct xilly_endpoint *endpo= int) t =3D wait_event_interruptible_timeout(endpoint->ep_wait, (endpoint->idtlen >=3D 0), XILLY_TIMEOUT); + + xilly_allow_isr(endpoint, false); + if (t <=3D 0) { dev_err(endpoint->dev, "Failed to quiesce the device on exit.\n"); @@ -1915,6 +1951,8 @@ int xillybus_endpoint_discovery(struct xilly_endpoint= *endpoint) =20 endpoint->idtlen =3D -1; =20 + xilly_allow_isr(endpoint, true); + /* * Set DMA 32/64 bit mode, quiesce the device (?!) and get IDT * buffer size. @@ -1925,6 +1963,9 @@ int xillybus_endpoint_discovery(struct xilly_endpoint= *endpoint) t =3D wait_event_interruptible_timeout(endpoint->ep_wait, (endpoint->idtlen >=3D 0), XILLY_TIMEOUT); + + xilly_allow_isr(endpoint, false); + if (t <=3D 0) { dev_err(endpoint->dev, "No response from FPGA. Aborting.\n"); return -ENODEV; @@ -1951,6 +1992,7 @@ int xillybus_endpoint_discovery(struct xilly_endpoint= *endpoint) if (rc) goto failed_idt; =20 + /* xilly_obtain_idt() allows and then disallows the ISR */ rc =3D xilly_obtain_idt(endpoint); if (rc) goto failed_idt; @@ -1969,6 +2011,8 @@ int xillybus_endpoint_discovery(struct xilly_endpoint= *endpoint) if (rc) goto failed_idt; =20 + xilly_allow_isr(endpoint, true); + rc =3D xillybus_init_chrdev(dev, &xillybus_fops, endpoint->owner, endpoint, idt_handle.names, --=20 2.34.1