From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384519; b=rE03Do/XAiubDnh93NfI/Dustjne4zSgeOYuABRWPCxa7Jcj1oJm1jtyLL/T+9O9Qn6g DqkHVvtge4pFFnUpalZSQV98RM8qHTK84MJmRBqT96bt8RpkJQMuPG1IkXZAFcFammsoE HsSjJL/RkaO/wKaN+O1M9u6A4Zvk2TUBGLr5ZvrceVJT+GGd0wfcmlt/Zid8wmtmaMJAe CHaUKl+whNfM+zY54mBEALfUv+E5xny1eY+3ikuC5pz7K3QlVZSo1sXnInrBwy6htgcHa SSWhKEqPRbOLPrZFa9NFwefYw7sL89FogJ6qjyGBFc8X3kQid6lbfpgVV91EfP4DM5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384519; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=ZWS/URKDi3CxzRzIYD07XFQfgBg5+XqqUC8GcndTTOo=; b=UmKFBCsQSUBCPBMAQp45iM+oYJ0UKEQ9PtZFt4fH9pDlkCuvBHsguriIBt8xUeYMtXqh Fdf2njnIqUSIj/TUapdSJyrBCiuyn+LEVnAEAJ3n8QRNATvut4Sdp9flNrpHRYMCfhRRi vxq2cHAJr1BD4Quh5D2FdI0F6L87iVwoihOtsReJiuUGu+O1ankMqxjSlL73g2v50D4Y/ ZCT58a5rydirA+IQIsyI3Se0PHs3qzCaGuR+k8/a8wXSmVnNmfCb1aei7jcLGExRnAtGZ YSPdyCBPTQVJaaDvbbEpAEmnR/9ThlM4qpEsvmHkN/tvCoupWAy5//E6L7djEpnIixQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VNhFVOkJ; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4793B606A330 for ; Fri, 4 Dec 2026 11:41:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4793B606A330 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.a=rsa-sha256 header.s=20260707 header.b=VNhFVOkJ Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso1934299eec.0 for ; Fri, 04 Dec 2026 03:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796384518; x=1796989318; 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:content-type; bh=ZWS/URKDi3CxzRzIYD07XFQfgBg5+XqqUC8GcndTTOo=; b=VNhFVOkJHbdIG8F7JqV0udSgUPQyLk8LiFWM4kZzPBelj7h3e/lHRdHPosgxNXPwQ5 Q7ZZ23r5g3+BQtvob7Xr62qvZxYjuACZJYZF5wge5RtwYYjkmB3Y9fbAsOXxSeN9I7o3 lBfU2msJMgnqYMA3LL5p+PzLcM/HqlhhgJA99lUXGfu6ovAwJ6ldpCS/vAb13p6gqNuo XbAXA6AJ99C5vwhgkQIbk8FxbUESt6OwBDBMmnmnMi0FwKGHXlsDbBlCeO1f0reBzt5u Ne5on7otcrI3hdLA1ih48ZlEqGYbrqckP18fzJuejqk5iRSMX7+slUArdUyE0KzIEeEV Bv8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796384518; x=1796989318; h=content-transfer-encoding:mime-version: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=ZWS/URKDi3CxzRzIYD07XFQfgBg5+XqqUC8GcndTTOo=; b=O0V5FcpZIsGmuU80WvjY1viqUoXXH+36QyP3dg2Nq6/9CDyLXhL2/YQQCZ/uvfvoJM A1nldTYWtq5ZNx00cWJNgqJU9O5AYj0JVBoKh/qQJYtiCeZJcREiouvkCIts8PmlrPuq 668yO5kmXa3w1VqI54OBpPqQR6JQbB0/Y03NvMvVnx/cjS3ygJZwEsIcLfX5WU0M81xh TDM5kCmRx0/6Y13DY1AUCFEBkYuLoG/17yxQvnrM1veJrXDiOG+n7ruIoEHme9HXM7bV /TSSygGwP3WXl2MBOEmI2Wp9ivd05g4kPYFdrDZd8yIH4imheTy7nJXaU8pCfbfPZE6T StVA== X-Gm-Message-State: APuU4Z/zPREV31fve15JOKEt8RGbjFUrURP03XIQtDEtgR4pDeclHQ9E 2a7JeRO/rDCT523NHQRkwgRWFttyAURDZVhk3UPQnwem4zIejsntnlY/ X-Gm-Gg: AZFdTZczOWW5YeIydR891XrTAFA2d93YZTDSmI9tC+DjEoX9GBQ600IZ2coA7K8Ks2p ncHbY5g73xwobsHcCEcVjJeysay5fePrpVTVwGkPqOTEWjX6r2ac14GL3R4goc4/nxg9+9zm7Zp ZgqQmqAgFDF/NM0ykEgIXyPgk/QpR9bvpcICo7ShI1qkpng/4Qw/87mMmmxFDcl7XJWiuZixqd/ Fi5d628bJhJzHYRZuSmj3G7KoIKUodCXnJNtNu14Y8ucIANqDz7gvLUeUyzAjyMT4k1c5x3bb+2 iqXRTKVu81M/aPB2AYjeKfeVL/VsbL3/8HipAOR3b5Xgpq+oAFmyomWXXYA/44lO1WLWQv5taIn KXMQtofuoHGlcVCQ6FwWLJ/9sjGCmhNa2qxu7lrDXDT7ozIkohjV3TUBbo+ZTfbECHN7/wjrurb bJ8KCta68VKvvqGMNb1+pKcyFFJb8fH+JnK4a1+nnOiMI2wr3f/EpStWw2hhlBuoFQ3T2JvIzCG JdZjuoEiyO3Yp7oHzqTiAYZsYFu4R26upNTI3tJZmDdcwlChNFPkZg5dtkcgM8OlG31qC8pUg6j /N6gl4jxGoe+UHaFSBStV5yG5OijcqYNUJotqHoARiNDkHiSLK9h X-Received: by 2002:a05:693c:63cf:b0:387:4332:d3d1 with SMTP id 5a478bee46e88-387521a1addmr1783881eec.41.1796384518147; Fri, 04 Dec 2026 03:41:58 -0800 (PST) Received: from localhost.localdomain ([103.149.158.169]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875218c61esm8143692eec.4.2026.12.04.03.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 03:41:57 -0800 (PST) From: Sreeraj S Kurup To: perex@perex.cz, tiwai@suse.de Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org, Sreeraj S Kurup Subject: [PATCH] sound: Add a generic result header Date: Fri, 4 Dec 2026 11:41:22 +0000 Message-ID: <20261204114122.4465-1-sreekuttan2156239@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add include/sound/snd_result.h to provide a common result structure for sound APIs. Some sound APIs return unsigned int values but also use negative error codes to report failures. Since the return type is unsigned int, negative error codes are converted to unsigned values. This makes it hard to tell whether the returned value is an error or a valid result. For example, returning -1 from an unsigned int function produces 0xffffffff, which could also be a valid value returned by the function. This makes it difficult to handle errors when the full range of unsigned values can be used. The new result structure uses a type field to identify what kind of value is stored. It supports error codes, signed integers, unsigned integers and pointers. Helper functions are provided to create each type of result. This allows sound APIs to return errors and different kinds of values without using special values to indicate errors. More result types and their corresponding helper functions can be added later as needed by other sound APIs. Signed-off-by: Sreeraj S Kurup --- include/sound/snd_result.h | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 include/sound/snd_result.h diff --git a/include/sound/snd_result.h b/include/sound/snd_result.h new file mode 100644 index 000000000000..61503675e7fb --- /dev/null +++ b/include/sound/snd_result.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Generic result type and helpers for sound APIs + * that need to return an error code or a value of + * a different type. + * + */ + +#ifndef __SOUND_RESULT_H +#define __SOUND_RESULT_H + +enum snd_result_type { + SND_RESULT_ERR, + SND_RESULT_INT, + SND_RESULT_UINT, + SND_RESULT_PTR, +}; + +struct snd_result { + enum snd_result_type type; + union { + int err; + int i; + unsigned int u; + void *ptr; + }; +}; + +static inline struct snd_result snd_result_err(int err) +{ + return (struct snd_result) { + .type = SND_RESULT_ERR, + .err = err, + }; +} + +static inline struct snd_result snd_result_int(int value) +{ + return (struct snd_result) { + .type = SND_RESULT_INT, + .i = value, + }; +} + +static inline struct snd_result snd_result_uint(unsigned int value) +{ + return (struct snd_result) { + .type = SND_RESULT_UINT, + .u = value, + }; +} + +static inline struct snd_result snd_result_ptr(void *value) +{ + return (struct snd_result) { + .type = SND_RESULT_PTR, + .ptr = value, + }; +} + +#endif -- 2.55.0