All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jehoon Park <jehoon.park@samsung.com>
To: linux-cxl@vger.kernel.org
Cc: nvdimm@lists.linux.dev,
	Alison Schofield <alison.schofield@intel.com>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Ira Weiny <ira.weiny@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Kyungsan Kim <ks0204.kim@samsung.com>,
	Junhyeok Im <junhyeok.im@samsung.com>,
	Jehoon Park <jehoon.park@samsung.com>
Subject: [ndctl PATCH v2 2/3] libcxl: Fix accessors for temperature field to support negative value
Date: Mon,  7 Aug 2023 15:35:48 +0900	[thread overview]
Message-ID: <20230807063549.5942-3-jehoon.park@samsung.com> (raw)
In-Reply-To: <20230807063549.5942-1-jehoon.park@samsung.com>

Add a new macro function to retrieve a signed value such as a temperature.
Modify accessors for signed value to return INT_MAX when error occurs and
set errno to corresponding errno codes.

Signed-off-by: Jehoon Park <jehoon.park@samsung.com>
---
 cxl/lib/libcxl.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index af4ca44..fc64de1 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -3661,11 +3661,23 @@ cxl_cmd_alert_config_get_life_used_prog_warn_threshold(struct cxl_cmd *cmd)
 			 life_used_prog_warn_threshold);
 }
 
+#define cmd_get_field_s16(cmd, n, N, field)				\
+do {									\
+	struct cxl_cmd_##n *c =						\
+		(struct cxl_cmd_##n *)cmd->send_cmd->out.payload;	\
+	int rc = cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_##N);	\
+	if (rc)	{							\
+		errno = -rc;						\
+		return INT_MAX;						\
+	}								\
+	return (int16_t)le16_to_cpu(c->field);				\
+} while(0)
+
 CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_over_temperature_crit_alert_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_over_temperature_crit_alert_threshold);
 }
 
@@ -3673,7 +3685,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_under_temperature_crit_alert_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_under_temperature_crit_alert_threshold);
 }
 
@@ -3681,7 +3693,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_over_temperature_prog_warn_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_over_temperature_prog_warn_threshold);
 }
 
@@ -3689,7 +3701,7 @@ CXL_EXPORT int
 cxl_cmd_alert_config_get_dev_under_temperature_prog_warn_threshold(
 	struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_alert_config, GET_ALERT_CONFIG,
+	cmd_get_field_s16(cmd, get_alert_config, GET_ALERT_CONFIG,
 			  dev_under_temperature_prog_warn_threshold);
 }
 
@@ -3905,8 +3917,6 @@ CXL_EXPORT int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd)
 {
 	int rc = health_info_get_life_used_raw(cmd);
 
-	if (rc < 0)
-		return rc;
 	if (rc == CXL_CMD_HEALTH_INFO_LIFE_USED_NOT_IMPL)
 		return -EOPNOTSUPP;
 	return rc;
@@ -3914,7 +3924,7 @@ CXL_EXPORT int cxl_cmd_health_info_get_life_used(struct cxl_cmd *cmd)
 
 static int health_info_get_temperature_raw(struct cxl_cmd *cmd)
 {
-	cmd_get_field_u16(cmd, get_health_info, GET_HEALTH_INFO,
+	cmd_get_field_s16(cmd, get_health_info, GET_HEALTH_INFO,
 				 temperature);
 }
 
@@ -3922,10 +3932,10 @@ CXL_EXPORT int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd)
 {
 	int rc = health_info_get_temperature_raw(cmd);
 
-	if (rc < 0)
-		return rc;
-	if (rc == CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL)
-		return -EOPNOTSUPP;
+	if (rc == CXL_CMD_HEALTH_INFO_TEMPERATURE_NOT_IMPL) {
+		errno = EOPNOTSUPP;
+		return INT_MAX;
+	}
 	return rc;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2023-08-07  6:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20230807063513epcas2p261ba4dfbfff34e99077596128eb6fc48@epcas2p2.samsung.com>
2023-08-07  6:35 ` [ndctl PATCH v2 0/3] Fix accessors for temperature field when it is negative Jehoon Park
     [not found]   ` <CGME20230807063523epcas2p45f74891b764d920b2a9bd22ddf6b6998@epcas2p4.samsung.com>
2023-08-07  6:35     ` [ndctl PATCH v2 1/3] libcxl: Update a revision by CXL 3.0 specification Jehoon Park
2023-08-07 13:02       ` Jonathan Cameron
2023-08-08  7:38         ` Jehoon Park
2023-08-25  1:45       ` Davidlohr Bueso
     [not found]   ` <CGME20230807063538epcas2p4965d5d117b8ef87ac4217bec53beff95@epcas2p4.samsung.com>
2023-08-07  6:35     ` Jehoon Park [this message]
2023-08-07 13:14       ` [ndctl PATCH v2 2/3] libcxl: Fix accessors for temperature field to support negative value Jonathan Cameron
2023-08-08  7:41         ` Jehoon Park
     [not found]   ` <CGME20230807063547epcas2p4ccb33e410e77a94e088f283b8c2925db@epcas2p4.samsung.com>
2023-08-07  6:35     ` [ndctl PATCH v2 3/3] cxl: Fix the checking value when listing device's health info Jehoon Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230807063549.5942-3-jehoon.park@samsung.com \
    --to=jehoon.park@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=junhyeok.im@samsung.com \
    --cc=ks0204.kim@samsung.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.