Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp2064080lqa; Tue, 30 Apr 2024 07:20:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJB/7gv2af2Grq5iHvf9MkKOZ0TgQBOOHXeDQF2fh0x8rphtbYXITNwzSneJF30JBiPZxUXoru68wioJBNuQGFT0YM4py1rbwJAa/23g== X-Google-Smtp-Source: AGHT+IGAl0pKFQoI0BuNzzog0pzQ/Od6OFhFMYV4k9sCn8LtJNr0W7Qu9zdnHr8xUTFcmHnFHSnj X-Received: by 2002:a05:6e02:144a:b0:36b:3c2f:4d1e with SMTP id p10-20020a056e02144a00b0036b3c2f4d1emr18659230ilo.28.1714486850291; Tue, 30 Apr 2024 07:20:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714486850; cv=pass; d=google.com; s=arc-20160816; b=M2bBxIsiO2eYGOPjsb3ofEzbXesrEcVKyZ5XVge9YYpfe1ju8dmpuLxcqjNdXapQE0 bzd6E32+yDRwJmN5qXHilYxugnuigRNu/kPPz3CBJrPSNSy0zOjg247FX6wJKGR20kLQ exs7bl+m1xMXPbhASeWTPrW76JjkV47XNoOPyOaTJR3LNOTlf31dp+MvRKWzHnlCx5hU 7iSW0J1lvQSs+mCGvPCOeuTkG5SgIq2949b+NfpG6bmJkUyalpqvxWhM0IiLNEKkGCrX 3GRSasFZgcEIZnrFd/G6FF/7F1f2N03lY2WtnTP+ZxCIQp4LLUnfBpSgn+xy4MmAa87B /r/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=2Nsi+kUuVlRwO+YscLsuVmpvv08E0sHrgn4SKq3ugFM=; fh=8T7bNu6wT54FxYslemDTwEhqED5sZCZy6cCb2TWwA34=; b=vmSFhtQbDadA+B8721v+y4ozUkvy1Dgqt5gYzZOfD+pOr9wXbG953H3F9ahPrO0uB+ 9i4fIExv2Ur0TUtZfr5KTVoT7w/VYF8hepCXgr9cw7cMNwTDXwAvnDpMo74/yltiM6yZ bQyIZP0tHJaoKohTwxXiH5CIzZ5iyi0L1fdebugcqWsxL9G3DTVMqLJUwHe21gQU1zM9 ad3/KWY5JxmM7Oiw546PK3gL5WcY2sWONr9RmqG4TmX6olk3/DYCcDYiYs3BgzoSJ2r1 pantbyQQdwOLbXwf1ZAe3O6fXxHG13sZW7u2e3xNwAWpjF2U5DcjNKDHkfEIXLcspXtE LdGw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vy0gf/uC"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-164099-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id r13-20020a63d90d000000b005f3f312f17dsi21621868pgg.593.2024.04.30.07.20.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:20:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164099-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Vy0gf/uC"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-164099-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164099-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C19142828A4 for ; Tue, 30 Apr 2024 14:20:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 538D51802D1; Tue, 30 Apr 2024 14:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Vy0gf/uC" Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 77575175558 for ; Tue, 30 Apr 2024 14:09:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714486189; cv=none; b=Pn4kE2z9nnuEoI3A30E3wsYmKM8hRZ65Xm7kr5IJn2+HnS/vFjqaBoTmYgiwVjIQ4TtynYUa5ceh3zWjfJ2Swzv0ZkA7H7Y2b7dnh2W0LG9I4rfz45wydw5Jphmu9e3xqyEyX/O20gygtYKPc4mu2/GlA1Kbz4+f7Yk3qlASSrg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714486189; c=relaxed/simple; bh=H0WsvqNTNFr7LXN1miq+Dc39F6X1tipdPUEwPS+odes=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AgaA90swgMwolZzKd0D9d5HsUUOfKxcor5xdQ3OD+SvSQN8nnMn/j+otLCgS+JMyCvU5bcP+u0+lEFIYsCzEsibeiBjjKjFHnCg3bMYle3NWqcOhg+NmsKrQq6MEesNNY0d5j0uDUFU/0PICILfpoGACoOjXehWEHAAD1cuY0xw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Vy0gf/uC; arc=none smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-56e477db7fbso9872385a12.3 for ; Tue, 30 Apr 2024 07:09:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714486185; x=1715090985; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2Nsi+kUuVlRwO+YscLsuVmpvv08E0sHrgn4SKq3ugFM=; b=Vy0gf/uCQQNMY5LLcLc0s/sAyGwjc8uF8nN/dKcpiINfVxJWqZTZ2hf4ZNaelIEmHv pklWqDJ07V2BTfnI1giEIA7OV5fCPnki633c/J6fzG/puQeU9HtNjbPH2bGmdhGXkbPc a9LqLgdcsK27aEp5ZLeR30jD4HWPyeVmdAqpuLIM9d0wLHYiDs+bJJFl37/7doawo7ZF X7d6hBN6OJtp1IEH8RpmoYaHY4Bc838JexYVpIlsMt+ima09UMV0zKif4yJIGikWRX3q 4FWKdUZgD7qO5ZpuItY1VhvHx6Tr4+NvmMLo9/b/iQEgh0J4aFcRahJPpQ10DCZS+baM Fqxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714486185; x=1715090985; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2Nsi+kUuVlRwO+YscLsuVmpvv08E0sHrgn4SKq3ugFM=; b=c7brJQk1YK6t6488AxvbrRLrX4x0LS4SJD2vhKlAc/WzMRS9IFfMZzHABojYxhi7eV acLINtk+9GiaNfbC6J8YgEHIooFnDugDzWc6UY40bx6XfGfX8cGI9iMcHRpU11umiPoy FnG0oBdfG/Z0b89oknz7Yj51icia/gGeoR+NY173eUp05tUTLSHJh7AHner+dEoN6b/a S1s5N5Tx0JyZIJzk/UNee87Q5ESqNFioWrsK/Y2rVphmeWkb1pCoJ2J35pzaYw95gUho x3m2SV0mEYlPu+N1tpw6j09Zxm4XcnnRDerhXVU7tG1g5Q3HL3HVP5RJW989CokYqGLS 83Kw== X-Forwarded-Encrypted: i=1; AJvYcCWMO8ZUGOilRSk16nDmqueRXdET39v9GRX/XSaYO+RH+CgwzPDFW3SY/43m1+7Ix6XnbC7cRRJZkC+atAb7ho7mUc2L3S1IibAiCwgZ X-Gm-Message-State: AOJu0Yze3qtYMkmVhhgPlLPfCuik4r92cjv1yuTLXKL8uB3P8kn9UDBO +p42+bUWIxhbLRKjQCnFT7/Xwikt0Zr/ipKt3o74N8YOUnBp4+6Ovy84xjqZ/RK+eB4/GekAuoo SfHA= X-Received: by 2002:a17:906:4a8d:b0:a59:40b8:e235 with SMTP id x13-20020a1709064a8d00b00a5940b8e235mr71722eju.71.1714486185598; Tue, 30 Apr 2024 07:09:45 -0700 (PDT) Received: from krzk-bin.. ([178.197.223.16]) by smtp.gmail.com with ESMTPSA id a14-20020a1709062b0e00b00a58bcb55704sm6050092ejg.165.2024.04.30.07.09.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:09:45 -0700 (PDT) From: Krzysztof Kozlowski To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Krzysztof Kozlowski Subject: [PATCH] ASoC: use inline function for type safety in snd_soc_substream_to_rtd() Date: Tue, 30 Apr 2024 16:09:38 +0200 Message-ID: <20240430140938.328088-1-krzysztof.kozlowski@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A common pattern in sound drivers is getting 'struct snd_soc_pcm_runtime' from 'struct snd_pcm_substream' opaque pointer private_data field with snd_soc_substream_to_rtd(). However 'private_data' appears in several other structures as well, including 'struct snd_compr_stream'. The field might not hold the same type for every structure, although seems the case at least for 'struct snd_compr_stream', so code can easily make a mistake by using macro for wrong structures. Switch from macro to inline function, so such mistake will be build-time detectable. Signed-off-by: Krzysztof Kozlowski --- include/sound/soc.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index 2a1b6c198547..cacaa92487a0 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1215,8 +1215,12 @@ struct snd_soc_pcm_runtime { /* see soc_new_pcm_runtime() */ #define snd_soc_rtd_to_cpu(rtd, n) (rtd)->dais[n] #define snd_soc_rtd_to_codec(rtd, n) (rtd)->dais[n + (rtd)->dai_link->num_cpus] -#define snd_soc_substream_to_rtd(substream) \ - (struct snd_soc_pcm_runtime *)snd_pcm_substream_chip(substream) + +static inline struct snd_soc_pcm_runtime * +snd_soc_substream_to_rtd(const struct snd_pcm_substream *substream) +{ + return substream->private_data; +} #define for_each_rtd_components(rtd, i, component) \ for ((i) = 0, component = NULL; \ -- 2.43.0