Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2324626pxp; Mon, 7 Mar 2022 12:56:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJydlY7LjHO+2tRQCHfPnEn+bTgRxrJdXhYw4FiEBqGtdGf7i94y+vxU2yjSo+LYHXKJH+OW X-Received: by 2002:a17:90a:fec:b0:1bf:3c6a:c8a3 with SMTP id 99-20020a17090a0fec00b001bf3c6ac8a3mr875517pjz.191.1646686565204; Mon, 07 Mar 2022 12:56:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646686565; cv=none; d=google.com; s=arc-20160816; b=bx6fwCh0SItT/JV3/39Oqp+Isvhiak51yX2bOIhVHJBhkJ0jP9oOaA1crTZChxrP5u H6n0srXY3T6OMbWyzKanA5asU74kz3OkfeFskt3OOGcupcKr9ISaj0vm4jbPf6onXXxZ /RePAsCdYuDMpyzNb/9yYS6DATtM/fDNKbJjEPZ7EyorpWDtPw1pPHaRA0JlU4ELekvY grZMtLgNmZoVa/rKIWza0cnqFDVnU/mqBsqQCysTIALGM06uSxtaBpN75U7DN1FLEbHA dr8wXQ7oD9lDxyWLMlV6S5d31l/qp4snHNY7z8vHTb6uArPre+hh8bNMm/W1sfmhI6c7 KsvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=5LigUQH3eW5GSlPkafEnbTkMfLkaSU6yR36/4QRsjNw=; b=EK2pW1OjHW4oj52BLxF3mxrKD52QHk1XeewGAwIJ5M7D0XwEWTDPnXOqmXPTNryLzO geriaQDty5Ts1Ecd5BO/S2YvmbrvEfurqP/Otv9XS5vAd63Bh51lsAR8QRhD1JA64INX fc6TNa0cqjcUN+JQy0Vm83QMWq5T+4MqJm90t3JywU/xKWdUId5NlFf3AhinCbEiKuby Jz8YeqPtoP4iP+NM8dU6nomMrzTC0utOI43frAZ+GN4ffXcJRk7rXQA52R/eV3kRp4j8 0kFAomDT+bSMSlxz8Q3Q/7YPJFAeluOt2frdNonUztL2EsgCKg1mWcTDRqCBad63Fwg+ fw+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bj2iJMwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a170902ea0600b0015193ff78fcsi13963089plg.50.2022.03.07.12.55.49; Mon, 07 Mar 2022 12:56:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bj2iJMwP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243347AbiCGOp2 (ORCPT + 99 others); Mon, 7 Mar 2022 09:45:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239555AbiCGOp1 (ORCPT ); Mon, 7 Mar 2022 09:45:27 -0500 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BB2B140EF for ; Mon, 7 Mar 2022 06:44:32 -0800 (PST) Received: by mail-pl1-x62a.google.com with SMTP id z11so13945152pla.7 for ; Mon, 07 Mar 2022 06:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5LigUQH3eW5GSlPkafEnbTkMfLkaSU6yR36/4QRsjNw=; b=Bj2iJMwPQ9Dc+ArNwHzYLW3J5J+tEB3ta2nPO3ROhKtqFn/WN8+nK3oscWG3hjsjKj nRSaasKIOfnqm8nMJdhplfrsu/IldF8haJT33RHEssR4peHHgcA5G9tB0Yc9tafYiXhZ lDEoN4i7wXGwhU6YwYpCwFbKy/zu3bEJob5xtPC+7LSEIsD7OE9WamReIbgaqS3DKrcw 7IgcNC88X9d9+rZsbR8aDoTDcx5UT5eI/8QUuA5yrJstko1gxEDRtoARyYgAnRUJjCPn htoNB8gk7O6u8sAP3Vn5ela4wrKoWzYPbtxRbxvWfl4TEbTxsmpkjNvDFjASE+ozTC6v gMvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5LigUQH3eW5GSlPkafEnbTkMfLkaSU6yR36/4QRsjNw=; b=yF/tbClyyrTBuWbH8H8RAz1bcHZf5PbUJ/u4JtsA7sSjbNs9Au7lPEyNLqhYjF6UEJ wLb75J04c+FHyDeFJjnHFuvLk28Zpgp9tk8fLYZrU3YleNtrQoVPuZvGMeSXH3lih5r9 OMXf7nP+gAUMs0Y/c2PfCSmYEI44npwnDVDZAooHaVWOWT3lk1eZjF6YUYj/3dYhg2Iy VSTrKpQNmMYQBUQAWaqQ055TwZMv7vEw1hzyHbSeI40zC0eRwxmI7x/10Yblf+CTTy/B V15xov7IY1l73rEOhs5WD04XbmKBNz1u8oF64daje1mTLHdw4lMdV2OtS7jYFqWcDjMg bLqg== X-Gm-Message-State: AOAM533htqhcXBQLNTSvUE3C2gq47RLBrpsJfZX3gd792C6Rjav/27l3 ZLfVoAjvtv1ctVt8caDVwUWdb7LBMZMJjttl/LTcv6fpSNU= X-Received: by 2002:a17:902:a3cb:b0:151:e52e:fa0c with SMTP id q11-20020a170902a3cb00b00151e52efa0cmr6138611plb.70.1646664271812; Mon, 07 Mar 2022 06:44:31 -0800 (PST) MIME-Version: 1.0 References: <20220307094042.48446-1-clement.leger@bootlin.com> <20220307120000.49f88c8b@fixe.home> In-Reply-To: <20220307120000.49f88c8b@fixe.home> From: Jens Wiklander Date: Mon, 7 Mar 2022 15:44:20 +0100 Message-ID: Subject: Re: [PATCH v2] rtc: optee: add RTC driver for OP-TEE RTC PTA To: =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: Alessandro Zummo , Alexandre Belloni , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-rtc@vger.kernel.org, Etienne Carriere , Thomas Petazzoni Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 7, 2022 at 12:01 PM Cl=C3=A9ment L=C3=A9ger wrote: > > Le Mon, 7 Mar 2022 11:40:38 +0100, > Jens Wiklander a =C3=A9crit : > > > On Mon, Mar 7, 2022 at 10:42 AM Cl=C3=A9ment L=C3=A9ger wrote: > > > > > > This drivers allows to communicate with a RTC PTA handled by OP-TEE [= 1]. > > > This PTA allows to query RTC information, set/get time and set/get > > > offset depending on the supported features. > > > > > > [1] https://github.com/OP-TEE/optee_os/pull/5179 > > > > > > Signed-off-by: Cl=C3=A9ment L=C3=A9ger > > > --- > > > > > > Changes in v2: > > > > Hmm, this seems to be a second v2. > > Hmpf, I answered to Etienne questions on V1 and forgot I already sent a > V2. > > > > > > - Rebased over tee-shm-for-v5.18 > > > - Switch to tee_shm_alloc_kernel_buf() > > > - Use export_uuid() to copy uuid > > > - Fix warnings reported by checkpatch > > > - Free SHM in error exit path > > > - Fix error messages to include ret value and fix wrong IOCTL names > > > - Use 100 columns char limit > > > > From bdc48fa11e46 ("checkpatch/coding-style: deprecate 80-column warnin= g"): > > Yes, staying withing 80 columns is certainly still _preferred_. Bu= t > > it's not the hard limit that the checkpatch warnings imply, and oth= er > > concerns can most certainly dominate. > > > > Increase the default limit to 100 characters. Not because 100 > > characters is some hard limit either, but that's certainly a "what = are > > you doing" kind of value and less likely to be about the occasional > > slightly longer lines. > > Ok. > > > > + > > > + if (param[0].u.memref.size !=3D sizeof(*optee_tm)) { > > > + dev_err(dev, "Invalid read size from OPTEE\n"); > > > + return -EPROTO; > > > + } > > > > The dev_err() prints above are basically covering "can't happen" > > cases. Robust code should certainly do the checks, but I'm not so sure > > about how useful the prints are. > > Agreed, if it fails, this is likely to be due to protocol changes and > thus, the developer will probably know where to search for the error. > > [...] > > > > +static int optee_rtc_probe(struct device *dev) > > > +{ > > > + struct tee_client_device *rtc_device =3D to_tee_client_device= (dev); > > > + struct tee_ioctl_open_session_arg sess_arg; > > > + struct optee_rtc *priv; > > > + struct rtc_device *rtc; > > > + struct tee_shm *shm; > > > + int ret, err; > > > + > > > + memset(&sess_arg, 0, sizeof(sess_arg)); > > > + > > > + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > > > + if (!priv) > > > + return -ENOMEM; > > > + > > > + rtc =3D devm_rtc_allocate_device(dev); > > > + if (IS_ERR(rtc)) > > > + return PTR_ERR(rtc); > > > + > > > + /* Open context with TEE driver */ > > > + priv->ctx =3D tee_client_open_context(NULL, optee_ctx_match, = NULL, NULL); > > > + if (IS_ERR(priv->ctx)) > > > + return -ENODEV; > > > + > > > + /* Open session with rtc Trusted App */ > > > + export_uuid(sess_arg.uuid, &rtc_device->id.uuid); > > > + sess_arg.clnt_login =3D TEE_IOCTL_LOGIN_REE_KERNEL; > > > + > > > + ret =3D tee_client_open_session(priv->ctx, &sess_arg, NULL); > > > + if (ret < 0 || sess_arg.ret !=3D 0) { > > > + dev_err(dev, "tee_client_open_session failed, err: %x= \n", sess_arg.ret); > > > > This print is the most useful print in the driver. This is typically > > reached if the PTA doesn't exist. > > If the PTA does not exists, is the driver even probed ? I thought it > was based on the UUID matching. Yes, it is, but perhaps there's some configuration mismatch or something. > > > > > > + err =3D -EINVAL; > > > + goto out_ctx; > > > + } > > > + priv->session_id =3D sess_arg.session; > > > + > > > + shm =3D tee_shm_alloc_kernel_buf(priv->ctx, sizeof(struct opt= ee_rtc_info)); > > > + if (IS_ERR(shm)) { > > > + dev_err(priv->dev, "tee_shm_alloc_kernel_buf failed\n= "); > > > + err =3D PTR_ERR(shm); > > > + goto out_sess; > > > + } > > > + > > > + priv->shm =3D shm; > > > + priv->dev =3D dev; > > > + dev_set_drvdata(dev, priv); > > > + > > > + rtc->ops =3D &optee_rtc_ops; > > > + > > > + err =3D optee_rtc_read_info(dev, rtc, &priv->features); > > > + if (err) { > > > + dev_err(dev, "Failed to get RTC features from OP-TEE\= n"); > > > > This print could also be worth keeping, but the rest are in my opinion > > of limited interest. > > > > It's a tradeoff with the prints, no big deal if you'd like to keep more= . > > I'm ok with that statement. The runtime errors are less likely (if not > totally unlikely) to happen. I'll sent a new version (V4 this time...) > with theses modifications. OK. Cheers, Jens > > Thanks, > > -- > Cl=C3=A9ment L=C3=A9ger, > Embedded Linux and Kernel engineer at Bootlin > https://bootlin.com