From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752445AbdLEWDj (ORCPT ); Tue, 5 Dec 2017 17:03:39 -0500 Received: from smtprelay0138.hostedemail.com ([216.40.44.138]:58439 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751066AbdLEWDh (ORCPT ); Tue, 5 Dec 2017 17:03:37 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3871:3872:4250:4321:5007:6119:7903:8603:10004:10400:10848:10903:11026:11232:11473:11658:11914:12043:12296:12438:12740:12760:12895:13069:13101:13311:13357:13439:14659:14721:21080:21324:21433:21451:21627:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: hands08_3c62a460a5d49 X-Filterd-Recvd-Size: 2758 Message-ID: <1512511413.6321.94.camel@perches.com> Subject: Re: [PATCH v5 1/5] soc: qcom: Introduce QMI encoder/decoder From: Joe Perches To: Bjorn Andersson , Andy Gross , Ohad Ben-Cohen Cc: Arun Kumar Neelakantam , Chris Lew , Philippe Ombredanne , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-remoteproc@vger.kernel.org Date: Tue, 05 Dec 2017 14:03:33 -0800 In-Reply-To: <20171205174310.15799-2-bjorn.andersson@linaro.org> References: <20171205174310.15799-1-bjorn.andersson@linaro.org> <20171205174310.15799-2-bjorn.andersson@linaro.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.26.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2017-12-05 at 09:43 -0800, Bjorn Andersson wrote: > Add the helper library for encoding and decoding QMI encoded messages. > The implementation is taken from lib/qmi_encdec.c of the Qualcomm kernel > (msm-3.18). > > Modifications has been made to the public API, source buffers has been > made const and the debug-logging part was omitted, for now. [] > diff --git a/drivers/soc/qcom/qmi_encdec.c b/drivers/soc/qcom/qmi_encdec.c [] > +#define QMI_ENCDEC_ENCODE_TLV(type, length, p_dst) do { \ > + *p_dst++ = type; \ > + *p_dst++ = ((u8)((length) & 0xFF)); \ > + *p_dst++ = ((u8)(((length) >> 8) & 0xFF)); \ > +} while (0) > + > +#define QMI_ENCDEC_DECODE_TLV(p_type, p_length, p_src) do { \ > + *p_type = (u8)*p_src++; \ > + *p_length = (u8)*p_src++; \ > + *p_length |= ((u8)*p_src) << 8; \ > +} while (0) > > +#define QMI_ENCDEC_DECODE_N_BYTES(p_dst, p_src, size) \ > +do { \ > + memcpy(p_dst, p_src, size); \ > + p_dst = (u8 *)p_dst + size; \ > + p_src = (u8 *)p_src + size; \ > +} while (0) > + I dislike the asymmetric use of p_dst being incremented by 3 and p_src being incremented by 2 here Is it really useful to have these macros do any increments of arguments? Why not a static inline and use a variant of __be16_to_cpu/cpu_to_be16 > +static int qmi_encode_basic_elem(void *buf_dst, const void *buf_src, > + u32 elem_len, u32 elem_size) > +{ > + u32 i, rc = 0; > + > + for (i = 0; i < elem_len; i++) { > + QMI_ENCDEC_ENCODE_N_BYTES(buf_dst, buf_src, elem_size); > + rc += elem_size; > + } I find this use obscure where buf_dst and buf_src are both modified with an addition by the macro.