Message ID | 20231222181250.49764-1-xypron.glpk@gmx.de |
---|---|
State | Superseded, archived |
Delegated to: | Tom Rini |
Headers | show |
Series | [1/1] lib: smbios: verify_checksum() is duplicate | expand |
On Fri, Dec 22, 2023 at 6:13 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote: > > The function verify_checksum() duplicates what table_compute_checksum() > does. Replace it. > > Fixes: 415eab0655a8 ("smbios: add parsing API") > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > lib/smbios-parser.c | 18 ++---------------- > 1 file changed, 2 insertions(+), 16 deletions(-) Reviewed-by: Simon Glass <sjg@chromium.org> It would be worth mentioning that that function is always including in the build,
Hi Heinrich, On Fri, 22 Dec 2023 at 20:18, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote: > > The function verify_checksum() duplicates what table_compute_checksum() > does. Replace it. > > Fixes: 415eab0655a8 ("smbios: add parsing API") If we could drop this during the merge or send a v2 it would be great. > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > --- > lib/smbios-parser.c | 18 ++---------------- > 1 file changed, 2 insertions(+), 16 deletions(-) > > diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c > index f4de350e6e..a29a06398d 100644 > --- a/lib/smbios-parser.c > +++ b/lib/smbios-parser.c > @@ -5,23 +5,9 @@ > > #define LOG_CATEGORY LOGC_BOOT > > +#include <tables_csum.h> > #include <smbios.h> > > -static inline int verify_checksum(const struct smbios_entry *e) > -{ > - /* > - * Checksums for SMBIOS tables are calculated to have a value, so that > - * the sum over all bytes yields zero (using unsigned 8 bit arithmetic). > - */ > - u8 *byte = (u8 *)e; > - u8 sum = 0; > - > - for (int i = 0; i < e->length; i++) > - sum += byte[i]; > - > - return sum; > -} > - > const struct smbios_entry *smbios_entry(u64 address, u32 size) > { > const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address; > @@ -32,7 +18,7 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size) > if (memcmp(entry->anchor, "_SM_", 4)) > return NULL; > > - if (verify_checksum(entry)) > + if (table_compute_checksum(entry, entry->length)) > return NULL; > > return entry; > -- > 2.43.0 > Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff --git a/lib/smbios-parser.c b/lib/smbios-parser.c index f4de350e6e..a29a06398d 100644 --- a/lib/smbios-parser.c +++ b/lib/smbios-parser.c @@ -5,23 +5,9 @@ #define LOG_CATEGORY LOGC_BOOT +#include <tables_csum.h> #include <smbios.h> -static inline int verify_checksum(const struct smbios_entry *e) -{ - /* - * Checksums for SMBIOS tables are calculated to have a value, so that - * the sum over all bytes yields zero (using unsigned 8 bit arithmetic). - */ - u8 *byte = (u8 *)e; - u8 sum = 0; - - for (int i = 0; i < e->length; i++) - sum += byte[i]; - - return sum; -} - const struct smbios_entry *smbios_entry(u64 address, u32 size) { const struct smbios_entry *entry = (struct smbios_entry *)(uintptr_t)address; @@ -32,7 +18,7 @@ const struct smbios_entry *smbios_entry(u64 address, u32 size) if (memcmp(entry->anchor, "_SM_", 4)) return NULL; - if (verify_checksum(entry)) + if (table_compute_checksum(entry, entry->length)) return NULL; return entry;
The function verify_checksum() duplicates what table_compute_checksum() does. Replace it. Fixes: 415eab0655a8 ("smbios: add parsing API") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> --- lib/smbios-parser.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) -- 2.43.0