From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZLRIs-0005YY-26 for mharc-grub-devel@gnu.org; Sat, 01 Aug 2015 03:33:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51505) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLRIp-0005Xw-Bk for grub-devel@gnu.org; Sat, 01 Aug 2015 03:33:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLRIh-00043k-HN for grub-devel@gnu.org; Sat, 01 Aug 2015 03:33:55 -0400 Received: from mail-la0-x235.google.com ([2a00:1450:4010:c03::235]:36223) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLRIh-00043U-8X for grub-devel@gnu.org; Sat, 01 Aug 2015 03:33:47 -0400 Received: by labiq1 with SMTP id iq1so21702995lab.3 for ; Sat, 01 Aug 2015 00:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=epMyP+RAPB9CI6hlnp5drgrDbwMMYqq2WULsRtYy33s=; b=VUni1xeSpiWIYLGDhy0KJiXtaIJevSl9YZaN0FSQ2mTtDa4u4BFE24ZSVFkqsukGPk LtAgMkIGI/K3tVZOrXHeN29u/61qhzDaGpMQu+aIn07JS9OK/zcNxfcLEbAO3T4ci+8T RUE0PqxNjyfYuxhQW70babRHhy20wy0WYCdjfP19lEekkojTaZj54mpLKxlGkWSWfCcT tdTxENiV8q5LOKyN6ocz/Ld66f/3gNmcXg7CyCQo71rfpaygkBiVJXDYXTUC5UljEDWV w3sCuGEeuz4Ybi4vzFbj9bM9OUupOo+46jyowg8qbcMQuFOuSURpP4fcl3lfEqm+XQxX 1GiA== X-Received: by 10.152.36.7 with SMTP id m7mr7170730laj.87.1438414426418; Sat, 01 Aug 2015 00:33:46 -0700 (PDT) Received: from opensuse.site (ppp91-76-6-204.pppoe.mtu-net.ru. [91.76.6.204]) by smtp.gmail.com with ESMTPSA id uf7sm1450168lbb.29.2015.08.01.00.33.44 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Aug 2015 00:33:45 -0700 (PDT) Date: Sat, 1 Aug 2015 10:33:43 +0300 From: Andrei Borzenkov To: Paulo Flabiano Smorigo Subject: Re: [PATCH] ofdisk: Recognizes SAS disks automatically Message-ID: <20150801103343.41ddb9b4@opensuse.site> In-Reply-To: <1438349665-14139-1-git-send-email-pfsmorigo@linux.vnet.ibm.com> References: <1438349665-14139-1-git-send-email-pfsmorigo@linux.vnet.ibm.com> X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.28; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::235 Cc: The development of GNU GRUB X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Aug 2015 07:33:56 -0000 =D0=92 Fri, 31 Jul 2015 10:34:25 -0300 Paulo Flabiano Smorigo =D0=BF=D0=B8=D1=88=D0= =B5=D1=82: > Read all children from sas path and add it to the device list. Examples of paths and names would be useful for reference. >=20 > --- > grub-core/disk/ieee1275/ofdisk.c | 51 ++++++++++++++++++++++++++++++++++= ++++++ > include/grub/ieee1275/ofdisk.h | 3 +++ > 2 files changed, 54 insertions(+) >=20 > diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/o= fdisk.c > index 331769b..b17f6d1 100644 > --- a/grub-core/disk/ieee1275/ofdisk.c > +++ b/grub-core/disk/ieee1275/ofdisk.c > @@ -260,6 +260,57 @@ dev_iterate (const struct grub_ieee1275_devalias *al= ias) > grub_free (buf); > return; > } > + else if (grub_strcmp (alias->type, "sas_ioa") =3D=3D 0) > + { > + struct sas_children > + { > + struct grub_ieee1275_common_hdr common; > + grub_ieee1275_cell_t method; > + grub_ieee1275_cell_t ihandle; > + grub_ieee1275_cell_t max; > + grub_ieee1275_cell_t table; > + grub_ieee1275_cell_t catch_result; > + grub_ieee1275_cell_t nentries; > + } > + args; > + char *buf, *bufptr; > + unsigned i; > + grub_ieee1275_ihandle_t ihandle; > + > + buf =3D grub_malloc (grub_strlen (alias->path) > + + sizeof("/disk@") + IEEE1275_SAS_CHILDREN_SIZE= + 1); > + if (!buf) > + return; > + > + bufptr =3D grub_stpcpy (buf, alias->path); > + > + if (grub_ieee1275_open (alias->path, &ihandle)) > + return; memory leak. > + > + INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2); > + args.method =3D (grub_ieee1275_cell_t) "get-sas-children"; > + args.ihandle =3D ihandle; > + args.max =3D IEEE1275_SAS_CHILDREN_BUFFER_SIZE; > + args.table =3D 0; > + args.catch_result =3D 0; > + args.nentries =3D 0; > + > + if (IEEE1275_CALL_ENTRY_FN (&args) =3D=3D -1) > + { > + grub_ieee1275_close (ihandle); > + return; memory leak > + } > + grub_uint64_t *ptr; > + for (i =3D 0; i < args.nentries; i++) > + { > + ptr =3D (grub_uint64_t *) (args.table + IEEE1275_SAS_CHILDREN_= SIZE * i); Is it guaranteed to be aligned? Why do you need magic constant if it really sizeof(grub_unit64_t)? > + grub_snprintf (bufptr, 100, "/disk@%" PRIxGRUB_UINT64_T, (grub= _uint64_t) *ptr); Where size 100 comes from? You just allocated 8 bytes for the rest (sans final zero byte), but printf outputs 16 bytes, so it overflows buffer. > + dev_iterate_real (buf, buf); > + } > + > + grub_ieee1275_close (ihandle); Out of curiosity - what happens with args.table? Does firmware free it implicitly? > + grub_free (buf); > + } > =20 > if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_= DISKS) > && grub_strcmp (alias->type, "block") =3D=3D 0) > diff --git a/include/grub/ieee1275/ofdisk.h b/include/grub/ieee1275/ofdis= k.h > index 2f69e3f..59f84f7 100644 > --- a/include/grub/ieee1275/ofdisk.h > +++ b/include/grub/ieee1275/ofdisk.h > @@ -19,6 +19,9 @@ > #ifndef GRUB_OFDISK_HEADER > #define GRUB_OFDISK_HEADER 1 > =20 > +#define IEEE1275_SAS_CHILDREN_SIZE 8 > +#define IEEE1275_SAS_CHILDREN_BUFFER_SIZE 100*IEEE1275_SAS_CHILDREN_SIZE > + > extern void grub_ofdisk_init (void); > extern void grub_ofdisk_fini (void); > =20