Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp126844pxx; Tue, 27 Oct 2020 23:52:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyz26wxGYzSFgSG4+Ux4Wat8B7dXFM+i2WUh2j5LYFNyebw2+Yh4nh4rSjVg9XCYZDQEOrd X-Received: by 2002:a50:d751:: with SMTP id i17mr6328362edj.337.1603867938959; Tue, 27 Oct 2020 23:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603867938; cv=none; d=google.com; s=arc-20160816; b=qIQ70E0rSnpprYeb8z1Xs/zyiJEFK+I74aLJ6QCZjtBmPbis/Wz/T0V8eggxNx5Gee 7UWrOJWwCcCVxhErmJsybgKalpfd8n7OYU6naZ4hTGIyMqLo+oHgr7BYwCfRZUOsf9rW V6VTSYuD7mgQq/4bUtHlPNcX/Woi55Ao5cBEMzzQ2a0gZ2yGKXANNRqhznTrvaBmWdYX hQtGLNnyzyAoVB1YxHO1KYT8AnnI7u4lK5gEiWGQ05JSwyCCoyP6s34HldNGLLz3TLAo 68ebk3vBr6JYdmMBxPW50PAsId+qtYS0MKFHnH3hKomvMCuFIpKoWNAM+at/45Es1Ym0 m0lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TL4B+5yGPsuzk8YLy1Eb/baT+Nq11wWNa0Lsz50auDk=; b=MmxYqu//YaN7NItuiCm3BeyVJnFzNglsgFU7zpP0LXN1udCcG63Ooxc4qowVaNzfjw WuPIAeqB3PpbJRgEgbK1e+YYsTLERdC080N0tkJ6McZ5d4gXA/rj0EOZWjg6jWc41Kpp zDOgmSOTPUORT3pDpOBzjNhDsVQVzK3Cw8O0pMPSVP/Bepy+zBPRc/ak/yMhcqSfnN0U JnS1Z9IGK70ePIdYHHN0GbPrUuYUu18jbmalMS71SdJAg0CFZW2elCodszAS6k+6Qok8 aZGrpkpd4oDLcUjeSQ3WWPJeuS0FlgEy3eG6dNsJU2+544bDwni0TE7CXfuUjEjzji1K fvIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EykaKmtt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d14si2732415edu.275.2020.10.27.23.51.56; Tue, 27 Oct 2020 23:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EykaKmtt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2898260AbgJ0Kad (ORCPT + 99 others); Tue, 27 Oct 2020 06:30:33 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:38143 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2898246AbgJ0K3w (ORCPT ); Tue, 27 Oct 2020 06:29:52 -0400 Received: by mail-pj1-f65.google.com with SMTP id gi3so522255pjb.3; Tue, 27 Oct 2020 03:29:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TL4B+5yGPsuzk8YLy1Eb/baT+Nq11wWNa0Lsz50auDk=; b=EykaKmttOBuXKBD9Zv5StJFK7gLO7kju3F1ajh/rQFgazI8+C72rrVEcJQSDgd471i rGMjUvCNSI0fPzHuySmn3xF+HIwFPHVqRhmXvElpsxLhGUjA/riQFutmXqfXSJWtRkOa uWt5UMK4vAbgs0k1v0SfJejNjrgh+eWSMf7DFLBYVmwcuYgcWFnqVO2pyADNyTPYYq5N WFKuBC24JywqIjfHJrLcD5C+KUEXH2lvIj2VUKW3ahFUayCu2yLVOlmvw63C996ghhY/ pyeiB+xCM3JPkfs2oYUMtPRAxUYAcsN2KFxkSUMI36jTdo+u7sxJvYyqsrybc9CrYQSU k4IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TL4B+5yGPsuzk8YLy1Eb/baT+Nq11wWNa0Lsz50auDk=; b=AMJ68oLWu3IFo0lrH1/1SyBN9+WyQH+oxzwYQ2W9xvVX1W61L38ClqI9xiA3BYXd6b Lo76+4o6k6GyMQEJikTfG4nBU5ZyRos50i0wu/ZKSUHHB/1MbaoE1wQIAIjwZQRjV86S o728hOaN4UVjLeOw0tFxm0/9Z067K3RxVehz4uRI4m48Kiy2EsCLD02qKXngF8i19DRz ySh9EgL0mbR9512sOg20ado5EvyZmWCee07m0VXYCO2mloaRj1w7w8xX1eUQihjpGhgF 06rZfv4TPQwLV2pqDEUVyXIStGmrDgRqnIOTVvhyMk4L0VNSMX5ROChaqxlGqumB6Eo/ JQqA== X-Gm-Message-State: AOAM530JJPEqNeYTBq05KL6wi9IrG+af+suPilNOLwXz826/tVKIRHZy rRP1hK7Qnhc05wJpI1ZYovcdjUXCiEC2+O4ZaZo= X-Received: by 2002:a17:90a:fb92:: with SMTP id cp18mr1437134pjb.228.1603794592208; Tue, 27 Oct 2020 03:29:52 -0700 (PDT) MIME-Version: 1.0 References: <20201026133609.24262-1-brgl@bgdev.pl> <20201026133609.24262-3-brgl@bgdev.pl> In-Reply-To: From: Andy Shevchenko Date: Tue, 27 Oct 2020 12:30:41 +0200 Message-ID: Subject: Re: [PATCH 2/5] iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc() To: Bartosz Golaszewski Cc: Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek , linux-iio , linux-arm Mailing List , Linux Kernel Mailing List , Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 27, 2020 at 12:04 PM Bartosz Golaszewski wrote: > On Tue, Oct 27, 2020 at 10:33 AM Andy Shevchenko > wrote: > > > > On Mon, Oct 26, 2020 at 4:03 PM Bartosz Golaszewski wrote: > > > > > > From: Bartosz Golaszewski > > > > > > We now have devm_krealloc() in the kernel Use it indstead of calling > > > kfree() and kcalloc() separately. > > > > Which is completely lawful when size > previous_size (I mean, the > > additional patch you sent previously seems not related to this). > > > > Sure but devm_krealloc() is cleaner and adds the benefit of resource management. I meant devm_krealloc(). It should work in this case without your additional "fix" patch. > > > - kfree(xadc->data); > > > - xadc->data = kcalloc(n, sizeof(*xadc->data), GFP_KERNEL); > > > + xadc->data = devm_krealloc(indio_dev->dev.parent, xadc->data, > > > + n * sizeof(*xadc->data), > > > > I think you need to use something from overflow.h instead of explicit > > multiplication here. > > > > Or maybe add devm_krealloc_array() which would perform the checks > behind the scenes? Maybe. But what to do in the cases when you have struct with flexible arrays, like struct foo { ... type bar[]; }; ? And you do kzalloc(sizeof(foo)) followed by krealloc(). The above name (krealloc_array) may be a bit ambiguous. > > > + GFP_KERNEL | __GFP_ZERO); -- With Best Regards, Andy Shevchenko