From nobody Mon Apr 27 12:16:46 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F00BC43334 for ; Mon, 13 Jun 2022 16:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236339AbiFMQt4 (ORCPT ); Mon, 13 Jun 2022 12:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241134AbiFMQtB (ORCPT ); Mon, 13 Jun 2022 12:49:01 -0400 Received: from SpacedOut.fries.net (SpacedOut.fries.net [IPv6:2001:470:3832:200::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D22A71EA864 for ; Mon, 13 Jun 2022 07:35:48 -0700 (PDT) Received: from SpacedOut.fries.net (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by SpacedOut.fries.net (8.15.2/8.15.2/Debian-22) with ESMTPS id 25DEZckq3980090 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 13 Jun 2022 09:35:38 -0500 Received: (from david@localhost) by SpacedOut.fries.net (8.15.2/8.15.2/Submit) id 25DEZZWS3980089; Mon, 13 Jun 2022 09:35:35 -0500 Date: Mon, 13 Jun 2022 09:35:35 -0500 From: David Fries To: Mark Brown Cc: linux-kernel@vger.kernel.org Subject: [PATCH] spi: spidev_test: Warn when the mode is not the requested mode Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.2 (SpacedOut.fries.net [IPv6:::1]); Mon, 13 Jun 2022 09:35:38 -0500 (CDT) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Print a warning if the device mode doesn't match the requested mode. The user doesn't enter the mode in hex so it isn't obvious when setting the mode succeeds that the mode isn't the requested mode. The kernel logs a message, it will be more visible if the test also prints a warning. I was testing --quad, which is unsupported, but doesn't cause the mode request to fail. Signed-off-by: David Fries --- Sorry forgot to run checkpatch.pl though it was silent about the comments, which I reworded. tools/spi/spidev_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 83844f8b862a..941d713d6f23 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c @@ -417,6 +417,7 @@ int main(int argc, char *argv[]) { int ret =3D 0; int fd; + uint32_t request; =20 parse_opts(argc, argv); =20 @@ -429,7 +430,10 @@ int main(int argc, char *argv[]) =20 /* * spi mode + * WR is write 'mode' to request the transfer mode + * RD is read what mode the device actually is */ + request =3D mode; ret =3D ioctl(fd, SPI_IOC_WR_MODE32, &mode); if (ret =3D=3D -1) pabort("can't set spi mode"); @@ -437,6 +441,14 @@ int main(int argc, char *argv[]) ret =3D ioctl(fd, SPI_IOC_RD_MODE32, &mode); if (ret =3D=3D -1) pabort("can't get spi mode"); + /* + * Drivers can reject some mode options without returning an error. + * Warn in this case to avoid the user thinking the requested mode is + * supported since it didn't give an error. + */ + if (request !=3D mode) + printf("WARNING device does not support requested mode 0x%x\n", + request); =20 /* * bits per word --=20 2.30.2