Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp272373ybi; Tue, 18 Jun 2019 22:32:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxY6pwG/hLE6OMhlryL2PHOdmOymC8+d+yyxPsAUnzQbt7kZgQthO4rwZqE3rBYxRGyV8Z X-Received: by 2002:a17:90a:25c8:: with SMTP id k66mr9244934pje.129.1560922334599; Tue, 18 Jun 2019 22:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560922334; cv=none; d=google.com; s=arc-20160816; b=ymWrkf9mJrMTA+k8BTAV6hwcz0YsFrt5fM1nUuxNER7dKhePlwYM5NnOpktNPGuJdD Hn7gigJ9K3oijmnIke4P+PCf7VjFNccl3v7jE0U0Vvx+qF3ESxIE0P4zYRID6m367JgG qP9G7Ge1N18kCJAZl8Hg7gORBMK6PpIr3nlIvOW+2OyuCRFl2ZsitNcjn/rAGjhKT/D6 Bn7DSXBgvbZHukweHayNJve05cllnTLtNRMwznlwIKOcEQ6d2reQr2gDY33OHC/Hqb91 nA0z+SFuhVlFM8I8o0PnHnLnK7VxI3z1EBaAGBKvp3KOHZ7vSgfGG67rB27ljdsRB0XC mPUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=buhWTROSF4QaiBD0PrOB0xejan9MPIV0yZA5jFiSTQ0=; b=GTvOc+Xbwl1tV7+YjqhRV9uKeyNkZfrkSDSYfdbYJIy1ksZB0NJdPbuI510In+ulQQ wAIK0Ol0uqFr0eNcDveTWjzy/1LlQxYp07jH5qiW6xaoHVoRaewrefOOKypuZEX+ND5D PYIK7+PqkNRBVJRsz49IdqrqhhNxg4S4zwNXAkE3eUpeu6G0gJIqQgrS/KfgHCOJ22bp o1G4ACfxIuIRiO542DqjKZrqeMW675l3qLqkMtZWc8tiByRM5IAozMzPBuoCzknxnxGz aVwcVcZ9qmlEunTxC36ECHX/+HWI3r+abkYuqmZadmpGal4JP8vMttg2AgPwLzvVSV6r EkJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=kMtb4Gdn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 97si14714540plc.181.2019.06.18.22.31.58; Tue, 18 Jun 2019 22:32:14 -0700 (PDT) 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=@oracle.com header.s=corp-2018-07-02 header.b=kMtb4Gdn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730916AbfFSFac (ORCPT + 99 others); Wed, 19 Jun 2019 01:30:32 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:54638 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726195AbfFSFab (ORCPT ); Wed, 19 Jun 2019 01:30:31 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5J5O27q176930; Wed, 19 Jun 2019 05:30:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=buhWTROSF4QaiBD0PrOB0xejan9MPIV0yZA5jFiSTQ0=; b=kMtb4Gdn2i40OcM675R7t0kdiM3vs9UjF8SABFF70VdrVdTA9sQLC5EJKpJ4FTo7re/w TH63yAuRQ0UsD4WyrIpEowSOP+0LHKFaT6bkF6jbGwOy1B4POEdmiF9pD4J6+F7vrF6J bh/+nSoEZ1RSnaB3i4FibkDUf4ogts4IvsqOXohv+o4tIIDgUgvXeSTtnrjZK1esEcFk 5LqWs+9i1GmTzR93rcUFsrYGu3J6t+moc/nhfO62RisId5MoBDh6yFNuT4TEmPs5a2B5 mfZ71S5SiaUUDk7paeQqfG2wSGV2bGgG8lZaCx3xw0zKlQq0QjtpglD0QOwXEriFMtP5 zw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2t780994cw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2019 05:30:23 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5J5TEwV068317; Wed, 19 Jun 2019 05:30:23 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2t77ymvdq1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Jun 2019 05:30:23 +0000 Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x5J5UK2g002327; Wed, 19 Jun 2019 05:30:20 GMT Received: from kadam (/41.57.98.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 18 Jun 2019 22:30:19 -0700 Date: Wed, 19 Jun 2019 08:30:12 +0300 From: Dan Carpenter To: Colin King Cc: Benson Leung , Enric Balletbo i Serra , Nick Crews , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] platform/chrome: wilco_ec: fix null pointer dereference on failed kzalloc Message-ID: <20190619053012.GM28859@kadam> References: <20190618153924.19491-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190618153924.19491-1-colin.king@canonical.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9292 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190043 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9292 signatures=668687 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1906190043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 18, 2019 at 04:39:24PM +0100, Colin King wrote: > diff --git a/drivers/platform/chrome/wilco_ec/event.c b/drivers/platform/chrome/wilco_ec/event.c > index c975b76e6255..e251a989b152 100644 > --- a/drivers/platform/chrome/wilco_ec/event.c > +++ b/drivers/platform/chrome/wilco_ec/event.c > @@ -112,8 +112,11 @@ module_param(queue_size, int, 0644); > static struct ec_event_queue *event_queue_new(int capacity) > { > size_t entries_size = sizeof(struct ec_event *) * capacity; > - struct ec_event_queue *q = kzalloc(sizeof(*q) + entries_size, > - GFP_KERNEL); > + struct ec_event_queue *q; > + > + q = kzalloc(sizeof(*q) + entries_size, GFP_KERNEL); > + if (!q) > + return NULL; We have a new struct_size() macro designed for these allocations. q = kzalloc(struct_size(q, entries, capacity), GFP_KERNEL); The advantage is that it checks for integer overflows. regards, dan carpenter