From patchwork Thu May 13 08:47:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Miguel Silva X-Patchwork-Id: 437277 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp127328jao; Thu, 13 May 2021 01:47:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo0rNWikbpSSPV0YZV9cwG8TgGxs1QR6hbUk10jLfJO9+zwPhNP1YklPtVpC5lTZJThUGc X-Received: by 2002:a50:ab16:: with SMTP id s22mr6544194edc.323.1620895650585; Thu, 13 May 2021 01:47:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620895650; cv=none; d=google.com; s=arc-20160816; b=iJcYvk8knxLvpREy0CsahaCKxkn2Dfg7c9JvJoZm10HLCp7LEKDaQ5YoYbkXAitLJC O3L0zAGxXS3qAwofMXRS7g41FjqvroYukogF4NnjBsEQbsehwbgT1ddKVcQqNQB3Sn3M Wx+3Bw04w1s5oDjSTt26qjQyh3MMFO/YLa5BchkbHLeyiTjq+yU4LpvTeJ010vU8TF+r tyHLuKgnTpOvv+XYDOpTRPOqIXpXXbW3ZR71WDvqqllfWD2C/AjDH1bVSTtlYcnHntt3 l3mQrVOx3eJs25d04DpkQyUzqYdjXctSB9W/b0uYWZeSZm3NmQcEYKN7ZSKvtbvAC4bX dB5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9wdsrW9vDLYc6IQvaaSKZQ3XOa1HAhG690/1zHFSgqw=; b=qku9qHGi7XVcs0rmhWoVGsvnZwh+yu4MAsVa7jDEwoBbDNB0gLaAB25c6tMWge4MFQ hJ7FxziTneAEwP0XhRhK1Rk4BvRiKyZZgd2xfjEQfZG4uP8hHY4Zq94x/irEdS0pE9sc ufs4HnqgO2NVb3tHNmpHLzkI2pfm1jDbJRgXEx0WKLJqhxbMVU7Db773VIJvne5td3bu hFDsB9gkkK9otHvnHTDKFlpQ6O2tIlXAf5/yr1+78Ke1kGZRvxRbPYKGD97P7XKnSkO/ 1GVkvIq0zVwbVPXRCNeMC4BBT7SxXsL43yToaOjXSz84rmsN958YOPXLitXnW2wspn38 6zCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ugV7jpog; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si2247959edt.295.2021.05.13.01.47.30; Thu, 13 May 2021 01:47:30 -0700 (PDT) Received-SPF: pass (google.com: domain of devicetree-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=@linaro.org header.s=google header.b=ugV7jpog; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbhEMIsi (ORCPT + 7 others); Thu, 13 May 2021 04:48:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232136AbhEMIsg (ORCPT ); Thu, 13 May 2021 04:48:36 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48DC2C061760 for ; Thu, 13 May 2021 01:47:27 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id b19-20020a05600c06d3b029014258a636e8so4286487wmn.2 for ; Thu, 13 May 2021 01:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9wdsrW9vDLYc6IQvaaSKZQ3XOa1HAhG690/1zHFSgqw=; b=ugV7jpogsUgQc1HA3xONSlrlwr3xbaJg2hrS7xjVCwIz01wml4hLzyefNFf9iZhjx/ lR0dH0V/uIqEzaV7J+I9925+3p7Y1ODBeLRAGD+QUIXq+Z3ZX6n7Ufk6xWUckpadoL2K w/n+beRLx7Ai6FEUkyNXZeX8AmEhYc7lle9k0VtfKvtgNC/xUxL13mOWZCncY9cYnQid Ed4jeMc2XMq9AJFxCnRtZOMM9d+E8XxsV7sfcescMsv8D81xWZYX362odYh8JnvUwxA6 6yWCML1TLJWnG8w1M1FRfVaN+TcIbBZi/vHh6ZPPgX47eEodmySdgE8e/vLS19eQDGNs T5xQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9wdsrW9vDLYc6IQvaaSKZQ3XOa1HAhG690/1zHFSgqw=; b=TLgtbmlYVZcpHtGZTLZ7Q0Sxj6BnbG4me0Is+LfqqrVtKlqladEGPk8a4Ps60LpKXM 0HlF5JuoMjt3xMDYR9sQzdU2OVM6w6JKbt7tmc7PLL5lsNWIDQ9x7z81UONzPYFNorpJ /VJj7b/2De+9UB7BKV0bktDwqcK6Ew2uEdz6SAuRBAqndqzOrC4zD7tX+qBMuXOA4//T w7pJfK0NLO35W6lh8GH0lFc0Ih5v02Bu7sbZ7wiaqFsQwU3wG02d/Ca+0ydzNPHhpwWp XMj22b60Fs3VmvVvoNRCv8DAzYqn1tskDyBvBaLA8wW8SedujhgqhDL8E6Np1xrQacZV 4o9Q== X-Gm-Message-State: AOAM532OmN5cblG9l78mGl1zANPKR3rfhEBG2NGLxWOf7khDpBKFhnbP i5sfLRpbPUoAwjk38IxNwKm31A== X-Received: by 2002:a1c:238d:: with SMTP id j135mr2704526wmj.170.1620895645998; Thu, 13 May 2021 01:47:25 -0700 (PDT) Received: from arch-thunder.local (a109-49-46-234.cpe.netcabo.pt. [109.49.46.234]) by smtp.gmail.com with ESMTPSA id h15sm1730282wmq.4.2021.05.13.01.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 01:47:25 -0700 (PDT) From: Rui Miguel Silva To: Greg Kroah-Hartman , Sebastian Siewior , Laurent Pinchart , Rob Herring Cc: linux-usb@vger.kernel.org, devicetree@vger.kernel.org, Rui Miguel Silva Subject: [PATCH v4 1/9] usb: isp1760: fix strict typechecking Date: Thu, 13 May 2021 09:47:09 +0100 Message-Id: <20210513084717.2487366-2-rui.silva@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210513084717.2487366-1-rui.silva@linaro.org> References: <20210513084717.2487366-1-rui.silva@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org There are a lot of pre-existing typechecking warnings around the access and assign of elements of ptd structure of __dw type. sparse: warning: invalid assignment: |= sparse: left side has type restricted __dw sparse: right side has type unsigned int or warning: restricted __dw degrades to integer or sparse: warning: incorrect type in assignment (different base types) sparse: expected restricted __dw [usertype] dw4 sparse: got unsigned int [assigned] [usertype] usof To handle this, annotate conversions along the {TO,FROM}_DW* macros and some assignments and function arguments. This clean up completely all sparse warnings for this driver. Signed-off-by: Rui Miguel Silva --- drivers/usb/isp1760/isp1760-hcd.c | 92 ++++++++++++++++--------------- 1 file changed, 47 insertions(+), 45 deletions(-) -- 2.31.1 diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c index 33ae656c4b68..0e0a4b01c710 100644 --- a/drivers/usb/isp1760/isp1760-hcd.c +++ b/drivers/usb/isp1760/isp1760-hcd.c @@ -66,44 +66,46 @@ struct ptd { #define ATL_PTD_OFFSET 0x0c00 #define PAYLOAD_OFFSET 0x1000 - -/* ATL */ -/* DW0 */ -#define DW0_VALID_BIT 1 -#define FROM_DW0_VALID(x) ((x) & 0x01) -#define TO_DW0_LENGTH(x) (((u32) x) << 3) -#define TO_DW0_MAXPACKET(x) (((u32) x) << 18) -#define TO_DW0_MULTI(x) (((u32) x) << 29) -#define TO_DW0_ENDPOINT(x) (((u32) x) << 31) +#define TO_DW(x) ((__force __dw)x) +#define TO_U32(x) ((__force u32)x) + + /* ATL */ + /* DW0 */ +#define DW0_VALID_BIT TO_DW(1) +#define FROM_DW0_VALID(x) (TO_U32(x) & 0x01) +#define TO_DW0_LENGTH(x) TO_DW((((u32)x) << 3)) +#define TO_DW0_MAXPACKET(x) TO_DW((((u32)x) << 18)) +#define TO_DW0_MULTI(x) TO_DW((((u32)x) << 29)) +#define TO_DW0_ENDPOINT(x) TO_DW((((u32)x) << 31)) /* DW1 */ -#define TO_DW1_DEVICE_ADDR(x) (((u32) x) << 3) -#define TO_DW1_PID_TOKEN(x) (((u32) x) << 10) -#define DW1_TRANS_BULK ((u32) 2 << 12) -#define DW1_TRANS_INT ((u32) 3 << 12) -#define DW1_TRANS_SPLIT ((u32) 1 << 14) -#define DW1_SE_USB_LOSPEED ((u32) 2 << 16) -#define TO_DW1_PORT_NUM(x) (((u32) x) << 18) -#define TO_DW1_HUB_NUM(x) (((u32) x) << 25) +#define TO_DW1_DEVICE_ADDR(x) TO_DW((((u32)x) << 3)) +#define TO_DW1_PID_TOKEN(x) TO_DW((((u32)x) << 10)) +#define DW1_TRANS_BULK TO_DW(((u32)2 << 12)) +#define DW1_TRANS_INT TO_DW(((u32)3 << 12)) +#define DW1_TRANS_SPLIT TO_DW(((u32)1 << 14)) +#define DW1_SE_USB_LOSPEED TO_DW(((u32)2 << 16)) +#define TO_DW1_PORT_NUM(x) TO_DW((((u32)x) << 18)) +#define TO_DW1_HUB_NUM(x) TO_DW((((u32)x) << 25)) /* DW2 */ -#define TO_DW2_DATA_START_ADDR(x) (((u32) x) << 8) -#define TO_DW2_RL(x) ((x) << 25) -#define FROM_DW2_RL(x) (((x) >> 25) & 0xf) +#define TO_DW2_DATA_START_ADDR(x) TO_DW((((u32)x) << 8)) +#define TO_DW2_RL(x) TO_DW(((x) << 25)) +#define FROM_DW2_RL(x) ((TO_U32(x) >> 25) & 0xf) /* DW3 */ -#define FROM_DW3_NRBYTESTRANSFERRED(x) ((x) & 0x7fff) -#define FROM_DW3_SCS_NRBYTESTRANSFERRED(x) ((x) & 0x07ff) -#define TO_DW3_NAKCOUNT(x) ((x) << 19) -#define FROM_DW3_NAKCOUNT(x) (((x) >> 19) & 0xf) -#define TO_DW3_CERR(x) ((x) << 23) -#define FROM_DW3_CERR(x) (((x) >> 23) & 0x3) -#define TO_DW3_DATA_TOGGLE(x) ((x) << 25) -#define FROM_DW3_DATA_TOGGLE(x) (((x) >> 25) & 0x1) -#define TO_DW3_PING(x) ((x) << 26) -#define FROM_DW3_PING(x) (((x) >> 26) & 0x1) -#define DW3_ERROR_BIT (1 << 28) -#define DW3_BABBLE_BIT (1 << 29) -#define DW3_HALT_BIT (1 << 30) -#define DW3_ACTIVE_BIT (1 << 31) -#define FROM_DW3_ACTIVE(x) (((x) >> 31) & 0x01) +#define FROM_DW3_NRBYTESTRANSFERRED(x) TO_U32((x) & 0x7fff) +#define FROM_DW3_SCS_NRBYTESTRANSFERRED(x) TO_U32((x) & 0x07ff) +#define TO_DW3_NAKCOUNT(x) TO_DW(((x) << 19)) +#define FROM_DW3_NAKCOUNT(x) ((TO_U32(x) >> 19) & 0xf) +#define TO_DW3_CERR(x) TO_DW(((x) << 23)) +#define FROM_DW3_CERR(x) ((TO_U32(x) >> 23) & 0x3) +#define TO_DW3_DATA_TOGGLE(x) TO_DW(((x) << 25)) +#define FROM_DW3_DATA_TOGGLE(x) ((TO_U32(x) >> 25) & 0x1) +#define TO_DW3_PING(x) TO_DW(((x) << 26)) +#define FROM_DW3_PING(x) ((TO_U32(x) >> 26) & 0x1) +#define DW3_ERROR_BIT TO_DW((1 << 28)) +#define DW3_BABBLE_BIT TO_DW((1 << 29)) +#define DW3_HALT_BIT TO_DW((1 << 30)) +#define DW3_ACTIVE_BIT TO_DW((1 << 31)) +#define FROM_DW3_ACTIVE(x) ((TO_U32(x) >> 31) & 0x01) #define INT_UNDERRUN (1 << 2) #define INT_BABBLE (1 << 1) @@ -292,12 +294,12 @@ static void ptd_write(void __iomem *base, u32 ptd_offset, u32 slot, struct ptd *ptd) { mem_writes8(base, ptd_offset + slot*sizeof(*ptd) + sizeof(ptd->dw0), - &ptd->dw1, 7*sizeof(ptd->dw1)); + (__force u32 *)&ptd->dw1, 7 * sizeof(ptd->dw1)); /* Make sure dw0 gets written last (after other dw's and after payload) since it contains the enable bit */ wmb(); - mem_writes8(base, ptd_offset + slot*sizeof(*ptd), &ptd->dw0, - sizeof(ptd->dw0)); + mem_writes8(base, ptd_offset + slot * sizeof(*ptd), + (__force u32 *)&ptd->dw0, sizeof(ptd->dw0)); } @@ -553,7 +555,7 @@ static void create_ptd_atl(struct isp1760_qh *qh, ptd->dw0 |= TO_DW0_ENDPOINT(usb_pipeendpoint(qtd->urb->pipe)); /* DW1 */ - ptd->dw1 = usb_pipeendpoint(qtd->urb->pipe) >> 1; + ptd->dw1 = TO_DW((usb_pipeendpoint(qtd->urb->pipe) >> 1)); ptd->dw1 |= TO_DW1_DEVICE_ADDR(usb_pipedevice(qtd->urb->pipe)); ptd->dw1 |= TO_DW1_PID_TOKEN(qtd->packet_type); @@ -575,7 +577,7 @@ static void create_ptd_atl(struct isp1760_qh *qh, /* SE bit for Split INT transfers */ if (usb_pipeint(qtd->urb->pipe) && (qtd->urb->dev->speed == USB_SPEED_LOW)) - ptd->dw1 |= 2 << 16; + ptd->dw1 |= DW1_SE_USB_LOSPEED; rl = 0; nak = 0; @@ -647,14 +649,14 @@ static void transform_add_int(struct isp1760_qh *qh, * that number come from? 0xff seems to work fine... */ /* ptd->dw5 = 0x1c; */ - ptd->dw5 = 0xff; /* Execute Complete Split on any uFrame */ + ptd->dw5 = TO_DW(0xff); /* Execute Complete Split on any uFrame */ } period = period >> 1;/* Ensure equal or shorter period than requested */ period &= 0xf8; /* Mask off too large values and lowest unused 3 bits */ - ptd->dw2 |= period; - ptd->dw4 = usof; + ptd->dw2 |= TO_DW(period); + ptd->dw4 = TO_DW(usof); } static void create_ptd_int(struct isp1760_qh *qh, @@ -977,10 +979,10 @@ static void schedule_ptds(struct usb_hcd *hcd) static int check_int_transfer(struct usb_hcd *hcd, struct ptd *ptd, struct urb *urb) { - __dw dw4; + u32 dw4; int i; - dw4 = ptd->dw4; + dw4 = TO_U32(ptd->dw4); dw4 >>= 8; /* FIXME: ISP1761 datasheet does not say what to do with these. Do we