From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D5A4C388F9 for ; Tue, 27 Oct 2020 10:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4C6D622281 for ; Tue, 27 Oct 2020 10:41:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="qqiRWFU+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2898694AbgJ0KlS (ORCPT ); Tue, 27 Oct 2020 06:41:18 -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-Google-Smtp-Source: ABdhPJzeY90F2ZT44I1CsbyMJrlcyjfgRa7+QDxzsQKMQ0nX22n4K2iNKsRhc4EwRIy+/lSHaV6EkTIXK0h5XOWQI2I= 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5DA6C4363A for ; Tue, 27 Oct 2020 10:42:14 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D59B20829 for ; Tue, 27 Oct 2020 10:42:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GkSM1jVV"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=baylibre-com.20150623.gappssmtp.com header.i=@baylibre-com.20150623.gappssmtp.com header.b="qqiRWFU+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D59B20829 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wDBQm1vE7q1m52KoP465P6v+Nrw7uYv2NlkadZXkySk=; b=GkSM1jVVMpnfkOhhwplji9ahE fs2uzq48sY4WDOZqEqBux1bn8JT081N4ucrzGrtEdMTc6CGXEvSXsDQxEYicJrfPeG4H3eMxcwdX1 XENJwF3ZGQ6g+Mx8UNz83Lvqmj3DBjTOCnFXXZmgcMEmLaTf3guk7Nylce8OHxJ3Ksni4nnHVB+d3 Poiz8GbC1ue83wPMMOiYPshVuFQUIlKChoK2LYpTdNxLx8Mu6r8qYF5czo7p0whyYoxtJh1YwAecO uVaEiDVEwcyoSM+79qqgNJyU01muTwsJC2gO7ZEDcOaChKsnTRFCj7IlmbISqidElSkqGnlz/NuCT 4nesSgoTA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXMPM-00015T-LG; Tue, 27 Oct 2020 10:40:52 +0000 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXMPI-00014G-UW for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 10:40:50 +0000 Received: by mail-ej1-x644.google.com with SMTP id bn26so1499208ejb.6 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=tEXrFbZF1VidpmVM9MDaXTsFRrHQ9Uctk2UYugLe+BfWNaD4xTSTUSwQr/YLYDNdf1 6bFfrAS5L4M8aYwuMwqm9BPIrGT/k8b+4zatwdX+bFzaK/bRjHU4e3LCiKSaEyE3jBSK evHQUwqCyIH6+XJR3ubN5Fuj699jaqOVxXEL8lAheRNAddH+zc8Aw3NPPq1/7VNpVNyT YamlGa6dhKKi3kZWxCMxTCtIMBXjrEJGIF0jFc2IjhFrjP8U7GrTJQrIDuOLdVKomXBF +YjOhTm2WOheK4+wU6AOPYCrX9CsU2cW8/lxVFYSmWS31DTV8pR5QYSMgQ8HLTvdt1Zg qCDw== X-Gm-Message-State: AOAM5326w0SF8Hw7RpbbDGd5moxDKavQtWR2GpjKGAY0BZXBaQGNuZF9 6JNJI+TthX2E8ULZBIN1CNprlA0SfAujZoL90gp4Ig== X-Google-Smtp-Source: ABdhPJzeY90F2ZT44I1CsbyMJrlcyjfgRa7+QDxzsQKMQ0nX22n4K2iNKsRhc4EwRIy+/lSHaV6EkTIXK0h5XOWQI2I= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_064049_146788_2FA938E9 X-CRM114-Status: GOOD ( 24.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lars-Peter Clausen , linux-iio , Bartosz Golaszewski , Michal Simek , Linux Kernel Mailing List , linux-arm Mailing List , Peter Meerwald-Stadler , Jonathan Cameron Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel