sg_init_table zeroes its first argument, so the allocation of that argument doesn't have to. --- block/bsg-lib.c | 2 +- drivers/dma/sh/rcar-dmac.c | 2 +- drivers/dma/sh/shdma-base.c | 2 +- drivers/infiniband/hw/efa/efa_verbs.c | 2 +- drivers/media/common/saa7146/saa7146_core.c | 2 +- drivers/misc/mic/scif/scif_nodeqp.c | 2 +- drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c | 2 +- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 2 +- drivers/pci/p2pdma.c | 2 +- drivers/spi/spi-topcliff-pch.c | 4 ++-- drivers/target/target_core_rd.c | 2 +- drivers/tty/serial/pch_uart.c | 2 +- net/rds/rdma.c | 2 +- net/sunrpc/xprtrdma/frwr_ops.c | 2 +- 14 files changed, 15 insertions(+), 15 deletions(-)
sg_init_table zeroes its first argument, so the allocation of that argument doesn't have to. the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // <smpl> @@ expression x,n,flags; @@ x = - kcalloc + kmalloc_array (n,sizeof(struct scatterlist),flags) ... sg_init_table(x,n) // </smpl> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr> --- drivers/tty/serial/pch_uart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff -u -p a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c --- a/drivers/tty/serial/pch_uart.c +++ b/drivers/tty/serial/pch_uart.c @@ -981,7 +981,7 @@ static unsigned int dma_handle_tx(struct priv->tx_dma_use = 1; - priv->sg_tx_p = kcalloc(num, sizeof(struct scatterlist), GFP_ATOMIC); + priv->sg_tx_p = kmalloc_array(num, sizeof(struct scatterlist), GFP_ATOMIC); if (!priv->sg_tx_p) { dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__); return 0;
On Sun, Sep 20, 2020 at 01:26:13PM +0200, Julia Lawall wrote:
> sg_init_table zeroes its first argument, so the allocation of that argument
> doesn't have to.
>
> the semantic patch that makes this change is as follows:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x,n,flags;
> @@
>
> x =
> - kcalloc
> + kmalloc_array
> (n,sizeof(struct scatterlist),flags)
> ...
> sg_init_table(x,n)
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
It inits the first entry in the array, but what about all of the other
ones? Is that "safe" to have uninitialized data in them like your
change causes to happen?
thanks,
greg k-h
On Sun, 20 Sep 2020, Greg Kroah-Hartman wrote:
> On Sun, Sep 20, 2020 at 01:26:13PM +0200, Julia Lawall wrote:
> > sg_init_table zeroes its first argument, so the allocation of that argument
> > doesn't have to.
> >
> > the semantic patch that makes this change is as follows:
> > (http://coccinelle.lip6.fr/)
> >
> > // <smpl>
> > @@
> > expression x,n,flags;
> > @@
> >
> > x =
> > - kcalloc
> > + kmalloc_array
> > (n,sizeof(struct scatterlist),flags)
> > ...
> > sg_init_table(x,n)
> > // </smpl>
> >
> > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
>
> It inits the first entry in the array, but what about all of the other
> ones? Is that "safe" to have uninitialized data in them like your
> change causes to happen?
Sorry, I don't follow. The complete code is:
priv->sg_tx_p = kcalloc(num, sizeof(struct scatterlist), GFP_ATOMIC);
if (!priv->sg_tx_p) {
dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__);
return 0;
}
sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
and the definition of sg_init_table is:
void sg_init_table(struct scatterlist *sgl, unsigned int nents)
{
memset(sgl, 0, sizeof(*sgl) * nents);
sg_init_marker(sgl, nents);
}
It looks to me like it zeroes all of the elements? The same file does
contain a call:
sg_init_table(&priv->sg_rx, 1);
But that's not the one associated with the patch.
julia
On Sun, 20 Sep 2020 13:26:12 +0200, Julia Lawall wrote: > sg_init_table zeroes its first argument, so the allocation of that argument > doesn't have to. Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next Thanks! [1/1] spi/topcliff-pch: drop double zeroing commit: ca03dba30f2b8ff45a2972c6691e4c96d8c52b3b All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
Hello Mark, On 21.09.20 18:58, Mark Brown wrote: > On Sun, 20 Sep 2020 13:26:12 +0200, Julia Lawall wrote: >> sg_init_table zeroes its first argument, so the allocation of that argument >> doesn't have to. > > Applied to > > https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next > > Thanks! I do not understand which of the 14 patches you applied. Your mail responds to the 00/14 mail. Rolf > > [1/1] spi/topcliff-pch: drop double zeroing > commit: ca03dba30f2b8ff45a2972c6691e4c96d8c52b3b > > All being well this means that it will be integrated into the linux-next > tree (usually sometime in the next 24 hours) and sent to Linus during > the next merge window (or sooner if it is a bug fix), however if > problems are discovered then the patch may be dropped or reverted. > > You may get further e-mails resulting from automated or manual testing > and review of the tree, please engage with people reporting problems and > send followup patches addressing any issues that are reported if needed. > > If any updates are required or you are submitting further changes they > should be sent as incremental updates against current git, existing > patches will not be replaced. > > Please add any relevant lists and maintainers to the CCs when replying > to this mail. > > Thanks, > Mark >
[-- Attachment #1: Type: text/plain, Size: 349 bytes --] On Wed, Sep 23, 2020 at 05:10:33PM +0200, Rolf Reintjes wrote: > On 21.09.20 18:58, Mark Brown wrote: > I do not understand which of the 14 patches you applied. Your mail responds > to the 00/14 mail. As the mail you're replying to says: > > [1/1] spi/topcliff-pch: drop double zeroing > > commit: ca03dba30f2b8ff45a2972c6691e4c96d8c52b3b [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --]
On Sun, Sep 20, 2020 at 02:47:11PM +0200, Julia Lawall wrote:
>
>
> On Sun, 20 Sep 2020, Greg Kroah-Hartman wrote:
>
> > On Sun, Sep 20, 2020 at 01:26:13PM +0200, Julia Lawall wrote:
> > > sg_init_table zeroes its first argument, so the allocation of that argument
> > > doesn't have to.
> > >
> > > the semantic patch that makes this change is as follows:
> > > (http://coccinelle.lip6.fr/)
> > >
> > > // <smpl>
> > > @@
> > > expression x,n,flags;
> > > @@
> > >
> > > x =
> > > - kcalloc
> > > + kmalloc_array
> > > (n,sizeof(struct scatterlist),flags)
> > > ...
> > > sg_init_table(x,n)
> > > // </smpl>
> > >
> > > Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
> >
> > It inits the first entry in the array, but what about all of the other
> > ones? Is that "safe" to have uninitialized data in them like your
> > change causes to happen?
>
> Sorry, I don't follow. The complete code is:
>
> priv->sg_tx_p = kcalloc(num, sizeof(struct scatterlist), GFP_ATOMIC);
> if (!priv->sg_tx_p) {
> dev_err(priv->port.dev, "%s:kzalloc Failed\n", __func__);
> return 0;
> }
>
> sg_init_table(priv->sg_tx_p, num); /* Initialize SG table */
>
> and the definition of sg_init_table is:
>
> void sg_init_table(struct scatterlist *sgl, unsigned int nents)
> {
> memset(sgl, 0, sizeof(*sgl) * nents);
> sg_init_marker(sgl, nents);
> }
Ah, missed the "* nents" thing there, sorry, my fault.
greg k-h
On Sun, 20 Sep 2020 13:26:12 +0200, Julia Lawall wrote: > sg_init_table zeroes its first argument, so the allocation of that argument > doesn't have to. Applied to 5.10/scsi-queue, thanks! [02/14] scsi: target: rd: Drop double zeroing https://git.kernel.org/mkp/scsi/c/4b217e015b75 -- Martin K. Petersen Oracle Linux Engineering