From nobody Fri Apr 17 20:22:44 2026 Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 C34EA2472A2 for ; Mon, 16 Feb 2026 00:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771203220; cv=none; b=feyJ+fMU+mMbC0RtJfVCV9K/AM8DOIQ5zp4BVyNDyOvaQiYTncoW5Ilxb/NsVAR1YGHBzJbTySDzh+er08MyH3Fz7un15LZwCLBm1/ANTkqM1Wrw6lB/YZ/UV0HPjZD1lwOUhx9knxKspiTzpSPG/JtXO74FedO/wkmoPHPQ0pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771203220; c=relaxed/simple; bh=TBLSrqBeZomDV2gMZy7BCzI9rhkp7P+o3Dt33E5ZQvQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aCiG3s1Y691JId3J6g5AB83VHuhlwd5PXltdOqjdQrD28iPaO0YJ1uWkxfRRn7Ib6Inp185MTGjuUe4ttxoLUF+x5IxprD9yXU4Q1kedRK0itn+70grzSi4vRw8uHpAbYSUs2P5qdLaAOGApvvCBODKmMq6IGWGvTWI0IIW0c7A= 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=QFPO2+pV; arc=none smtp.client-ip=209.85.128.179 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="QFPO2+pV" Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-7927261a3acso22661327b3.0 for ; Sun, 15 Feb 2026 16:53:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771203218; x=1771808018; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TEPsTH3PriBiWEFGViHWLoH9Qxt8oTMiRXWW0uvcBQY=; b=QFPO2+pVWLu2MiHeMqPwcZsvQc81mH6xZsqgW5OwGR+cgYo89ZZMxomYjOXIQnv5/9 fsMt5y5GB8YDqcmY7O7u37geQcPmLNYUHttscQjSsEtJI7GZc5MME85EfBIQLL+aHy2g jhEwELhfF6vI17O5xU1KZdV9428C7BK+bqKiEH6eNOhkkZW16FwDp+vr5nd4n/dIsHdu N7Ki2RKqtHAcGgKtthFlWBEJhNWQjXrt/2+G75iAyYax5NMLE5lduCQ5CbHZcPxU3Le1 Nnkz4431c3205OG0lxz8UJBFFK9owCrPZYTZrWP8DJ1WCD5FHMZWH1f9jQa7tiGM3tji rbbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771203218; x=1771808018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TEPsTH3PriBiWEFGViHWLoH9Qxt8oTMiRXWW0uvcBQY=; b=lt1DMntgA+WKxjlB0eyGbFyor8CvNXU134w7niDaCYJDoR4KDMjSDi5QJ+dCPY8wCd CicWeePDCcJYGKuNzONvg6peypo6vbBR3hnQieSN0NriebX/73U7ekNP4YNK79wDVpCR 4Cu/40Byauu2jKdJrI2RhGK3H+T25X9OKaOqGeXWDrbqriotIeASw26qhfBZrIP8Ikb2 XWn1yH5MUrugzrFYdTpBNGHZDjW2txkpbOQMIoElyPdd+dXyAag13sv+p00WDZQaeoN2 B+R3ufEUYwGRAUN+j3HbjECNl0Dnau9FOgZmN08ZrCAWPq+SCgvJtyuXmr9aKd91Oand uCKg== X-Forwarded-Encrypted: i=1; AJvYcCVryaJRBlFKPw28AZ0XlwkGawaaxDmcFpdsVajfoBKXwZNKWSEDH38jnjp/NX4zHylfV76x+U1d2OFODOQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yy/UWFt7WVR+m1Na3dZS1RfTF9E+VAVPyB2/UWGZ1s6070QzFZn SiGS9UCRW6+zY4WkL7pz370/xepAVM8+t2ivvWq6bBUUVKLLIjDIInHT X-Gm-Gg: AZuq6aLOMhhrUsma5EXjaWo/mXS2cJLI9ISw5eDon8jE96HvxZdWdYiE1kR9cesRxK+ B0ehlkkiuX7l5jUzrXI8KE9grxCfagXP4aCAuIVo+ZIAA+tNXoMQXmt3uNPJxO2iI0Qjvfa/kFx C6ilnqyxBgx+TG4UszZvVO25kW6Mmib1DkUaEzYjprRggb6K8Fu6IHO6LtLBoyK9WvnisboNGE/ dI7G0iiJkRuqhhXGnhdF2ScUNRXxp9nwk7PyK0meolMz/1C6FqMeO1ZOGihq2jkwJxYe4AdZPNT N3kXq6dplBa7TF41C7tqU5nWSmkIL3fEjXehpRAgCETf86gDtopWqaTO5ZzhIUYc3aynuRMdSHI IstGvO4EiZ0FFo2MkGVdoaGbECTldSmyfgPsrY/qgmGZ4cPZF3fV7xlsca/mShGJtxgu4qtDQ7s FJ7rP+lvMvawa3Wy8QPgN+98qKIceVzMCuWrF4vayZjYZBXDro7K7gw0fWguqgQUHLCBHTd94BH 0Licbxt4U4wPJYcWWyB/woca6kFQK04dQ7lWaxpjAc= X-Received: by 2002:a05:690c:1a:b0:796:3c5d:70bf with SMTP id 00721157ae682-797ac5570c3mr48531827b3.29.1771203217683; Sun, 15 Feb 2026 16:53:37 -0800 (PST) Received: from tux ([2601:7c0:c37c:4c00:e3a8:26f7:7e08:88e1]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7966c257ed5sm94797637b3.45.2026.02.15.16.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Feb 2026 16:53:37 -0800 (PST) From: Ethan Tidmore To: jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ethan Tidmore Subject: [PATCH v3 1/2] iio: light: gp2ap020a00f: simplify locking with guard() Date: Sun, 15 Feb 2026 18:53:16 -0600 Message-ID: <20260216005317.11763-2-ethantidmore06@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260216005317.11763-1-ethantidmore06@gmail.com> References: <20260216005317.11763-1-ethantidmore06@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the guard() cleanup handler to manage the device lock. This simplifies the code by removing the need for manual unlocking and goto error handling paths. Suggested-by: Jonathan Cameron Signed-off-by: Ethan Tidmore --- v3: - Use guard() instead of manual locking and unlocking. drivers/iio/light/gp2ap020a00f.c | 64 ++++++++++---------------------- 1 file changed, 20 insertions(+), 44 deletions(-) diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a= 00f.c index c7df4b258e2c..d1a511ac7690 100644 --- a/drivers/iio/light/gp2ap020a00f.c +++ b/drivers/iio/light/gp2ap020a00f.c @@ -31,6 +31,7 @@ * the other one. */ =20 +#include #include #include #include @@ -1024,17 +1025,14 @@ static int gp2ap020a00f_write_event_val(struct iio_= dev *indio_dev, bool event_en =3D false; u8 thresh_val_id; u8 thresh_reg_l; - int err =3D 0; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 thresh_reg_l =3D gp2ap020a00f_get_thresh_reg(chan, dir); thresh_val_id =3D GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l); =20 - if (thresh_val_id > GP2AP020A00F_THRESH_PH) { - err =3D -EINVAL; - goto error_unlock; - } + if (thresh_val_id > GP2AP020A00F_THRESH_PH) + return -EINVAL; =20 switch (thresh_reg_l) { case GP2AP020A00F_TH_L_REG: @@ -1046,30 +1044,23 @@ static int gp2ap020a00f_write_event_val(struct iio_= dev *indio_dev, &data->flags); break; case GP2AP020A00F_PH_L_REG: - if (val =3D=3D 0) { - err =3D -EINVAL; - goto error_unlock; - } + if (val =3D=3D 0) + return -EINVAL; + event_en =3D test_bit(GP2AP020A00F_FLAG_PROX_RISING_EV, &data->flags); break; case GP2AP020A00F_PL_L_REG: - if (val =3D=3D 0) { - err =3D -EINVAL; - goto error_unlock; - } + if (val =3D=3D 0) + return -EINVAL; + event_en =3D test_bit(GP2AP020A00F_FLAG_PROX_FALLING_EV, &data->flags); break; } =20 data->thresh_val[thresh_val_id] =3D val; - err =3D gp2ap020a00f_write_event_threshold(data, thresh_val_id, - event_en); -error_unlock: - mutex_unlock(&data->lock); - - return err; + return gp2ap020a00f_write_event_threshold(data, thresh_val_id, event_en); } =20 static int gp2ap020a00f_read_event_val(struct iio_dev *indio_dev, @@ -1081,23 +1072,17 @@ static int gp2ap020a00f_read_event_val(struct iio_d= ev *indio_dev, { struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); u8 thresh_reg_l; - int err =3D IIO_VAL_INT; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 thresh_reg_l =3D gp2ap020a00f_get_thresh_reg(chan, dir); =20 - if (thresh_reg_l > GP2AP020A00F_PH_L_REG) { - err =3D -EINVAL; - goto error_unlock; - } + if (thresh_reg_l > GP2AP020A00F_PH_L_REG) + return -EINVAL; =20 *val =3D data->thresh_val[GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l)]; =20 -error_unlock: - mutex_unlock(&data->lock); - - return err; + return IIO_VAL_INT; } =20 static int gp2ap020a00f_write_prox_event_config(struct iio_dev *indio_dev, @@ -1165,7 +1150,7 @@ static int gp2ap020a00f_write_event_config(struct iio= _dev *indio_dev, enum gp2ap020a00f_cmd cmd; int err; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 switch (chan->type) { case IIO_PROXIMITY: @@ -1186,8 +1171,6 @@ static int gp2ap020a00f_write_event_config(struct iio= _dev *indio_dev, err =3D -EINVAL; } =20 - mutex_unlock(&data->lock); - return err; } =20 @@ -1199,7 +1182,7 @@ static int gp2ap020a00f_read_event_config(struct iio_= dev *indio_dev, struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); int event_en =3D 0; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 switch (chan->type) { case IIO_PROXIMITY: @@ -1223,8 +1206,6 @@ static int gp2ap020a00f_read_event_config(struct iio_= dev *indio_dev, break; } =20 - mutex_unlock(&data->lock); - return event_en; } =20 @@ -1385,7 +1366,7 @@ static int gp2ap020a00f_buffer_postenable(struct iio_= dev *indio_dev) struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); int i, err =3D 0; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 /* * Enable triggers according to the scan_mask. Enabling either @@ -1413,15 +1394,12 @@ static int gp2ap020a00f_buffer_postenable(struct ii= o_dev *indio_dev) } =20 if (err < 0) - goto error_unlock; + return err; =20 data->buffer =3D kmalloc(indio_dev->scan_bytes, GFP_KERNEL); if (!data->buffer) err =3D -ENOMEM; =20 -error_unlock: - mutex_unlock(&data->lock); - return err; } =20 @@ -1430,7 +1408,7 @@ static int gp2ap020a00f_buffer_predisable(struct iio_= dev *indio_dev) struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); int i, err =3D 0; =20 - mutex_lock(&data->lock); + guard(mutex)(&data->lock); =20 iio_for_each_active_channel(indio_dev, i) { switch (i) { @@ -1452,8 +1430,6 @@ static int gp2ap020a00f_buffer_predisable(struct iio_= dev *indio_dev) if (err =3D=3D 0) kfree(data->buffer); =20 - mutex_unlock(&data->lock); - return err; } =20 --=20 2.53.0 From nobody Fri Apr 17 20:22:44 2026 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.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 6BEEA256C84 for ; Mon, 16 Feb 2026 00:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771203220; cv=none; b=NLSfAQB+oUiJk1f7P6Q+A20K1Ez04VUK5p0goDFzciqXCwczFJ0Mmj3P7nwRxu5gG7jpipvBr7d4cmkzvS2LajN4uyYOqXs6AYbTzh6OmiTwFaSA+hqleAKIHbrfRqDKRiQXWKtwDJD5NegX5QV3wxgnqDqs4m7PF3jkJeGVArE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771203220; c=relaxed/simple; bh=60hN41ih3iOsAB6ymTysRnh2xYyZO8I9uzHpwFHZRtQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WUoHBMCozlt+uP6C+iyrbkNs9uAG7MaFhLjaoPmouNrHId2qwpSBc/kH2dkjCIo98J45U3Qox2nkimCQak0pDbC5bOn3FjiFidbvFRUqD0ojHUImixZQpEtyjRfRRyixzqAtStyWTeeJvz6U2D+1zujaGwwZe+HKqgyVYDjMspE= 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=SsaBWMP8; arc=none smtp.client-ip=209.85.128.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="SsaBWMP8" Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-7946a1f2430so21157697b3.1 for ; Sun, 15 Feb 2026 16:53:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771203218; x=1771808018; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vXcdPR7MA83++rX9pDUuu51PyGAjXa4lMqkkaZ3K5L4=; b=SsaBWMP8l6UOFllBy/vn+6aqDdqS+o14Vp2/soOKl20pBH/gCpU+5DeM5i3YJuHWB0 v0DVBSMGlFQYZwDTvdGabDwYz3Zy5qGcerhyxtrnVnKncDFZgJKLIGmBVvzKqgwtQ97i g+JRf0fCUHgMqeOEQ/ST/HCjtIJ2uZZO38GWTwx9ldEByhhqrxAmlGC/XrNxDBERyv2J cnK0B4X+l1qFyDLd5UzZdCPbaJJAKnejQ9mVBhdMZfgULZnPM50C83gOHhFbrnW6jTss DQX5G0SSxRVdxoJZk2JkOjXhHKVGNnMlCunFClRwIKmduCxsG+TM7Y+AyXvCmcX0WU0e 2faA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771203218; x=1771808018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=vXcdPR7MA83++rX9pDUuu51PyGAjXa4lMqkkaZ3K5L4=; b=OHMnTyjZ3V+Vs/KvbXB4xSHMmDPEe4ibeFppw1CMKydRcoVWqAaNEow7UViPFPHNmE Zzk1QyiYO0Xsv/liHjOeDR6vV2lZj2eVMdBhcL4eWZ9pzZIjPcJcOTtNm0sFHJ5k9zxk KS/KV5AoN5lk/MeJeqLDo9StD2RcwepKX6VUdYyuRcfGd9sBrIRgwoSIDECnLia5U0IS R9QFmFaxV2W0rJ4q15OQPcBdzzuQwa0zFqtj8Iw0YkhDTTosT4b8RFWHW/M4NtlP6cRy vWJp19/sjWpKi3Vcq0M1XY+mgUlbs6IMgkWozff0hIt+Bt6cfEfS3ikKB98AP3wOxTeZ iUOg== X-Forwarded-Encrypted: i=1; AJvYcCVfZTPNa6zCmFeNVeE2QSlLGZZRkd1e/oJ5JK/HYFq4U8dLGg+jj+b//VHzRuF1crS3pZ+IfKXnSlbbEUE=@vger.kernel.org X-Gm-Message-State: AOJu0YzE6wcW7gP5EuXXd7Oplx2AccUqJOkvZ9ar63+FAMRk+Bgzx/Eu JWw/yHPyWLDEwRmQcnA5kTwIDBTexSJ2f2lpBa3YIAZ/fAIJbEB3Z2cl X-Gm-Gg: AZuq6aKV/t4URSkSUovOmzQdOSuoRKOnd3ObkcP546Ojh0yoK/dE2zqLeD44geiJ7uA FoY90jU0YzMr9H0b6dKCbNRP5rhec5ge5AitbnlXRiov7KjJcZTZ6lHl5474GEVNjW/I1b3JSyC Il2C8HG7Zgg0lqGtTaOJLvtDGdITzTF8wBkHlI0U461UHM2cyuWGXBbLbr1ngQnRgUtz6zem1zk yHASlBVv5zqUmfHe1rLZjHCRtwZnpPKWZKGm1xfo5m4IVK8CZC2SwGQJNk5UipHuj/G9+6Q4xuk hjwekiGn6wfwUkJBmCuY+IMeutY9RD67ozOL0yWQUuovGRu7fVMfOpnmilCK04hZYdd5f7HB+3P 99HW7vQ5eBoSwF3fJwN87Cv6pVVi2UZbCbctsbOrBQ4FJTEaGYWz1r1v/L/17Bfr4kKI1xoLY3T ZGbWfvnKeom/g3KJAQctxoM6fmcTF5aeUNj1ShUP5C0rrfLZ6FeGqDJAYg90ex2+8cp752YvIy8 bQ0bw/6CeS8GsT6eTtBdvPWazzPrB/RvyUAuQfCe+E= X-Received: by 2002:a05:690c:d96:b0:795:294c:fd31 with SMTP id 00721157ae682-797ac5d3737mr46326717b3.38.1771203218448; Sun, 15 Feb 2026 16:53:38 -0800 (PST) Received: from tux ([2601:7c0:c37c:4c00:e3a8:26f7:7e08:88e1]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7966c257ed5sm94797637b3.45.2026.02.15.16.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Feb 2026 16:53:38 -0800 (PST) From: Ethan Tidmore To: jic23@kernel.org Cc: dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Ethan Tidmore Subject: [PATCH v3 2/2] iio: light: gp2ap020a00f: correct return type to int Date: Sun, 15 Feb 2026 18:53:17 -0600 Message-ID: <20260216005317.11763-3-ethantidmore06@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260216005317.11763-1-ethantidmore06@gmail.com> References: <20260216005317.11763-1-ethantidmore06@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function gp2ap020a00f_get_thresh_reg() can return -EINVAL in its error path. Yet, the function has return type of u8. Added error checking for gp2ap020a00f_get_thresh_reg() return value. Detected by Smatch: drivers/iio/light/gp2ap020a00f.c:1013 gp2ap020a00f_get_thresh_reg() warn: signedness bug returning '(-22)' Signed-off-by: Ethan Tidmore Reviewed-by: Andy Shevchenko --- v3: - Remove Fixes: tag. - Added Smatch warning. v2: - Fixed gp2ap020a00f_get_thresh_reg() parameter alignment. - Removed unneeded whitespace between assignment and check. drivers/iio/light/gp2ap020a00f.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/iio/light/gp2ap020a00f.c b/drivers/iio/light/gp2ap020a= 00f.c index d1a511ac7690..fae7605f2f5c 100644 --- a/drivers/iio/light/gp2ap020a00f.c +++ b/drivers/iio/light/gp2ap020a00f.c @@ -993,8 +993,8 @@ static irqreturn_t gp2ap020a00f_trigger_handler(int irq= , void *data) return IRQ_HANDLED; } =20 -static u8 gp2ap020a00f_get_thresh_reg(const struct iio_chan_spec *chan, - enum iio_event_direction event_dir) +static int gp2ap020a00f_get_thresh_reg(const struct iio_chan_spec *chan, + enum iio_event_direction event_dir) { switch (chan->type) { case IIO_PROXIMITY: @@ -1024,11 +1024,14 @@ static int gp2ap020a00f_write_event_val(struct iio_= dev *indio_dev, struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); bool event_en =3D false; u8 thresh_val_id; - u8 thresh_reg_l; + int thresh_reg_l; =20 guard(mutex)(&data->lock); =20 thresh_reg_l =3D gp2ap020a00f_get_thresh_reg(chan, dir); + if (thresh_reg_l < 0) + return thresh_reg_l; + thresh_val_id =3D GP2AP020A00F_THRESH_VAL_ID(thresh_reg_l); =20 if (thresh_val_id > GP2AP020A00F_THRESH_PH) @@ -1071,11 +1074,13 @@ static int gp2ap020a00f_read_event_val(struct iio_d= ev *indio_dev, int *val, int *val2) { struct gp2ap020a00f_data *data =3D iio_priv(indio_dev); - u8 thresh_reg_l; + int thresh_reg_l; =20 guard(mutex)(&data->lock); =20 thresh_reg_l =3D gp2ap020a00f_get_thresh_reg(chan, dir); + if (thresh_reg_l < 0) + return thresh_reg_l; =20 if (thresh_reg_l > GP2AP020A00F_PH_L_REG) return -EINVAL; --=20 2.53.0