From: Jerome Marchand <jmarchan@redhat.com>
To: John Moser <john.r.moser@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Is this code right in zram?
Date: Mon, 04 Jun 2012 14:08:35 +0200 [thread overview]
Message-ID: <4FCCA543.3030603@redhat.com> (raw)
In-Reply-To: <4FC7E610.5060207@gmail.com>
On 05/31/2012 11:43 PM, John Moser wrote:
> before I go stomping all over other peoples' work and sending idiotic
> patches, I think I'll ask. Since I have no clue what I'm doing.
>
> in drivers/staging/zram.c out of 3.4 (I just grabbed the source hours
> ago), I see this on lines 810-822:
I assume that's drivers/staging/zram_drv.c.
>
> /* Allocate the device array and initialize each one */
> pr_info("Creating %u devices ...\n", num_devices);
> zram_devices = kzalloc(num_devices * sizeof(struct zram),
> GFP_KERNEL);
> if (!zram_devices) {
> ret = -ENOMEM;
> goto unregister;
> }
>
> for (dev_id = 0; dev_id < num_devices; dev_id++) {
> ret = create_device(&zram_devices[dev_id], dev_id);
> if (ret)
> goto free_devices;
> }
>
> Curiosity got me to here:
>
> http://lwn.net/Articles/147014/
>
> So assuming this, what I see here is:
>
> - kmalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
> - memset() that to 0
> - immediately fill in this RAM without reading it
>
> I'm wondering what the immediate need is to fill the area with zeros?
It's to avoid to have undefined values between the time the device is
created and initialized. In that case, it may be superfluous since the
locking mechanism should avoid to access an uninitialized device.
> Also curious as to whether the kzalloc() thing should better be
> kcalloc(num_devices, sizeof(struct zram), GFP_KERNEL) as a matter of
> convention.
It probably doesn't matter much. Apparently kcalloc() never got a lot
of success and kzalloc(sizeof(foo) * num_foos) type of allocation are
more popular.
Jerome
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
next prev parent reply other threads:[~2012-06-04 12:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-31 21:43 Is this code right in zram? John Moser
2012-06-01 9:53 ` Borislav Petkov
2012-06-04 12:08 ` Jerome Marchand [this message]
2012-06-04 12:33 ` Joe Perches
2012-06-04 12:47 ` Jerome Marchand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FCCA543.3030603@redhat.com \
--to=jmarchan@redhat.com \
--cc=john.r.moser@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox