From patchwork Tue Apr 12 12:22:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 12810760 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 2EFE8C433FE for ; Tue, 12 Apr 2022 12:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235772AbiDLM7T (ORCPT ); Tue, 12 Apr 2022 08:59:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355056AbiDLM5q (ORCPT ); Tue, 12 Apr 2022 08:57:46 -0400 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCBB9583A1; Tue, 12 Apr 2022 05:31:14 -0700 (PDT) Received: from relay3-d.mail.gandi.net (unknown [217.70.183.195]) by mslow1.mail.gandi.net (Postfix) with ESMTP id 215C4CF6E6; Tue, 12 Apr 2022 12:22:22 +0000 (UTC) Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 530E560004; Tue, 12 Apr 2022 12:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1649766138; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yYar+EZz5N7PiDMFj3b3J7ixymPwvX8499KWau8exU8=; b=oapvIhjdGOscEhJufDW+Ov8FKM7b/3KQLJsXzxW+JBdJvZcIHz/Rn3A971azmySNHmlXlR dTsdpG6XZzEejvt/fD/kB0Wh3n2ILRWv3CuI2akVA8g4+UwWe791zApK6fjZLVz/OAL5cB r08yE0Y+enDC4q9My7eugN138dxjBSnubQEk0AociCTBUv4spDaNSoFySBk+y4ukjP6HCJ a1qNz5GHmyYFDKCa0F3Imktw4t8/f6ROb34QPSVF+7XZT1ruJynINb7kL7MElrxBVSk18T cKvXOUZSwB8G0w1eHijwoRGFoxrZE2X/aPJEXG7aK++8bnPkNJq8swuDu2gRsw== From: Paul Kocialkowski To: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Mark Brown , Thomas Petazzoni , Paul Kocialkowski Subject: [PATCH] spi: core: Only check bits_per_word validity when explicitly provided Date: Tue, 12 Apr 2022 14:22:07 +0200 Message-Id: <20220412122207.130181-1-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org On SPI device probe, the core will call spi_setup in spi_add_device before the corresponding driver was probed. When this happens, the bits_per_word member of the device is not yet set by the driver, resulting in the default being set to 8 bits-per-word. However some controllers do not support 8 bits-per-word at all, which results in a failure when checking the bits-per-word validity. In order to support these devices, skip the bits-per-word validity check when it is not explicitly provided by drivers. Signed-off-by: Paul Kocialkowski --- drivers/spi/spi.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 2e6d6bbeb784..563a56ce34a0 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3518,13 +3518,18 @@ int spi_setup(struct spi_device *spi) return -EINVAL; } - if (!spi->bits_per_word) + if (!spi->bits_per_word) { spi->bits_per_word = 8; - - status = __spi_validate_bits_per_word(spi->controller, - spi->bits_per_word); - if (status) - return status; + } else { + /* + * Some controllers may not support the default 8 bits-per-word + * so only perform the check when this is explicitly provided. + */ + status = __spi_validate_bits_per_word(spi->controller, + spi->bits_per_word); + if (status) + return status; + } if (spi->controller->max_speed_hz && (!spi->max_speed_hz ||