From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: Re: [PATCH v2 1/3] drm: Add SCDC helpers Date: Mon, 5 Dec 2016 12:16:52 +0100 Message-ID: <20161205111652.GE19891@ulmo.ba.sec> References: <20161202192415.16110-1-thierry.reding@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0819648051==" Return-path: Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com [IPv6:2607:f8b0:400e:c00::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6193B6E10D for ; Mon, 5 Dec 2016 11:16:57 +0000 (UTC) Received: by mail-pf0-x243.google.com with SMTP id y68so16950252pfb.1 for ; Mon, 05 Dec 2016 03:16:57 -0800 (PST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To: Jose Abreu Cc: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org --===============0819648051== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="brEuL7wsLY8+TuWz" Content-Disposition: inline --brEuL7wsLY8+TuWz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 05, 2016 at 10:12:39AM +0000, Jose Abreu wrote: > On 02-12-2016 19:24, Thierry Reding wrote: [...] > > +/** > > + * drm_scdc_write - write a block of data to SCDC > > + * @adapter: I2C controller > > + * @offset: start offset of block to write > > + * @buffer: block of data to write > > + * @size: size of the block to write > > + * > > + * Writes a block of data to SCDC, starting at a given offset. > > + * > > + * Returns: > > + * The number of bytes written to SCDC or a negative error code on fai= lure. > > + */ > > +ssize_t drm_scdc_write(struct i2c_adapter *adapter, u8 offset, > > + const void *buffer, size_t size) > > +{ > > + struct i2c_msg msg =3D { > > + .addr =3D SCDC_I2C_SLAVE_ADDRESS, > > + .flags =3D 0, > > + .len =3D 1 + size, > > + .buf =3D NULL, > > + }; > > + void *data; > > + int err; > > + > > + data =3D kmalloc(1 + size, GFP_TEMPORARY); > > + if (!data) > > + return -ENOMEM; > > + > > + msg.buf =3D data; > > + > > + memcpy(data, &offset, sizeof(offset)); > > + memcpy(data + 1, buffer, size); >=20 > Don't you agree it would be better if you use the same scheme as > drm_scdc_read()? Something like: >=20 > struct i2c_msg msgs[] =3D { > { > .addr =3D SCDC_I2C_SLAVE_ADDRESS, > .flags =3D 0, > .len =3D 1, > .buf =3D &offset, > }, { > .addr =3D SCDC_I2C_SLAVE_ADDRESS, > .flags =3D 0, > .len =3D size, > .buf =3D buffer, > }, > }; Ville had a similar comment on a prior iteration. It looks as if the above should work, but it's probably best to test it a little more widely to make sure we're not running into cases where it breaks. Have you by any chance verified that it works on your hardware? Thierry --brEuL7wsLY8+TuWz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAABCAAGBQJYRUykAAoJEN0jrNd/PrOh7PYQALLIhLqcWyb26XmTpH6H/YTl zaEgAZiMgwfPS44Sdn8+Gd+MjuFFSssuQ9IyWfB4L40UUfSt11JGcmfOkTlDWVse 7+2lHXo7UJwbg18SsKxf1bJvJboK2tb0M0D60seW76u5+Q7EgJiw2QuoFIC1v30v FBEPMLa9nr6T3nHZgl3fdiMrjoASUGIPiEHX+8a5cR1MXyfsvyULMHDqRL5A+JU3 BztxZqHkbe7cDxZsjAT9qwoLhOkxhyUCpNr2+afmXLyCkIo2z2Mp9//JlwavFG9O aqEoX12XGWLX3cyKAqNJo77xJQ53x3WSPH5MmNL6Olkd6fvEsXZ2eO3KN04ThCdu stp7adpuRKbaoGuMy/ydSTkFtG5rV3/gGIKmEC2XrU+pbNkM9cHdJoRWL3l/aCEE lnGiNx9tUzOUSCEcVRR1DgiQ2gcr3Jhrl0Ima9/yHI/yZXM3Jvm+MEUqjv162Zkk 07rVAcORAFMZRxZtE5yiAWZrBwIX3kgMEdBIsXv5S1PmUvifdv1hvmyYxFc8VVv3 MbnoOeXfSZwS07w5Mv7yOi5Vf77ZnkOOiGefORptKTD/N3zO0VtqZiajsh+O+UNa 5tGSpUrmtyiGy3IJsfSGoBd3xJwgpW5NGvl5rO5PRL0n5lsauC2R6GljBzd+Bkzl F1nYzayP1I9eAEyTEfai =NPh7 -----END PGP SIGNATURE----- --brEuL7wsLY8+TuWz-- --===============0819648051== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KZHJpLWRldmVs IG1haWxpbmcgbGlzdApkcmktZGV2ZWxAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vZHJpLWRldmVsCg== --===============0819648051==--