devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: LABBE Corentin <clabbe.montjoie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: PrasannaKumar Muralidharan
	<prasannatsmkumar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: mpm-VDJrAJ4Gl5ZBDgjK7y7TUQ@public.gmane.org,
	"Herbert Xu"
	<herbert-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org>,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	mark.rutland-5wv7dgnIgG8@public.gmane.org,
	"Ralf Baechle" <ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org>,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
	geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org,
	"Andrew Morton"
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	"Greg KH"
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
	mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	"Guenter Roeck" <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>,
	boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org,
	harvey.hunt-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org,
	alex.smith-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org,
	"Daniel Thompson"
	<daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	"Lee Jones" <lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	"Florian Fainelli"
	<f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	kieran-7hKh/agyDeatmTQ+vhA3Yw@public.gmane.org,
	"Krzysztof Kozlowski"
	<krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	joshua.henderson-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org,
	yendapally.reddy-dY08KVG/lbpWk0Htik3J/w@public.gmane.org,
	narmstrong-rdvid1DuHRBWk0Htik3J/w@public.gmane.org,
	wangkefeng.wang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org,
	"Christian Lamparter"
	<chunkeey-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>,
	"Álvaro Fernández Rojas"
	<noltari-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"Linus Walleij"
	<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	pankaj.dev-qxv4g6HH51o@public.gmane.org
Subject: Re: [PATCH] Add Ingenic JZ4780 hardware RNG driver
Date: Thu, 18 Aug 2016 13:53:00 +0200	[thread overview]
Message-ID: <20160818115300.GA6621@Red> (raw)
In-Reply-To: <CANc+2y55ZCkauwKNtuuCxLx-WOtm8z+A_EBKsYSjEUdc+ZbZTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Thu, Aug 18, 2016 at 10:44:18AM +0530, PrasannaKumar Muralidharan wrote:
> >> +static int jz4780_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
> >> +{
> >> +     struct jz4780_rng *jz4780_rng = container_of(rng, struct jz4780_rng,
> >> +                                                     rng);
> >> +     u32 *data = buf;
> >> +     *data = jz4780_rng_readl(jz4780_rng, REG_RNG_DATA);
> >> +     return 4;
> >> +}
> >
> > If max is less than 4, its bad
> 
> Data will be 4 bytes.
> 

No, according to comment in include/linux/hw_random.h "drivers can fill up to max bytes of data"
So you cannot write more than max bytes without risking buffer overflow.

And if max > 4, hwrng client need to recall your read function.
The better example I found is tpm_get_random() in drivers/char/tpm/tpm-interface.c for handling both problem.

Regards

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-08-18 11:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 15:35 [PATCH] Add Ingenic JZ4780 hardware RNG driver PrasannaKumar Muralidharan
2016-08-17 16:01 ` Daniel Thompson
2016-08-17 16:13   ` PrasannaKumar Muralidharan
2016-08-17 19:06 ` Corentin LABBE
2016-08-18  5:14   ` PrasannaKumar Muralidharan
     [not found]     ` <CANc+2y55ZCkauwKNtuuCxLx-WOtm8z+A_EBKsYSjEUdc+ZbZTQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-18 11:53       ` LABBE Corentin [this message]
2016-08-18 12:19         ` Daniel Thompson
2016-08-19  0:59 ` Rob Herring
2016-08-19  9:47 ` Jeffrey Walton
     [not found]   ` <CAH8yC8kt-+6tnzAc2bsu6GX4uX1bqVoE8sZXvCS34DDhGhP2XQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-08-19 12:54     ` PrasannaKumar Muralidharan
2016-08-19 10:55 ` Jeffrey Walton
2016-08-19 13:09   ` PrasannaKumar Muralidharan

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=20160818115300.GA6621@Red \
    --to=clabbe.montjoie-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=alex.smith-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=chunkeey-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org \
    --cc=daniel.thompson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=f.fainelli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=harvey.hunt-1AXoQHu6uovQT0dZR+AlfA@public.gmane.org \
    --cc=herbert-lOAM2aK0SrRLBo1qDEOMRrpzq4S04n8Q@public.gmane.org \
    --cc=joshua.henderson-UWL1GkI3JZL3oGB3hsPCZA@public.gmane.org \
    --cc=kieran-7hKh/agyDeatmTQ+vhA3Yw@public.gmane.org \
    --cc=krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=lee.jones-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=mpm-VDJrAJ4Gl5ZBDgjK7y7TUQ@public.gmane.org \
    --cc=narmstrong-rdvid1DuHRBWk0Htik3J/w@public.gmane.org \
    --cc=noltari-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=pankaj.dev-qxv4g6HH51o@public.gmane.org \
    --cc=prasannatsmkumar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=ralf-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=wangkefeng.wang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
    --cc=yendapally.reddy-dY08KVG/lbpWk0Htik3J/w@public.gmane.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;
as well as URLs for NNTP newsgroup(s).