Received: by 10.223.164.202 with SMTP id h10csp2458697wrb; Thu, 16 Nov 2017 15:57:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMYQmW67jbiYhhtEjdk7CnNsI+I3SqeAPbQaDUsO/SirckMDSlUYqXmlJpy7Qqp/TL3DKby4 X-Received: by 10.84.247.22 with SMTP id n22mr3316371pll.145.1510876665672; Thu, 16 Nov 2017 15:57:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510876665; cv=none; d=google.com; s=arc-20160816; b=iRi5mxSTUP5AQ1ybEFxaddx6TF7cg+It2FUuujcJOWv677TkTkGdbipQ7821bM48kC RdMrVkQjE3DcKlayGAncMZiRl+FYFPkihWr8k4kXB8Vg70YmtvhHcrEFh41GFS+cQUsV p4LkpIbY/Z/mlD9O8b9P9zlFR47JGXnr9mqxzZqv5CHWzgTSodwZu6qhXHJj6ONEHPFA SuXxDzAZ7tWIbpZv3ZUPLxwSfJDDL1dLGYvfNTb+ir6wWzOZW8waS0yq8hRMRW3Ht+66 9CUcdTEUyy+6Wc9n8/FhFhoiIwL3F3SKFB04gRNIu6y6Ct2M/K4iYaw3FAtmcYEM2/3P SYwQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=zdYRsNox4KvPw2c2nHk0dQfnKvge2TogVYCGH9s1u1I=; b=mSPSHwIG10WRKrlfzIuCJxBEnSWSsBXDPWyJpUyfb02Y2FloLBCrIU5rfEfsUayl6W QYT2WsJjVIRnobMUYSsG60YVtFgwb5RMNa+HDNLCDnE/iDHbi2a8FPr1Ve0lplI1Z7fC 2sxgkq3rDJQH2WWEyNx32sDwYeGd6Y7IRx/SpiITCiCGcPDwDmDuRq6j8kzANQh8mliC KxswlH121U5J8KGggOr985l6qdCGlm7uDjlA9fM9aScvJNdtxrnEfOpqyLj97b761VJ1 ePdZ1csLxBjplldBEX6UmtlnQbZsDapnwKriLGGjBSMEOZfns2/faPMfBtbcrrSgpjGq jFEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=Yj9TAjMI; dkim=pass header.i=@codeaurora.org header.s=default header.b=Ie+OujSN; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 60si1694825plb.732.2017.11.16.15.57.32; Thu, 16 Nov 2017 15:57:45 -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=@codeaurora.org header.s=default header.b=Yj9TAjMI; dkim=pass header.i=@codeaurora.org header.s=default header.b=Ie+OujSN; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933763AbdKPS56 (ORCPT + 92 others); Thu, 16 Nov 2017 13:57:58 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:41066 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760849AbdKPS5f (ORCPT ); Thu, 16 Nov 2017 13:57:35 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 14DEA601CF; Thu, 16 Nov 2017 18:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510858655; bh=cKeOo7VD81Ynq6bCVFLlW6y9WOt68OIssrz1WAeI+KE=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Yj9TAjMIBPsq597C7dFa0DQxH5zZAefVmF3DUnnlUffDiNrP9jBwMiC/ujftI2E8/ mccfwPLl0qesPfp2TMgQDIDLECGyToR2Q7hE2mBAKpqXJhp7oHlLKujorpzTKz8n0Q IQ6DfSHlXG6FcIXW6LDfAoQ3iNVjLFnCAyyjZN/s= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.142.6] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: clew@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C619760240; Thu, 16 Nov 2017 18:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1510858653; bh=cKeOo7VD81Ynq6bCVFLlW6y9WOt68OIssrz1WAeI+KE=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Ie+OujSNPjz2GcjD1FAaWm7eafdSoLRFK/8Qq2HOGkf1w4F6Kq6hAedKDQeuWQ4Vv B3v7QWbXn6+ZVYAWFQRWAMDghtaAbeeUxY0WtJbJg9OBs+SRChul46QXmltMX9PIYz PxHsV1O4Y77NvyhzgZZFBqFjn6YqoSWWV11KfPws= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C619760240 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=clew@codeaurora.org Subject: Re: [PATCH v3 1/5] soc: qcom: Introduce QMI encoder/decoder To: Bjorn Andersson , Andy Gross , Ohad Ben-Cohen Cc: Arun Kumar Neelakantam , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-remoteproc@vger.kernel.org References: <20171115201012.25892-1-bjorn.andersson@linaro.org> <20171115201012.25892-2-bjorn.andersson@linaro.org> <20171116054252.GK28761@minitux> From: Chris Lew Message-ID: <891288a2-4a41-7cff-3662-79561f3baab2@codeaurora.org> Date: Thu, 16 Nov 2017 10:57:32 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171116054252.GK28761@minitux> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/15/2017 9:42 PM, Bjorn Andersson wrote: > On Wed 15 Nov 12:10 PST 2017, Bjorn Andersson wrote: >> diff --git a/drivers/soc/qcom/qmi_encdec.c b/drivers/soc/qcom/qmi_encdec.c > [..] >> +void *qmi_encode_message(int type, unsigned int msg_id, size_t *len, >> + unsigned int txn_id, struct qmi_elem_info *ei, >> + const void *c_struct) >> +{ >> + struct qmi_header *hdr; >> + ssize_t msglen = 0; >> + void *msg; >> + int ret; >> + >> + /* Check the possibility of a zero length QMI message */ >> + if (!c_struct) { >> + ret = qmi_calc_min_msg_len(ei, 1); >> + if (ret) { >> + pr_err("%s: Calc. len %d != 0, but NULL c_struct\n", >> + __func__, ret); >> + return ERR_PTR(-EINVAL); >> + } >> + } >> + >> + msg = kzalloc(sizeof(*hdr) + *len, GFP_KERNEL); >> + if (!msg) >> + return ERR_PTR(-ENOMEM); >> + >> + msglen = qmi_encode(ei, msg + sizeof(*hdr), c_struct, *len, 1); >> + if (msglen < 0) { >> + kfree(msg); >> + return ERR_PTR(msglen); >> + } > > Talked to Chris Lew about this earlier today; > > The check above implies that it's valid to call this function with a > valid ei of minimum message length of 0 and c_struct being NULL. But the > call to qmi_encdec() will dereference c_struct in order to know that the > optional elements described in ei are unset. > > So the call to qmi_encode() needs to only be done conditionally on > c_struct being non-NULL, logically interpreting c_struct being NULL as > all optional fields are unset. > > Will post an update with this fixed. > I have tested this patch with QMI loopback servers, Qualcomm diag and slimbus ngd. Tested-By: Chris Lew >> + >> + hdr = msg; >> + hdr->type = type; >> + hdr->txn_id = txn_id; >> + hdr->msg_id = msg_id; >> + hdr->msg_len = msglen; >> + >> + *len = sizeof(*hdr) + msglen; >> + >> + return msg; >> +} >> +EXPORT_SYMBOL(qmi_encode_message); > > Regards, > Bjorn > -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project From 1584233714513313412@xxx Thu Nov 16 14:36:44 +0000 2017 X-GM-THRID: 1584165633790374120 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread