Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp17623lqp; Thu, 4 Apr 2024 06:07:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjIF7nwEDihtjJZoUa9SZLc4W55lx790421v/6At8sn+7iq7S24TAqhi0DM6w3lq9p+U6G4VcHD2m8MNalcz4mAl7NPMau3uRPU12WwA== X-Google-Smtp-Source: AGHT+IEs/PKCDKXJTW5LtoGn15HusM+X5K+jJyP2TPd/JpjvOa+4a3pj7VOCV5J4Wycs7YypF+Qr X-Received: by 2002:a05:6102:ace:b0:479:d10b:ebc1 with SMTP id m14-20020a0561020ace00b00479d10bebc1mr536612vsh.13.1712236048957; Thu, 04 Apr 2024 06:07:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712236048; cv=pass; d=google.com; s=arc-20160816; b=XPkiqvm25t27w9qAGAZA+nhoun5ASUoQHbCwQDzJwEzoUJ5Wqb/nBSd8ZMBbC3NXSf OmAZvuz/VjPd0suG+pdpqyDaZY817h7/ivEvJ8W9W6dhXVzjPi1wTV/pPhoKOAZUtOEd cRmfn/AgtRYsOScJnGm09eidHK23AcMATeixaCKp4qVTBCuFpBYG8uc9JW1bnB5IimaU ntFhgA8ouC5w0no9gh6kPs9PAtK+wjuGAe0Ktmxf68z9wrJukQEeLewaOYSfanQe8PL3 5IvPanSJisyMfCrZDVsTi+hJwFC0MRZa1nwkooxk4XXcIwza8EYv+GucPphGZKvVSEv1 R9Zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=B6ZKBE1A3WQx834moPxz4z7C1Jzbsva33aVYrv5N6S0=; fh=nt8OD/gGcrjDh0FGIxBLAJDw09fH+D5qaykN0anWwok=; b=mPBE0Hl17jc8pNMwnFrs+3WUguHOSMCMnCIoSqLE1WBV8lLREtr6iQyLvnB+QiOlUb jBK1c+3oJX8erO0YiAW/43T5XNl2jBA9LORSay8QxHERswd7V9uHULCo8ZxTlp5fTgOK ep1NiCmQlOvy8REf6vmtUm2IQZO5WrDAFrEaiu4GLucJ2Hkbs44bOPPmzQpF2a0TGOcC 9zfjldqL/m/wI0uO4AJGw+nzL0wTHTu8+CJ5fk5tFJukgrLW6NJ1YdZgWn83e1UvUlJI j7gqE2nAV3p0En59JEGtMupOKCTu2+zH7aoP36/5c147v568Tb8VathgfmtA4LpXpoOE u7cw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LUm8zcxc; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-131486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131486-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j22-20020a056102135600b004733ef24615si2051215vsl.655.2024.04.04.06.07.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 06:07:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LUm8zcxc; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-131486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131486-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 980D71C211A0 for ; Thu, 4 Apr 2024 13:07:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A921186AEE; Thu, 4 Apr 2024 13:07:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LUm8zcxc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B557376023; Thu, 4 Apr 2024 13:07:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712236038; cv=none; b=T6lub8yQWgHVXhEgL8uPvY1tFbwy26Bt0bIRnqVNAR+PGqlvj1hcg0RcEE2j81JdfVODJd5Rv5kU9CUjbHxzJbrnPLs1u4LQTL9i0ZXGOxTjd9cg7inojvYBpEswr5N1V5qu5gBma8scdjps9snWoVq8f2qnagjFL/bWfRiBTRM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712236038; c=relaxed/simple; bh=/WxjYUxiMjvM+15e3/TPZZtRZclGhIY3WqmvhzBts6Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZJ3JCPj50C+j+Q+ExVb+IeOHfAC0QNjch+YZ6rRnyC3z4rWUmxuL5XUS7aqSpeVKDAOYghWlaDjotWQtNybOmGO5eFhReBE2MNjQ99Enrxgz/HgjMeQDGWiIBjJErqlvQ2EPe5LYsvbo/YlmCGcgKKt5csTrCGYin2j1qwa4uZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LUm8zcxc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6F27C433F1; Thu, 4 Apr 2024 13:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712236038; bh=/WxjYUxiMjvM+15e3/TPZZtRZclGhIY3WqmvhzBts6Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LUm8zcxcIXRKrm7XbOazcjAb3bcda4GG7Zv9PMJSb8cwfMv++1zOWTAPvCiCziLtk IS+iVyT/JNbDTYpDXkhffcnF1k6/5+G4SsiuF0OMNlezjn5Clhz3r2Rso6nmP1+FHA /UmjzzZXr/OwtgHMN1fy3HfzEGlr3d0fSoozEB9g= Date: Thu, 4 Apr 2024 15:07:15 +0200 From: Greg Kroah-Hartman To: Dmitry Baryshkov Cc: Pavan Holla , Heikki Krogerus , Benson Leung , Tzung-Bi Shih , Guenter Roeck , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , chrome-platform@lists.linux.dev Subject: Re: [PATCH v3 2/2] usb: typec: ucsi: Implement ChromeOS UCSI driver Message-ID: <2024040449-average-foyer-defa@gregkh> References: <20240403-public-ucsi-h-v3-0-f848e18c8ed2@chromium.org> <20240403-public-ucsi-h-v3-2-f848e18c8ed2@chromium.org> <3ezjocthsigo3t746slmgzffnmpxw7wwf3s535basiaf2qy6io@7ocxva6ndsbt> 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=us-ascii Content-Disposition: inline In-Reply-To: <3ezjocthsigo3t746slmgzffnmpxw7wwf3s535basiaf2qy6io@7ocxva6ndsbt> On Wed, Apr 03, 2024 at 09:58:33PM +0300, Dmitry Baryshkov wrote: > On Wed, Apr 03, 2024 at 06:05:22PM +0000, Pavan Holla wrote: > > Implementation of a UCSI transport driver for ChromeOS. > > This driver will be loaded if the ChromeOS EC implements a PPM. > > > > Signed-off-by: Pavan Holla > > --- > > drivers/usb/typec/ucsi/Kconfig | 13 ++ > > drivers/usb/typec/ucsi/Makefile | 1 + > > drivers/usb/typec/ucsi/cros_ec_ucsi.c | 245 ++++++++++++++++++++++++++++++++++ > > 3 files changed, 259 insertions(+) > > > > diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig > > index bdcb1764cfae..4dceb14a66ee 100644 > > --- a/drivers/usb/typec/ucsi/Kconfig > > +++ b/drivers/usb/typec/ucsi/Kconfig > > @@ -69,4 +69,17 @@ config UCSI_PMIC_GLINK > > To compile the driver as a module, choose M here: the module will be > > called ucsi_glink. > > > > +config CROS_EC_UCSI > > + tristate "UCSI Driver for ChromeOS EC" > > + depends on MFD_CROS_EC_DEV > > + depends on CROS_USBPD_NOTIFY > > + depends on !EXTCON_TCSS_CROS_EC > > + default MFD_CROS_EC_DEV > > + help > > + This driver enables UCSI support for a ChromeOS EC. The EC is > > + expected to implement a PPM. > > + > > + To compile the driver as a module, choose M here: the module > > + will be called cros_ec_ucsi. > > + > > endif > > diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile > > index b4679f94696b..cb336eee055c 100644 > > --- a/drivers/usb/typec/ucsi/Makefile > > +++ b/drivers/usb/typec/ucsi/Makefile > > @@ -21,3 +21,4 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o > > obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o > > obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o > > obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o > > +obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o > > diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c > > new file mode 100644 > > index 000000000000..dd46b46d430f > > --- /dev/null > > +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c > > @@ -0,0 +1,245 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * UCSI driver for ChromeOS EC > > + * > > + * Copyright 2024 Google LLC. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include "ucsi.h" > > + > > +#define DRV_NAME "cros-ec-ucsi" > > + > > +#define MAX_EC_DATA_SIZE 256 > > +#define WRITE_TMO_MS 500 > > + > > +struct cros_ucsi_data { > > + struct device *dev; > > + struct ucsi *ucsi; > > + > > + struct cros_ec_device *ec; > > + struct notifier_block nb; > > + struct work_struct work; > > + > > + struct completion complete; > > + unsigned long flags; > > +}; > > + > > +static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val, > > + size_t val_len) > > +{ > > + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); > > + struct ec_params_ucsi_ppm_get req = { > > + .offset = offset, > > + .size = val_len, > > + }; > > + int ret; > > + > > + if (val_len > MAX_EC_DATA_SIZE) { > > + dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len); > > + return -EINVAL; > > + } > > + > > + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET, > > + &req, sizeof(req), val, val_len); > > + if (ret < 0) { > > + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret); > > + return ret; > > + } > > + return 0; > > +} > > + > > +static int cros_ucsi_async_write(struct ucsi *ucsi, unsigned int offset, > > + const void *val, size_t val_len) > > +{ > > + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); > > + uint8_t ec_buffer[MAX_EC_DATA_SIZE + sizeof(struct ec_params_ucsi_ppm_set)]; > > + struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *)ec_buffer; > > + int ret = 0; > > + > > + if (val_len > MAX_EC_DATA_SIZE) { > > + dev_err(udata->dev, "Can't write %zu bytes. Too big.", val_len); > > I think it's better be written as > > if (WARN_ON_ONCE(val_len > MAX_EC_DATA_SIZE)) > return -EINVAL; So if you trigger this, you just rebooted all boxes that have panic-on-warn enabled (hint, the HUGE majority in quantity of Linux systems out there.) So don't do that, just handle it like this. BUT, if this can be triggered by userspace, do NOT use dev_err() as that will just allow userspace to flood the kernel log. Pavan, who calls this? If userspace, this needs to be fixed. If it's only a kernel driver, it's fine as-is. thanks, greg k-h