Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp347492imu; Wed, 7 Nov 2018 18:51:00 -0800 (PST) X-Google-Smtp-Source: AJdET5cfQbBCsDsKeVzJ1aVRsoLwZUahlzE0ZCzRk5nj0nlzxwJuelP5PHiUVXRWKIz0/dt6R5ba X-Received: by 2002:a63:5c61:: with SMTP id n33-v6mr2289812pgm.1.1541645460145; Wed, 07 Nov 2018 18:51:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541645460; cv=none; d=google.com; s=arc-20160816; b=QCxDGKuCLb883s8Sw8QjiK97SNqyCohTEsg6qGnIQNdrM6bOVBhqRWEF9UET9BhqbE xTj+1z/Erkl1IiiCNeKLx2Ne6vT5gMseR80jxW2IwfWaqd4mghINpWYzq71z3eqyyiqe QsWjhJbYSL3o1TEXoniE64sMZLgo3ahe8oi+JOy9mNUUfAjI9EUbBqppLwFinH0Xlk0o kpRO6eS7SQaQu92Xy3ViFGTRNHwjYye42GlOazLYhj9M3dH5eV3EsJ5kd6C2NjfTB9Gz PFhYN57HbBXFW85dg/5OKvJHgBuOLmBX7g/kZEV4A3jXSoa+Jtn/RpsyYn+qidQQdkYe 5pSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=y/4UZToq2tS4oiFhUNEOOeGVB+rjNz76jbrKyvnBxYQ=; b=APxLAbxBMpY0zyjw8qju1GTVeEqUAkXhnIX/8k4o6VNOe3DVJ0X0oZTHDpj/oh/GR0 AFkQouxT6SC8AbhC/f5Wbug04zp3MRYkqumXvz+DNleyVSxczcpM6chK/OjFBRWZXuVd RbpL1iZ00wI0v99oihjclWM/cprFfsVCTxfNtMWYR9v0l1yiGwOVIvjQyK8p78nT0ZiO vgy02sOf92IUKOi893y/aAd0TAYY1FiKGLnmQw6jOmL6C/FXbqUWQhVnt3KbmEMH9Dq7 PZvmBDop5BcqPzPTb2k8jKL3vCE03UAtflR45owmsBnY9zqa+PlMkw1pqxMc53hAnFZL l9uA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JedbMW9i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si2375206pgs.126.2018.11.07.18.50.41; Wed, 07 Nov 2018 18:51:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JedbMW9i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbeKHMXB (ORCPT + 99 others); Thu, 8 Nov 2018 07:23:01 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44757 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728741AbeKHMXB (ORCPT ); Thu, 8 Nov 2018 07:23:01 -0500 Received: by mail-pl1-f196.google.com with SMTP id s5-v6so8790480plq.11 for ; Wed, 07 Nov 2018 18:49:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y/4UZToq2tS4oiFhUNEOOeGVB+rjNz76jbrKyvnBxYQ=; b=JedbMW9iEIhDjyw4LZzcmjFHYl6/f1pYsw6G5EVG2+iwkJYzprnVr5z4D8AdgbWwXR mFyBLCnj7OvlBdLXOfe7qNkm/fCQHPFVQnuryUogXNzgjbL935ZIakJRm1NnwkokpvYp 4A5EWs/vVG707lAKV6Xk0XyZiHVyTE5+UEFvU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=y/4UZToq2tS4oiFhUNEOOeGVB+rjNz76jbrKyvnBxYQ=; b=IluEqyV6tTCbaOTmRQ19xtMPrgzIfxaETRM93xGXv6H3pNwjyOHzyhgcM5UMqKnHEV vSou+Z2E377T2SSbDPGgKVfGhch9/BmqMNrFzVCfrURWJ0PFMs0WdvNptSG1Mg3d7GzD ttJ2fHmDk4IgFm9e7cPGsUaoRmlg2VMHJa6bF1TALvcAKMq/4dP2FnKqLBpzYjSP6CQq KHypRvrMpY+k3DqPObj13LuqW/e0i7pqT2gYm3bkRjJsmWwfEKWomd1KZ4+fYXBJO6ya ivvoLz2614IBoD4rjp6ADKfkHABlsScLl+Fhu/q7vegdlIOlMoI1d5J6eifrOyD7MUcu Yxdw== X-Gm-Message-State: AGRZ1gKvd6eydpfkmYQ3BkndFBEyrAGi3xSNZfb3PvC4wBzD5mSOsQrC fvnT9axGdLWR8iqyH76Op8zLhA== X-Received: by 2002:a17:902:aa8d:: with SMTP id d13-v6mr2881327plr.74.1541645385505; Wed, 07 Nov 2018 18:49:45 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id x14-v6sm2271519pfe.178.2018.11.07.18.49.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Nov 2018 18:49:44 -0800 (PST) From: Brian Norris To: Benson Leung Cc: Lee Jones , , Olof Johansson , Shawn Nematbakhsh , Alexandru Stan , Gwendal Grignou , Enrico Granata , RaviChandra Sadineni , Brian Norris Subject: [PATCH v2 1/2] platform/chrome: straighten out cros_ec_get_{next,host}_event() error codes Date: Wed, 7 Nov 2018 18:49:38 -0800 Message-Id: <20181108024939.174321-1-briannorris@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cros_ec_get_next_event() is documented to return 0 for success and negative for errors. It currently returns negative for some errors, and non-negative (number of bytes received) for success (including some "no data available" responses as zero). This mostly works out OK, because the callers were more or less ignoring the documentation, and only treating positive values as success (and indepdently checking the modification of 'wakeup'). Let's button this up by avoiding pretending to handle event/wakeup distinctions when no event info was retrieved (i.e., returned 0 bytes). And fix the documentation of cros_ec_get_host_event() and cros_ec_get_next_event() to accurately describe their behavior. Signed-off-by: Brian Norris --- v1 -> v2: * don't make as many changes to the API -- just fix the documentation and a few corner cases instead --- drivers/platform/chrome/cros_ec_proto.c | 4 ++-- include/linux/mfd/cros_ec.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c index b6fd4838f60f..fff67b389c87 100644 --- a/drivers/platform/chrome/cros_ec_proto.c +++ b/drivers/platform/chrome/cros_ec_proto.c @@ -580,7 +580,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event) if (!ec_dev->mkbp_event_supported) { ret = get_keyboard_state_event(ec_dev); - if (ret < 0) + if (ret <= 0) return ret; if (wake_event) @@ -590,7 +590,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event) } ret = get_next_event(ec_dev); - if (ret < 0) + if (ret <= 0) return ret; if (wake_event) { diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index e44e3ec8a9c7..de8b588c8776 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h @@ -317,7 +317,9 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev); * @wake_event: Pointer to a bool set to true upon return if the event might be * treated as a wake event. Ignored if null. * - * Return: 0 on success or negative error code. + * Return: negative error code on errors; 0 for no data; or else number of + * bytes received (i.e., an event was retrieved successfully). Event types are + * written out to @ec_dev->event_data.event_type on success. */ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); @@ -329,7 +331,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); * events raised and call the functions in the ec notifier. This function * is a helper to know which events are raised. * - * Return: 0 on success or negative error code. + * Return: 0 on error or non-zero bitmask of one or more EC_HOST_EVENT_*. */ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); -- 2.19.1.930.g4563a0d9d0-goog