At least you've helped me go back one further generation (always assuming there's an explanation for the McDonald/McDonnell discrepancy - The register entry for Edward's baptism is not that clear. Walter's surname seems to have only one "n" and the last two letters are not very clear - might be McDonald? Similarly the surname of the sponsors on the next line.)
Spelling of surnames wasn't standardised until elementary education and official written records became common later in the century. Even then there was flexibility. Members of some families didn't agree on a spelling of their surname - there are examples on 1901 or 1911 census and in BMD registrations.
When thinking about spellings of surnames and place-names one has to take into account:
Many people in Ireland in the first half of 19th century weren't able to read and write and so it was up to the scribe to decide how to spell a word - spelling of a surname in a parish register might change when there was a new clergyman or parish clerk, or if the person moved to a new parish or area;
Accents/dialects;
The first language of some people was Irish, they may have been known to friends & neighbours by the Irish form of their names but by the English version in written records;
There were variations in names and spellings of places. Ireland was the first country in the world to be surveyed and mapped in detail. The work was done by the Royal Engineers regiment of the British Army, assisted by local people (including an ancestor of President Biden in Mayo).
Irish Ancestors Wizard suggests "at least" 25 variants for the surname McDonald. Gaelic versions include MacDomnaill . Some variants don't have Mac. Prefixes Mac and O' might be omitted or added according to circumstances. (Your McMahon may have been Mahon in some records.)
https://www.johngrenham.com/wizard/If you do a search on Wizard for one of your McDonalds with father Walter, including birthplace Castlebar, you'll be led to a list of sources for the place + list of adjacent parishes.
I have a "Mc" surname in my tree. Mr "Mc", born c.1818 was literate and was consistent with the spelling of his name - I've seen his signature several times. English-born Mrs "Mc" wasn't literate. They lived in England. There were spelling variations in their children's birth registrations and on a census return after the husband's death. When their children were adults they always used the same spelling as their father and it has passed down the generations.
The other side of my family includes Loftus from Castlebar. A simple name but a variant is Loftis. My dad's birth on English GRO births index has been incorrectly transcribed from a printed index and they refused to change it. I got another entry corrected - Mulvee/Mulvie/Mulvey. Those were 20th century births, the 19thC ones had those variants + more.
My Castlebar family also had a military connection.