Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp128205pxx; Tue, 27 Oct 2020 23:55:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfZEtQE20sSg0urJy3IR2fe7mQxdDtIAKZzO5FeEo76M1PmvoBAoDlihPoK1kuPPtO7Yoh X-Received: by 2002:a17:906:1a0e:: with SMTP id i14mr6271840ejf.7.1603868152571; Tue, 27 Oct 2020 23:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603868152; cv=none; d=google.com; s=arc-20160816; b=wixSzY0oLhlnsjqL9Q34hmeyq86zvDySTRS/BJaBBScjrRktfwUVuQOIzN8ng4eNQG uX4Yd1qByQWtrfvg/w44vsB1RN9Czv/cHeouq4b05qsW282+RgUvfrpL/QjGAlxbts3z YHJ5q7Eq67p1b54aMtvCjPU26ows12dJMWjSx7lioxqoqMR6mkA1CbYfs4IlTluK2p8y AzOb2Yg5IhUIgPo1t1mRRFx56p46KaL7g0YaWD3+bL1MKhjFDgv5rLvVk+XBJvj+i/OX 4wh2ISWDcI2al9zTskmx7GyJZdwECt4hx5Oyz5kNDDgsW71QnwBKz2PuctWi4Rgjt/j6 XDqQ== 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=uTxMRA4/c1G5gjulnxVBfnJK6XAxYI7ClJM6lo1HV0s=; b=H0Ogbxibz4/52P0ITZ9j9EaP1aaAqjYg7Btph7oKU91r+JifmcC6mniFTMHMxWv7ZU KJ9MHfyKOMB81F69MeRX25fqjTllSy9QXbTPZa0TWIf88dxgXZp/U3BWAbPdz/78J5I7 LMhHUXCSbmKwMJoxx6kQLBAuxT0kfqVTIqm69XtuPPQmM8qgNq9na49zb9DZCo6gNZGh YzOSzVOtRDEp1MXlTv6/OWFhrqjNxZO8lc4ULWJHs8PK0ERBWzVsn5ofql6fIttbya3c YYP7YbCWXJuxUBoKLbdUHNM7+JERs9cvPkI3Fp/UmgSEkdjAkdn5lFffy+XknI/CWUZm 8AaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=qqiRWFU+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o2si2631671ejn.501.2020.10.27.23.55.29; Tue, 27 Oct 2020 23:55:52 -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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=qqiRWFU+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2898689AbgJ0KlL (ORCPT + 99 others); Tue, 27 Oct 2020 06:41:11 -0400 Received: from mail-ej1-f65.google.com ([209.85.218.65]:47073 "EHLO mail-ej1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2898664AbgJ0Kkt (ORCPT ); Tue, 27 Oct 2020 06:40:49 -0400 Received: by mail-ej1-f65.google.com with SMTP id t25so1459036ejd.13 for ; Tue, 27 Oct 2020 03:40:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uTxMRA4/c1G5gjulnxVBfnJK6XAxYI7ClJM6lo1HV0s=; b=qqiRWFU+UXC7Zw0SqnNgluYvZSaoqCUfaHtRq7Xma4zW6Pkovsz+14fGyz22X3w+Z4 d/g7cvlGZ3ZE0hrfhKYmO+b+1VTYuFf/8qW858mqOzo7ILcN/nsEJfMG32SmavwJWj4+ KrQOJoJrkFz8sMHM0pjWrfjecJxFa9/9YEjoL584XbLBVllpCdxMBhKswzMyCCaPtzfI D+x+POJj0RFMYDu14W9uVIoso4ckZSvDDZxgnXvTkeYxhLVYmOkm7w4sSfJels2LKhsN gcHgs5eIQ69tQQJ+yaly0nyQmECdEMp3gE48XrjP+guopMxRQJzhr9mSWt2Iw3Zcd/dx +cFQ== 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=uTxMRA4/c1G5gjulnxVBfnJK6XAxYI7ClJM6lo1HV0s=; b=et0QS04VVbfgQjas09pA/57Vs8Zxwl7re08MansokMZsPET+8WS8NYEEFf4bglKnEV uJayQXjljBtTKulXZscLb1rEsvRwHgxKwMmg186tripnO4UnxvUix+vb+skK2xYECE9M j3E6kuRo13/wL0j8TZCW6f1VBlCU/gZZm0e64n6bPyi/ALvD6yjr9HZYhdX4z6Gph0zi h49AHlobjoDxw8wrAybZr7yzyFyXlQnO5PuX4qUHT2jcfHRh/x15vY9YHgsEdGb9M1wr BdAFIoQCHnRpnggz7HCIcfgGuyU1KWqC6H4wcTKlrqESST6t9SmZEWxu38uLLjpmQiTG +AEg== X-Gm-Message-State: AOAM532Y8JMEuZK7cTdDl7V1QcYMtKFocMGKabpJc8wEbp1uvV6YMSdU /sFzZTXvVAfIEy2BKuLk0hsKzGqksuOfe1q4xalfjA== X-Received: by 2002:a17:906:5f96:: with SMTP id a22mr1708926eju.168.1603795247655; Tue, 27 Oct 2020 03:40:47 -0700 (PDT) MIME-Version: 1.0 References: <20201026133609.24262-1-brgl@bgdev.pl> <20201026133609.24262-3-brgl@bgdev.pl> In-Reply-To: From: Bartosz Golaszewski Date: Tue, 27 Oct 2020 11:40:37 +0100 Message-ID: Subject: Re: [PATCH 2/5] iio: adc: xilinx: use devm_krealloc() instead of kfree() + kcalloc() To: Andy Shevchenko Cc: Bartosz Golaszewski , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Michal Simek , linux-iio , linux-arm Mailing List , Linux Kernel Mailing List 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 11:29 AM Andy Shevchenko wrote: > > 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. > I know, this is why I sent the fix separately. The fix is still correct on its own. > > > > - 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[]; > }; > > ? Just use regular devm_krealloc() with struct_size()? > > And you do kzalloc(sizeof(foo)) followed by krealloc(). The above name > (krealloc_array) may be a bit ambiguous. But devm_krealloc_array() would only be useful for memory allocated by kmalloc_array() or kcalloc(). I don't see what's your point. Bartosz