From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752426AbcBKStd (ORCPT ); Thu, 11 Feb 2016 13:49:33 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38827 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751717AbcBKSt2 (ORCPT ); Thu, 11 Feb 2016 13:49:28 -0500 MIME-Version: 1.0 In-Reply-To: <56BCA031.3010702@collabora.com> References: <1454679181-8949-1-git-send-email-tomeu.vizoso@collabora.com> <1454679181-8949-3-git-send-email-tomeu.vizoso@collabora.com> <56BCA031.3010702@collabora.com> From: Gwendal Grignou Date: Thu, 11 Feb 2016 10:49:07 -0800 X-Google-Sender-Auth: kn1_ceiUYOHPemwnOsYxHLjybfE Message-ID: Subject: Re: [PATCH v1 2/6] mfd: cros_ec: Add MKBP event support To: Tomeu Vizoso Cc: Gwendal Grignou , Linux Kernel , Sameer Nanda , Benson Leung , =?UTF-8?Q?Enric_Balletb=C3=B2?= , Vic Yang , Vincent Palatin , Randall Spangler , Vic Yang , Olof Johansson , linux-input@vger.kernel.org, Dmitry Torokhov , Lee Jones Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2016 at 6:52 AM, Tomeu Vizoso wrote: > > On 02/05/2016 06:24 PM, Gwendal Grignou wrote: > > We should not used kmalloc when get events, these functions are called > > quite often. > > Gwendal. > > > > On Fri, Feb 5, 2016 at 5:32 AM, Tomeu Vizoso > > wrote: > > > > +static int cros_ec_get_host_command_version_mask(struct > > cros_ec_device *ec_dev, > > + u16 cmd, u32 *mask) > > +{ > > + struct ec_params_get_cmd_versions *pver; > > + struct ec_response_get_cmd_versions *rver; > > + struct cros_ec_command *msg; > > + int ret; > > + > > + msg = kmalloc(sizeof(*msg) + max(sizeof(rver), sizeof(pver)), > > + GFP_KERNEL); > > + if (!msg) > > + return -ENOMEM; > > > > Victor's version in https://chromium-review.googlesource.com/272954 > > looks cleaner: no malloc, no need to cast rver. > > I agree that it looks cleaner, but how would you allocate the payload at > build time if it has to be max(sizeof(*pver), sizeof(*rver))? For this one, given cros_ec_get_host_command_version_mask() is called once, a kmalloc is fine. Gwendal.