From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 0DF6E37B3F6 for ; Sat, 9 May 2026 02:56:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778295377; cv=none; b=fnSdDCeevEGPUm6BWZL7YSc6jtAOC5sEmEW+cR9+r4+3wn+7R082b/YrIxtt6zcw0K37od6kQrdBYmK2+V+DQqAVsvIHi3LDBYYy59dOuG6VKjYlNX3u2zqOCH4wXFuEyxstqWdcYn3g+1j8IcZTiQyJtIofL6SUBM9kvJrmUjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778295377; c=relaxed/simple; bh=7vgtzD9BQ48niWcSvjgkW6oNLh3IjoSCUB8nqqKKFXc=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=umFsYBfvahzi+FwJZ51vM3fYKnS8+U9ObliKX7ty32qbWTFzHfFcPb70UuCjdoEyFyYBG0kDJw9kEDYOR5bHXqenxXQ5hq1+SAgootPJ6vpsfNrtz2GdugPXwEQOxTExXZXE+hsJWXGeQQZSsF6kuZwMz28PVjl04UX95P7jXDg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=am7SMz6a; arc=none smtp.client-ip=209.85.214.171 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.b="am7SMz6a" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ab46931cf1so26203465ad.0 for ; Fri, 08 May 2026 19:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778295374; x=1778900174; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=6866R8amqJxla4MgcLS3O6o3R5zb0GhWrUGc5mXMT/w=; b=am7SMz6aG3QbCcRb6Ku5YbZAMws08Wo+xKqzw3oq9UcluQ8h8kES5aWFE8vQRJ8NhU kS8LDu/aLa5f7lHI39OyCD/LBSwnEJi3KZfEzZgGIEEAJBrmnEGIdn2hU0Cg9JhP3vtJ iSKZxPcP8aMntt5Daz3xV2xwvTojWtxOMlmA0glCtm910/4RCwQlRjsPTG1fOV6fJ+ji D6iGmYot/Ffm+DYLbjOb8rGjHTBHURVRrFyenjgj5Iu2NpPbbw2HIGG0VLZ+VQKcMXB2 GL1XGanJS6edaOD8iahQcbSm20GK/MThAmUkPWpG0Nsnz2NzENbJAg/ZVxkyKATGVsNv wMUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778295374; x=1778900174; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6866R8amqJxla4MgcLS3O6o3R5zb0GhWrUGc5mXMT/w=; b=PwN+bxYNAq5wzfO5MbKELuLBR58xdrrhj6SiA+UGOV7TcCCUOx3TR2n03MVcQTuogC QnX0AV1RiwmYj7e8rDtD7bGXZCHJT8/ID0RVNTaTcyDV1h2bmFVW94lP8avME/i5wVQ5 bPtsl2eefRA78R0/NuX4+kWAB/H8K8BvmXT+4ujDh5ruRzHkMtovq30Yfe6uUEkhy/fA B3/SlR088tjMc8ylhVM+foo5ep0U+uW6QHLqfGIBte7PVMBWw4o2blIpMbHI6o6QFpqc gEi05bURjtcTaLNvKBoEbkm4xU/1Jk5sB4OD9212cw1w1+rqEJnJAH8t0ikxHHGMF8My 7oUw== X-Forwarded-Encrypted: i=1; AFNElJ8UUgz47O6HgXwqGJaNO7oD9Krm0kmRhhXIAUCIWp2A78CVWCKRX5EkedJngayxqOq9GM/s0O3YT9tOobI=@vger.kernel.org X-Gm-Message-State: AOJu0YzvxkXK3dqYm3NDIo4q0Z7ZOTVLLVlEFdWi8og/vuCz9nsC0tKd bPVV7SzFD2DlSPYKbO+kaAqfSQW3kCI+EUqarxPyexyc4HlXbGqfHLKu X-Gm-Gg: Acq92OE5bnA6T9+yBY69jHke1pEOdZTgdLhbvtHY1LqGCwmFW/9Qu2nYgrt11GSsPlk cp/0NkGLTzWxZsbif2ilHtIFxMM4VuI6Akjsl/GaKRuqW4/uSne9JOByHIYKNCGvRq0x+gvlBby OCEmHN5LhGV/aZdCHQprka4IgjEAdMrG/jczV/lxib0G62D1C5bZdiRyvIPZ7bPW3OhAH0f/GkP QcE7FijdKiqnL4EysSz2DZV/DH5fZUuOos5frQcOai1eenDwKckuGdLxJetnQ44onv2wt3GDVNT ROSSUXeuzprW8AnaCDLX6JMt9WuQqvab58FK6BawcjfkhApR5Qjcj2WWUkFp3w9qAHjC1fbc+9K mFTK8D+4hGXwaoiI9RAD4GfRFSaNligbjs5ZJP9Kwceo/54HrA0kZwbY/G0ShdNog0NCGTe2pnJ JKPod8XiPCZhl7inutfpRS+RiEuiq8oU4M0bPuxmv3xAyNXQ8= X-Received: by 2002:a17:903:1103:b0:2b0:b258:2a57 with SMTP id d9443c01a7336-2babd60f239mr97861905ad.27.1778295374295; Fri, 08 May 2026 19:56:14 -0700 (PDT) Received: from ehlo.thunderbird.net ([2401:4900:791b:cfa1:9b60:879e:786b:b8d8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1d27109sm37316815ad.1.2026.05.08.19.56.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 May 2026 19:56:13 -0700 (PDT) Date: Sat, 09 May 2026 08:13:42 +0530 From: Sanjay Chitroda To: Maxwell Doose , jic23@kernel.org CC: Tomasz Duszynski , David Lechner , =?ISO-8859-1?Q?Nuno_S=E1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: =?US-ASCII?Q?Re=3A_=5BPATCH=5D_iio=3A_chemical=3A_scd30=3A_Cleanu?= =?US-ASCII?Q?p_initializations_in_scd30=5Ffloat=5Fto=5Ffp=28=29?= User-Agent: Thunderbird for Android In-Reply-To: <20260508225501.86448-1-m32285159@gmail.com> References: <20260508225501.86448-1-m32285159@gmail.com> Message-ID: <8F49F478-AAA8-4AE8-B6BC-BF3C3923AAD7@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 9 May 2026 4:25:00=E2=80=AFam IST, Maxwell Doose wrote: >The current variable declaration and initializations are barely readable >and use comma separations across multiple lines=2E Refactor the >initializations so that mantissa and exp have separate declarations and >sign gets initialized later=2E > >Signed-off-by: Maxwell Doose >--- > ps: > Hi Jonathan, I noticed a potential divide-by-zero bug on line 241 in > scd30_read_raw(), where the value of tmp is dictated by hardware=2E > If the scd30_command_read() call on line 236 assigns 0 to tmp, then > when we run: > *val2 =3D 1000000000 / tmp; > we'll get a divide-by-zero=2E Will send a patch for this later=2E > > best regards, > max >=20 > drivers/iio/chemical/scd30_core=2Ec | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) > >diff --git a/drivers/iio/chemical/scd30_core=2Ec b/drivers/iio/chemical/s= cd30_core=2Ec >index a665fcb78806=2E=2Ebe8c055be184 100644 >--- a/drivers/iio/chemical/scd30_core=2Ec >+++ b/drivers/iio/chemical/scd30_core=2Ec >@@ -89,10 +89,15 @@ static int scd30_reset(struct scd30_state *state) > /* simplified float to fixed point conversion with a scaling factor of 0= =2E01 */ > static int scd30_float_to_fp(int float32) > { >- int fraction, shift, >- mantissa =3D float32 & GENMASK(22, 0), >- sign =3D (float32 & BIT(31)) ? -1 : 1, >- exp =3D (float32 & ~BIT(31)) >> 23; >+ int fraction, shift, sign; >+ int mantissa =3D float32 & GENMASK(22, 0); >+ int exp =3D (float32 & ~BIT(31)) >> 23; >+ >+ /* Determine sign of received float based on IEEE 754 standard */ >+ if (float32 & BIT(31)) >+ sign =3D -1; >+ else >+ sign =3D 1; Hi, Thank you for the refactor change=2E The previous version was more compact and readable=2E Splitting the variab= le declarations and expanding the sign assignment into an if/else block doe= s not improve clarity significantly=2E You can keep it simpler like: sign =3D (float32 & BIT(31)) ? -1 : 1; The IEEE 754 representation is already implicit from the bit manipulation,= so additional comment is probably unnecessary=2E Thanks, Sanjay > > /* special case 0 */ > if (!exp && !mantissa) >-- >2=2E54=2E0 >