mirror of
https://review.coreboot.org/flashrom.git
synced 2025-04-27 07:02:34 +02:00

Convert the anon union of registered masters in the mst field of the flashctx to a anon struct. If we are going to dereference a pointer there in an undefined way we should crash and not plow ahead with invalid memory. The user of the registered_masters type is therefore responsible for querying the buses_supported field before attempting to dereference a ptr field in the anon struct. BUG=b:175849641 TEST=`flashrom -p internal --flash-name` Change-Id: I576967a8599b923c902e39f177f39146291cc242 Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/50246 Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Daniel Campello <campello@chromium.org> Reviewed-by: Sam McNally <sammc@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
/*
|
|
* This file is part of the flashrom project.
|
|
*
|
|
* Copyright (C) 2011,2013,2014 Carl-Daniel Hailfinger
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
/*
|
|
* Contains the opaque master framework.
|
|
* An opaque master is a master which does not provide direct access
|
|
* to the flash chip and which abstracts all flash chip properties into a
|
|
* master specific interface.
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include "flash.h"
|
|
#include "flashchips.h"
|
|
#include "chipdrivers.h"
|
|
#include "programmer.h"
|
|
|
|
int probe_opaque(struct flashctx *flash)
|
|
{
|
|
return flash->mst->opaque.probe(flash);
|
|
}
|
|
|
|
int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
|
|
{
|
|
return flash->mst->opaque.read(flash, buf, start, len);
|
|
}
|
|
|
|
int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
|
|
{
|
|
return flash->mst->opaque.write(flash, buf, start, len);
|
|
}
|
|
|
|
int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
|
|
{
|
|
return flash->mst->opaque.erase(flash, blockaddr, blocklen);
|
|
}
|
|
|
|
int register_opaque_master(const struct opaque_master *mst)
|
|
{
|
|
struct registered_master rmst = {0};
|
|
|
|
if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
|
|
msg_perr("%s called with incomplete master definition. "
|
|
"Please report a bug at flashrom@flashrom.org\n",
|
|
__func__);
|
|
return ERROR_FLASHROM_BUG;
|
|
}
|
|
rmst.buses_supported = BUS_PROG;
|
|
rmst.opaque = *mst;
|
|
return register_master(&rmst);
|
|
}
|